-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[BUG] Property isEnum false for referenced ENUM schemas #2645
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
The I have found one of my comment in swagger-api/swagger-codegen#7763 (comment) There is good input to the topic in PR #3186 (That was not merged, exactly it was merged and reverted). From an OpenAPI semantic perspective:
components:
schemas:
SomeObject:
type: object
Properties:
id:
type: integer
someProp:
$ref: '#/components/schemas/SomeEnum'
SomeEnum:
type: string
enum: [a, b, c] And components:
schemas:
SomeObject:
type: object
Properties:
id:
type: string
someProp:
type: string
enum: [a, b, c] are exactly the same, but the code generated by OpenAPI-Generator in both cases is not the same. The semantic of For example Java generators are using this to decide if a new enum type must be generated (when Example: Without any change to the Java-Generators: components:
schemas:
MyObject:
type: object
Properties:
id:
type: integer
someProp:
$ref: '#/components/schemas/SomeEnum'
SomeOtherObject:
type: object
Properties:
firstName:
type: string
lastName:
type: string
initState:
$ref: '#/components/schemas/SomeEnum'
SomeEnum:
type: string
enum: [a, b, c] If
Instead of using the shared model class Of course everything can be changed/improved to be more consistent. But we need to keep the current use-cases still working. For your use case: openapi-generator/modules/openapi-generator/src/main/resources/erlang-server/api.mustache Lines 67 to 69 in 26e775c
Line 68 is inside a In mustache java, this works (source).
|
Mentioned by @jaumard on Slack, following works for him to know if a field is an enum:
|
This workaround works for single enum field |
None of these tricks work if your enum is referenced. |
@erik-telesoftas The suggested workaround would work only assuming that the enum is a String enum. The values in If you will have a number enum, this would break, or you would get a false positive. |
Bug Report Checklist
Description
When generating the code of the Erlang server, I have noticed that the ENUM check would not work on one parameter. By reducing the file I found out that the generator wasn't putting the enum values in the generated code, not because
allowableValues
was null but becauseisEnum
was set on false for referenced ENUM parameters.openapi-generator version
4.0.0, commit b426bab
OpenAPI declaration file content or url
Command line used for generation
java -jar openapi-generator-cli.jar -i enums.yaml -g erlang-server -o server/
Steps to reproduce
request_param_info
(line 52)Obtained result:
Expected result:
Suggest a fix
In
DefaultCodegen
,fromProperty
, addingproperty.isEnum= true;
at line 2068 after assigningallowableValues
seems to fix the issue of the missing enum values, but doesn't assign any type to the property. To fix that I would move the type checking block right over the inline enum case as a functionprotected void setPropertyType(CodegenProperty property, Schema p, String name)
and add two calls, one forp
(setPropertyType(property, p, name)
) and one forreferencedSchema
(setPropertyType(property, referencedSchema, name
).The text was updated successfully, but these errors were encountered: