-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1671 from altro3/fix-oneof-in-generator
Fix generating classes for oneOf block without discriminator
- Loading branch information
Showing
9 changed files
with
111 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 11 additions & 9 deletions
20
...ator/src/main/resources/templates/java-micronaut/common/model/typeInfoAnnotation.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
{{#jackson}} | ||
{{#discriminator}} | ||
{{#discriminator.propertyBaseName}} | ||
{{#jackson}} | ||
@JsonIgnoreProperties( | ||
value = "{{{discriminator.propertyBaseName}}}", // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization | ||
allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization | ||
) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "{{{discriminator.propertyBaseName}}}", visible = true) | ||
{{#discriminator}} | ||
{{#vendorExtensions.hasMappedModels}} | ||
{{#vendorExtensions.hasMultipleMappedModels}} | ||
{{#vendorExtensions.hasMappedModels}} | ||
{{#vendorExtensions.hasMultipleMappedModels}} | ||
@JsonSubTypes({{openbrace}}{{#mappedModels}} | ||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"){{^-last}},{{/-last}} | ||
{{/mappedModels}}{{closebrace}}) | ||
{{/vendorExtensions.hasMultipleMappedModels}} | ||
{{^vendorExtensions.hasMultipleMappedModels}} | ||
{{/vendorExtensions.hasMultipleMappedModels}} | ||
{{^vendorExtensions.hasMultipleMappedModels}} | ||
@JsonSubTypes({{#mappedModels}}@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"){{/mappedModels}}) | ||
{{/vendorExtensions.hasMultipleMappedModels}} | ||
{{/vendorExtensions.hasMappedModels}} | ||
{{/vendorExtensions.hasMultipleMappedModels}} | ||
{{/vendorExtensions.hasMappedModels}} | ||
{{/jackson}} | ||
{{/discriminator.propertyBaseName}} | ||
{{/discriminator}} | ||
{{/jackson}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
...or/src/main/resources/templates/kotlin-micronaut/common/model/typeInfoAnnotation.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
{{#jackson}} | ||
{{#discriminator}} | ||
{{#discriminator.propertyBaseName}} | ||
{{#jackson}} | ||
@JsonIgnoreProperties( | ||
value = ["{{{discriminator.propertyBaseName}}}"], // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization | ||
allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization | ||
) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "{{{discriminator.propertyBaseName}}}", visible = true) | ||
{{#discriminator}} | ||
{{#vendorExtensions.hasMappedModels}} | ||
{{#vendorExtensions.hasMappedModels}} | ||
@JsonSubTypes({{#mappedModels}} | ||
JsonSubTypes.Type(value = {{modelName}}::class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"){{^-last}},{{/-last}} | ||
{{/mappedModels}}) | ||
{{/vendorExtensions.hasMappedModels}} | ||
{{/vendorExtensions.hasMappedModels}} | ||
{{/jackson}} | ||
{{/discriminator.propertyBaseName}} | ||
{{/discriminator}} | ||
{{/jackson}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
openapi-generator/src/test/resources/3_0/oneof-without-discriminator.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: 'Order API' | ||
version: v6 | ||
servers: | ||
- | ||
url: 'https://{environment}.com/api/{apiVersion}' | ||
variables: | ||
environment: | ||
enum: | ||
- api-dev.test.com | ||
default: api.dev.test.com | ||
apiVersion: | ||
enum: | ||
- v1 | ||
- v2 | ||
- v3 | ||
- v4 | ||
- v5 | ||
- v6 | ||
- v7 | ||
default: v6 | ||
paths: | ||
'/orders/{id}': | ||
get: | ||
tags: | ||
- Order | ||
operationId: getOrderById | ||
parameters: | ||
- | ||
$ref: '#/components/parameters/OrderId' | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/OrderDTO' | ||
components: | ||
parameters: | ||
OrderId: | ||
name: id | ||
in: path | ||
description: 'The ID' | ||
required: true | ||
schema: | ||
type: string | ||
schemas: | ||
OrderDTO: | ||
required: | ||
- id | ||
properties: | ||
id: | ||
type: string | ||
shopping_notes: | ||
nullable: true | ||
oneOf: | ||
- $ref: '#/components/schemas/ShoppingNotesDTO' | ||
ShoppingNotesDTO: | ||
properties: | ||
message: | ||
type: string | ||
icon_url: | ||
type: string | ||
type: object |