-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
set isEnum when model is enum #1794
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
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.
@zhemant What about the following instead?
if (ref != null && ref.getEnum() != null) {
...
}
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.
Yes, this is better. I will make these changes and push again.
|
For this spec: isModel is set and isPrimitiveType is false, with this much info is not sufficient to handle enum in language like C, so if we can set isEnum flag then in mustache we can handle model enums in non primitive part |
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.
What about using ModelUtils.unaliasSchema(globalSchemas, p) instead?
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.
This is already done for schema p in the same function before.
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.
I have analyzed the same code: ModelUtils.unaliasSchema(globalSchemas, p) is returning the reference-schema to indicate that a outer-enum must be created (which is correct).
You could use ModelUtils.getReferencedSchema(this.openAPI, p) to get the referenced schema regardless of any other consideration.
ff2a263 to
cba3a43
Compare
|
Looks like this will cause a lot of changes to other generators (e.g. C#) as shown in the CircleCI logs. We need to consider other ways to address the problem you're facing. |
|
Can we override the fromProperty method in CLibCurlClient.java and there we set isEnum tag? I have an idea of it, I am already sending openAPI for projectName so may be I can use it to set a globalvariable there and use it during fromProperty |
|
When you've time in the coming week, please ping me via Gitter and we can discuss other solutions in details. |
|
Closing this one for the time being. |
|
Please have a look at PR #2001 I have filed to fix the default value case where an outer-enum is created. components:
schemas:
TestObject:
type: object
properties:
myEnum:
$ref: '#/components/schemas/MyEnum'
MyEnum:
type: string
default: FIRSTVALUE
enum:
- FIRSTVALUE
- SECONDVALUEFor the java generators My PR sets I did not read the details behind your problem, but I have the felling that the topics are connected. Feel free to continue the discussion. |
|
I had a look at PR #2001, as I haven't dealt with the default value in an enum, but sure it will be helpful in case default value needs to be set. I want to differentiate between enum and non-primitive datatype but we only have isModel flag set to true rest all flags are false. so it was creating an issue. hence I thought of setting isEnum flag but didn't know it would interfere with other generators. By looking at your code, I got a few hints on how I can handle it in CLibCurl.java so it doesn't interfere with other generators. |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif 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.xmaster.Description of the PR
fix #1780 , Along with setting isModel to true, set isEnum to true when a model is generated for enum. This will allow better handling for enum variables when enum is of nonPrimitiveType.
@wing328 @OpenAPITools/generator-core-team