Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add help message about AnonymousSchema generated classes #211

Merged
merged 8 commits into from
Jul 18, 2022
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);
}
};