-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Add an option to generate the alias (map, array) as model #1729
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I've debugged through it many times I don't profess a deep understanding of the code for converting the specification model into Codegen* models. Nevertheless, from what I can see, setting generateAliasAsModel = true ought to restore the previous behaviour of emitting models that are merely aliases for typed maps or arrays.
However, the default setting of generateAliasAsModel = false currently emits code with compilation errors (in the Java case at least). For example, consider an operation that returns an array whose modelled element type A is defined by a Map<String, B> schema in which B is another modelled type. The CodegenOperation has returnBaseType = 'Map' but returnType = 'List<A>', which won't compile because class A is no longer generated. I didn't see any code below to rectify this issue.
If I understand correctly, this issue already exists in the current master so please open an issue to track it instead. The goal of this PR is to restore the old behaviour to generate alias (map, array) as model. and I believe your use case is to set |
Fair enough - the problem with the current behaviour can be seen as a separate issue, which I'll log in due course. In the meantime I'd be happy for the PR to proceed. Many thanks for the rapid turnaround William. |
Looks like there's a problem. I just rebased onto upstream/option_generate_alias_model and now I'm getting an NPE in my code because CodegenModel.additionalPropertiesType is no longer being set (to AttributeValue) for the alias type (AuditEvent extends Map<String, AttributeValue>). |
Does your customization include overriding
If you include this, it should set the codegen model's |
Thanks. With the suggested addAdditionPropertiesToCodeGenModel() override, generating from the CLI with the --generate-alias-as-model option now seems to work, and my AuditEvent (and other alias classes) are generated and referenced correctly in the API's CXF implementation class. My only question is: why is it necessary for the generator sub-class to do this in an override? For backwards compatibility shouldn't it be done automatically by DefaultCodegen? However, the <generateAliasAsModel>true</generateAliasAsModel> Maven plug-in configuration option has no effect. I tried it in both execution/configuration and execution/configuration/configOptions - under the debugger I can see that additionalProperties does not contain the key "generateAliasAsModel" at DefaultCodegen line 213 ( |
Fixes the first part of OpenAPITools#1729 (comment) (see OpenAPITools#1729 (comment)). The second part was fixed by OpenAPITools#1845 (commit d65dd76).
Fixes the first part of #1729 (comment) (see #1729 (comment)). The second part was fixed by #1845 (commit d65dd76).
…ls#1729) * add option to generate alias as model * fix issue due to incorrect merge
Fixes the first part of OpenAPITools#1729 (comment) (see OpenAPITools#1729 (comment)). The second part was fixed by OpenAPITools#1845 (commit d65dd76).
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
Add an option (--generate-alias-as-model in CLI or generateAliasAsModel in the config) to generate the alias (map, array) as model.
The option is default to false.