Skip to content

Commit dc9b01e

Browse files
authored
fix: Issues/58 - don't create a class for schemas that are simple types. (#59)
* Removed some verbose debug logging. * fix: issue/58: Don't create a class for enums that are simple types.
1 parent 2b65daf commit dc9b01e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

hooks/post-process.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,30 @@ module.exports = {
7171
}
7272
}
7373

74-
// This renames schema objects ensuring they're proper Java class names.
74+
// This renames schema objects ensuring they're proper Java class names. It also removes files that are schemas of simple types.
7575

7676
const schemas = asyncapi.components().schemas();
7777
//console.log("schemas: " + JSON.stringify(schemas));
7878

7979
for (const schema in schemas) {
80-
let javaName = _.camelCase(schema);
81-
javaName = _.upperFirst(javaName);
82-
83-
if (javaName !== schema) {
84-
const oldPath = path.resolve(sourcePath, `${schema }.java`);
85-
const newPath = path.resolve(sourcePath, `${javaName }.java`);
86-
fs.renameSync(oldPath, newPath);
87-
// console.log("Renamed class file " + schema + " to " + javaName);
80+
81+
let schemaObj = schemas[schema];
82+
let type = schemaObj.type();
83+
const oldPath = path.resolve(sourcePath, `${schema}.java`);
84+
85+
//console.log(`postprocess schema ${schema} ${type}`);
86+
87+
if (type === 'object' || type === 'enum') {
88+
let javaName = _.camelCase(schema);
89+
javaName = _.upperFirst(javaName);
90+
91+
if (javaName !== schema) {
92+
const newPath = path.resolve(sourcePath, `${javaName}.java`);
93+
fs.renameSync(oldPath, newPath);
94+
// console.log("Renamed class file " + schema + " to " + javaName);
95+
}
96+
} else {
97+
fs.unlinkSync(oldPath);
8898
}
8999
}
90100

0 commit comments

Comments
 (0)