Skip to content

Commit

Permalink
feat: add help message about AnonymousSchema generated classes (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenischev authored Jul 18, 2022
1 parent 6e69731 commit e4498b0
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions hooks/98_userHelp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const fs = require('fs');

function checkForAnonymousSchemaObjects(generator) {
const modelPath = generator.targetDir + '/src/main/java/com/asyncapi/model';
var anonymousPresent = false;
var anonymousFileNames = [];
fs.readdirSync(modelPath).forEach(file => {
if (file.startsWith('AnonymousSchema')) {
anonymousPresent = true;
anonymousFileNames.push(generator.templateParams['userJavaPackage'].replace(/\./g, '/') + '/model/' + file);
}
});
if (anonymousPresent) {
console.log(`Following AnonymousSchema classes were generated in DTO classes:
${anonymousFileNames.toString()}\n
This may be a result of explicit (composition, inheritance, array items) Schema Object definition e.g.\n
schemas:
NamedObject:
type: object
properties:
field:
type: array
items:
type: object #Anonymous object
properties:
field:
type: string
\nOR\n
messages:
Message:
payload:
type: object #Anonymous object
properties:\n
Please move such elements to child of "schemas:" to define proper names.
If changing of data model is not possible, you may use "$id" to set name e.g.\n
properties:
field:
type: array
items:
$id: ArrayElement #Name of object
type: object
properties:
field:
type: string`);
}
}

module.exports = {
/**
* Print help information for user if problems encountered during generation.
*
* @param generator
*/
'generate:after': generator => {
checkForAnonymousSchemaObjects(generator);
}
};

0 comments on commit e4498b0

Please sign in to comment.