Skip to content

Commit

Permalink
fix: Issues/58 - don't create a class for schemas that are simple typ…
Browse files Browse the repository at this point in the history
…es. (#59)

* Removed some verbose debug logging.

* fix: issue/58: Don't create a class for enums that are simple types.
  • Loading branch information
damaru-inc authored Sep 8, 2020
1 parent 2b65daf commit dc9b01e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions hooks/post-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,30 @@ module.exports = {
}
}

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

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

for (const schema in schemas) {
let javaName = _.camelCase(schema);
javaName = _.upperFirst(javaName);

if (javaName !== schema) {
const oldPath = path.resolve(sourcePath, `${schema }.java`);
const newPath = path.resolve(sourcePath, `${javaName }.java`);
fs.renameSync(oldPath, newPath);
// console.log("Renamed class file " + schema + " to " + javaName);

let schemaObj = schemas[schema];
let type = schemaObj.type();
const oldPath = path.resolve(sourcePath, `${schema}.java`);

//console.log(`postprocess schema ${schema} ${type}`);

if (type === 'object' || type === 'enum') {
let javaName = _.camelCase(schema);
javaName = _.upperFirst(javaName);

if (javaName !== schema) {
const newPath = path.resolve(sourcePath, `${javaName}.java`);
fs.renameSync(oldPath, newPath);
// console.log("Renamed class file " + schema + " to " + javaName);
}
} else {
fs.unlinkSync(oldPath);
}
}

Expand Down

0 comments on commit dc9b01e

Please sign in to comment.