Model not generated with the right type (allOf)
See original GitHub issueDescription
A member of a model is not using the model type requested by the spec. Please check the example for a better explanation
openapi-generator version
Master (3.1.1-SNAPSHOT)
OpenAPI declaration file content or url
This is a self contained file that reproduce the issue
swagger: "2.0"
info:
description: "dfsdfsdfs"
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/"
contact:
email: "apiteam@swagger.io"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
schemes:
- "https"
- "http"
paths:
/lifecycles:
put:
tags:
- Device
summary: xxxxxxx
operationId: editDeviceLifecycles
parameters:
- in: body
name: device-lifecycle-update-info
required: true
schema:
$ref: "#/definitions/DeviceLifecycleCore"
responses:
200:
description: OK
schema:
$ref: "#/definitions/DeviceLifecycleCore"
definitions:
DeviceLifecycleCore:
type: object
description: "DeviceLifecycleCore"
properties:
aaa:
type: string
description: "aaa"
bbb:
type: string
description: "bbb"
ccc:
type: string
description: "ccc"
returnSoftwareStatus:
$ref: "#/definitions/DeviceLifecycleStatus"
DeviceLifecycleStatus:
type: object
description: "DeviceLifecycleStatus"
allOf:
- $ref: "#/definitions/DeviceLifecycleStatusCore"
- type: object
required:
- id
properties:
id:
type: integer
format: int64
description: "Id associated with the status"
example: 123
DeviceLifecycleStatusCore:
type: object
description: "DeviceLifecycleStatusCore"
properties:
name:
type: string
description: "Name"
details:
type: string
description: "Any additional information needed for the status"
example: "Something is wrong"
As you can see returnSoftwareStatus
is supposed to be of type DeviceLifecycleStatus
. If you look in the generated code, you will see that it is of type DeviceLifecycleStatusCore
instead:
public DeviceLifecycleCore returnSoftwareStatus(DeviceLifecycleStatusCore returnSoftwareStatus) {
this.returnSoftwareStatus = returnSoftwareStatus;
return this;
}
/**
* DeviceLifecycleStatus
* @return returnSoftwareStatus
**/
@Valid
public DeviceLifecycleStatusCore getReturnSoftwareStatus() {
return returnSoftwareStatus;
}
public void setReturnSoftwareStatus(DeviceLifecycleStatusCore returnSoftwareStatus) {
this.returnSoftwareStatus = returnSoftwareStatus;
}
Command line used for generation
java -jar openapi-generator-cli.jar generate -i ./swagger.yaml --generator-name java-play-framework -o generatedServer -DhideGenerationTimestamp=true,booleanGetterPrefix=is
Steps to reproduce
Just run the command above
Related issues/PRs
None
Suggest a fix/enhancement
?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Open API generator allOf not generating model correctly
I want to generate our models based on an Openapi spec 3.0 yml definition. In my spec I have a definition using allOf...
Read more >oneOf, anyOf, allOf, not - Swagger
OpenAPI lets you combine and extend model definitions using the allOf keyword. allOf takes an array of object definitions that are used for...
Read more >Schema generation rules · GitBook - Goswagger.Io
For each schema, go-swagger will generate one or more model types in go. ... Generated models uses no reflection except for enum and...
Read more >OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
Media type definitions are spread across several resources. ... integer format: int32 responses: NotFound: description: Entity not found.
Read more >RE: REST Builder (OpenAPI) YAML "allOf" inheritance is not ...
But when buildREST is generating the stubs for this allOf schema, we do see two different DTO classes without an extends. Parent Class...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am also affected by this bug.
The problem comes from the https://github.com/OpenAPITools/openapi-generator/commit/a897feef50989d8b0d0238c067eebaef4f7f6c70 commit in the https://github.com/OpenAPITools/openapi-generator/pull/360 pull request. More precisely, from this change https://github.com/OpenAPITools/openapi-generator/commit/a897feef50989d8b0d0238c067eebaef4f7f6c70#diff-7cb46fa53f89a458a7b7cb201d2214a8R1527.
Before this commit, when these properties where not un-aliased, a
Schema
instance was used to compose the model property of composed models (models containingallOf
). ThisSchema
instance contained the appropriate $ref field indicating the original datatype name, from which the data type name was correctly extracted viaDefaultCodeGen::getSchemaType()
.Now, with this un-aliasing, instead of a
Schema
with the proper $ref field, aComposedSchema
is used to compose the model properties of composed datatypes. In those ComposedSchemas the original data type name is lost andDefaultCodeGen::getSchemaType()
returns the datatype of the first of the models involved in theallOff
clause:Though the https://github.com/OpenAPITools/openapi-generator/pull/360 pull request fixed the issues #255 and #191, it originated this #582 issue.
@wing328, do you think it would be possible to keep the fixes brought by https://github.com/OpenAPITools/openapi-generator/pull/360 and at the same time have a proper generation of composed schemas?
Maybe something like this:
You can notice I added
|| isComposedSchema(ref)
to the finalelse if
. This way composed models would not get broken when creating properties for models.Fixed by https://github.com/OpenAPITools/openapi-generator/pull/704