Closed lcc closed 1 year ago
@lcc do you mind clarifying which exact names you would expect from the generator and what you received?
Inferring names for models from JSON Schema is no exact science, so it's not as easy as saying it should be A or B, but happy to have a conversation about how to improve the default naming strategy 🙂
You can explicitly define the names using $id
so for example do:
"status": {
"$id": "BaseEventStatus",
"type": "string",
"description": "Represents the status of the order",
"enum": [
"waiting",
"dining",
"paying",
"paid",
"none"
]
},
If you have no control over the input data, you can remap the constrained names, but that should be a last resort IMO.
const generator = new GoGenerator({
constraints: {
modelName: ({modelName}) => {
const constrainedModelName = goDefaultModelNameConstraints()({modelName});
// Overwrite the name to use while still keeping the naming constraints for Go.
if(constrainedModelName === 'AnonymousSchema_2') return 'BaseEventType';
if(constrainedModelName === 'AnonymousSchema_5') return 'BaseEventStatus';
return constrainedModelName;
}
}
});
You can explicitly define the names using $id so for example do:
That solved it, thanks.
Inferring names for models from JSON Schema is no exact science, so it's not as easy as saying it should be A or B, but happy to have a conversation about how to improve the default naming strategy 🙂
Well, all other names were the keys for their schemas, so I guessed it would be the same way to the schema.
Anyhow I am going to make this as solved because it fixed my issue. Do you happen to know if it's possible for the generated files to have their json annotation generated?
Do you happen to know if it's possible for the generated files to have their json annotation generated?
It is once I finish #639 😅
Describe the bug
When generating models using the
GoGenerator()
if there are enums in the schemas definitions they are renamed to AnonymousSchema.How to Reproduce
Expected behavior
The expected behavior would be for the models to appear with their proper names.