You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an inline model has two or more properties that are inline objects (not using $ref) and those objects have the same set of properties the generator combines them in to a single Java class and references that class for both children properties even though these objects may not be conceptually related at all (see YAML example below)
Note both the "order" property and the "customer" property are of type ReceiptOrder which while functional seems wrong or at the very least confusing to anyone using the client, especially for methods with signatures like: setCustomer(ReceiptOrder customer)
I would assume the default would not combine objects and would only combine objects when a $ref was used explicitly. At the very least an option should be provided to turn this combining logic off.
The text was updated successfully, but these errors were encountered:
$ref for Separate Definitions
To prevent the generator from merging the two inline objects, you can define separate schemas for Order and Customer, and then use $ref to reference those schemas in your Receipt object.
Here's how you can modify your OpenAPI YAML - components: schemas: Order: type: object properties: id: type: integer format: int64 name: type: string Customer: type: object properties: id: type: integer format: int64 name: type: string Receipt: type: object properties: Order: $ref: '#/components/schemas/Order' Customer: $ref: '#/components/schemas/Customer'
In this case, separate Java classes Order and Customer will be generated, and you won’t face the merging issue.
Description
When an inline model has two or more properties that are inline objects (not using $ref) and those objects have the same set of properties the generator combines them in to a single Java class and references that class for both children properties even though these objects may not be conceptually related at all (see YAML example below)
openapi-generator version
5.0.1
OpenAPI declaration file content or url
Command line used for generation
generate -i -g java --additional-properties=withXml=false,java8=true,library=native,serializationLibrary=jackson,dateLibrary=java8,hideGenerationTimestamp=true -o ./client
Steps to reproduce
Run generator using the above command line on a YAML file that includes the above snippet and you will get code that looks like this for Receipt:
Note both the "order" property and the "customer" property are of type ReceiptOrder which while functional seems wrong or at the very least confusing to anyone using the client, especially for methods with signatures like: setCustomer(ReceiptOrder customer)
Related issues/PRs
Not for openapi-generator but in swagger-codegen:
swagger-api/swagger-codegen#4883
Suggest a fix/enhancement
I would assume the default would not combine objects and would only combine objects when a $ref was used explicitly. At the very least an option should be provided to turn this combining logic off.
The text was updated successfully, but these errors were encountered: