[BUG] [Python] $ref references to non-object types not working correctly
Created by: spacether
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
When looking at the swagger2.0 sample spec, the #/definitions/OuterEnum defines a string with enum examples. When it is used in other models, the parameters that refer to OuterEnum with $ref incorrectly list themselves as model parameters and do not include the correct enum options.
openapi-generator version
4.0.0-SNAPSHOT
OpenAPI declaration file content or url
definitions:
OuterEnum:
type: string
enum:
- "placed"
- "approved"
- "delivered"
Enum_Test:
type: object
required:
- enum_string_required
properties:
enum_string:
type: string
enum:
- UPPER
- lower
- ''
enum_string_required:
type: string
enum:
- UPPER
- lower
- ''
enum_integer:
type: integer
format: int32
enum:
- 1
- -1
enum_number:
type: number
format: double
enum:
- 1.1
- -1.2
outerEnum:
$ref: '#/definitions/OuterEnum'
Command line used for generation
java -DdebugModels -jar /Users/justin/programming/openapi/fork_mine/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -t modules/openapi-generator/src/main/resources/python -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g python -o samples/client/petstore/python -DpackageName=petstore_api
Steps to reproduce
- Run the above debugging for the models
- Inspect the OuterEnum model result, its dataType='str'
- Inspect the Enum_Test OuterEnum parameter, isModel is true and none of the enum values have been connected in
Related issues/PRs
- https://github.com/OpenAPITools/openapi-generator/issues/1627
- https://github.com/OpenAPITools/openapi-generator/issues/1990
- https://github.com/OpenAPITools/openapi-generator/issues/1981
- https://github.com/OpenAPITools/openapi-generator/issues/1927
Suggest a fix
For models where datatype is not object, we should:
- Convert them to codegen parameters
- Put them where they belong
- Remove the source models from the final models list