-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Java/Spring] Support Discriminator Based OneOf Interface (#…
…11650) * Fix #5381 added x-is-one-of-interface extension for oneOf interface in mustache template * Fix #5381 fixed name of model from UNKNOWN_BASE_TYPE to right one in api: operationId + OneOf Fix #5381 parcelableModel is not required * Fix #5381 removed not needed methods * Fix #5381 catch NPE cases in preprocessOpenAPI updated samples * Fix #5381 fixed generation of oneOf Models * Fix #5381 addOneOfInterfaceModel only for cases when useOneOfInterfaces is true and for spring * Fix #5381 NPE fix * Fix #5381 spring: fixed use of oneOf Models in API * Fix #5381 implementing oneOf for spring lib overriding methods with different behavior from default * Fix #5381 added x-is-one-of-interface extension for oneOf interface in mustache template * Fix #5381 fixed name of model from UNKNOWN_BASE_TYPE to right one in api: operationId + OneOf Fix #5381 removed not needed methods Fix #5381 fixed generation of oneOf Models Fix #5381 addOneOfInterfaceModel only for cases when useOneOfInterfaces is true and for spring Fix #5381 NPE fix for tests * Fix #5381 fixed handing of composed schema with array * Fix #5381 fixed NPE in addOneOfInterfaceModel * Fix #5381 fixed generation of oneOf models with descriminator * Initial merge of 5.0 * Aligned with master formatting * Corrected spacing for class names to align with samples. * Merged master * Updated samples * Consolidate methods from JavaClient and SpringCodegen (mov up to AbstractJavaCodegen) * set useLegacyDiscriminator to false, format templates * Suport JsonTypeName, fq class name for spring.io.Resource * Generate Samples * Test full qualified usage of the spring Resource interface. * Add java-camel to samples.circleci.spring profile * Add more complex example combining inheritance and oneof-interface * Remove x-implements Serializable from JavaClientCodegen (moved to AbstractJavaCodegen) * Fix spacing before opening brace after extends/implements * Generate Samples * Add more complex example combining inheritance and oneof-interface * Generate Samples * Fix JsonTypeName annotation handling in Java and JavaSpring * Content mediatype is hardcoded in api.mustache #11511 * Generate Samples * OAS3 incorrect data type when providing a default value #11367 * Generate Samples * Fix JsonTypeName annotation handling in Java and JavaSpring * Generate Samples * getIsClassnameSanitized: use null safe equals * Fix JsonTypeName annotation handling in Java and JavaSpring (merge) * Generate Samples * Generate Samples * Add oneof sample * Generate Samples * Giv example oas spec a meaningful name, demo usage of oneOf in Model * Generate Samples * Remove unnecessary JsonTypeName include, add example for JsonTypeName (Bar_Create) * Generate Samples * Generate Samples Co-authored-by: Alexej <[email protected]> Co-authored-by: JBurgess <[email protected]> Co-authored-by: William Cheng <[email protected]>
- Loading branch information
1 parent
a3fb571
commit e07c7d1
Showing
1,030 changed files
with
4,087 additions
and
1,027 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/server/petstore/spring-boot-oneof | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
documentationProvider: springdoc | ||
artifactId: springboot-oneof | ||
snapshotVersion: "true" | ||
hideGenerationTimestamp: "true" |
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
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
13 changes: 13 additions & 0 deletions
13
modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{>additionalModelTypeAnnotations}} | ||
{{#withXml}} | ||
{{>xmlAnnotation}} | ||
{{/withXml}} | ||
{{#discriminator}} | ||
{{>typeInfoAnnotation}} | ||
{{/discriminator}} | ||
{{>generatedAnnotation}} | ||
public interface {{classname}}{{#vendorExtensions.x-implements}}{{#-first}} extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} { | ||
{{#discriminator}} | ||
public {{propertyType}} {{propertyGetter}}(); | ||
{{/discriminator}} | ||
} |
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
18 changes: 14 additions & 4 deletions
18
modules/openapi-generator/src/main/resources/JavaSpring/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,11 +1,21 @@ | ||
{{#jackson}} | ||
{{#discriminator.mappedModels}} | ||
{{#-first}} | ||
@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, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true) | ||
@JsonSubTypes({ | ||
{{#discriminator.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}}"), | ||
{{/discriminator.mappedModels}} | ||
}){{/jackson}} | ||
{{/-first}} | ||
{{^vendorExtensions.x-discriminator-value}} | ||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{{mappingName}}}"){{^-last}},{{/-last}} | ||
{{/vendorExtensions.x-discriminator-value}} | ||
{{#vendorExtensions.x-discriminator-value}} | ||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{{vendorExtensions.x-discriminator-value}}}"){{^-last}},{{/-last}} | ||
{{/vendorExtensions.x-discriminator-value}} | ||
{{#-last}} | ||
}) | ||
{{/-last}} | ||
{{/discriminator.mappedModels}} | ||
{{/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
134 changes: 134 additions & 0 deletions
134
modules/openapi-generator/src/test/resources/3_0/issue_5381.yaml
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,134 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: ByRefOrValue | ||
description: > | ||
This tests for a oneOf interface representation | ||
version: 0.0.1 | ||
servers: | ||
- url: "http://localhost:8080" | ||
tags: | ||
- name: Foo | ||
paths: | ||
/foo: | ||
get: | ||
tags: | ||
- Foo | ||
summary: GET all Foos | ||
operationId: getAllFoos | ||
responses: | ||
'200': | ||
$ref: '#/components/responses/200FooArray' | ||
post: | ||
tags: | ||
- Foo | ||
summary: Create a Foo | ||
operationId: createFoo | ||
requestBody: | ||
$ref: '#/components/requestBodies/Foo' | ||
responses: | ||
'201': | ||
$ref: '#/components/responses/201Foo' | ||
|
||
components: | ||
schemas: | ||
Entity: | ||
type: object | ||
allOf: | ||
- "$ref": "#/components/schemas/Addressable" | ||
- "$ref": "#/components/schemas/Extensible" | ||
|
||
EntityRef: | ||
description: Entity reference schema to be use for all entityRef class. | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
description: Name of the related entity. | ||
'@referredType': | ||
type: string | ||
description: The actual type of the target instance when needed for disambiguation. | ||
allOf: | ||
- $ref: '#/components/schemas/Addressable' | ||
- "$ref": "#/components/schemas/Extensible" | ||
|
||
|
||
Addressable: | ||
type: object | ||
properties: | ||
href: | ||
type: string | ||
description: Hyperlink reference | ||
id: | ||
type: string | ||
description: unique identifier | ||
description: Base schema for adressable entities | ||
Extensible: | ||
type: object | ||
properties: | ||
"@schemaLocation": | ||
type: string | ||
description: A URI to a JSON-Schema file that defines additional attributes | ||
and relationships | ||
"@baseType": | ||
type: string | ||
description: When sub-classing, this defines the super-class | ||
"@type": | ||
type: string | ||
description: When sub-classing, this defines the sub-class Extensible name | ||
required: | ||
- '@type' | ||
|
||
FooRefOrValue: | ||
type: object | ||
oneOf: | ||
- $ref: "#/components/schemas/Foo" | ||
- $ref: "#/components/schemas/FooRef" | ||
discriminator: | ||
propertyName: "@type" | ||
mapping: | ||
Foo: "#/components/schemas/Foo" | ||
FooRef: "#/components/schemas/FooRef" | ||
|
||
Foo: | ||
type: object | ||
properties: | ||
fooPropA: | ||
type: string | ||
fooPropB: | ||
type: string | ||
allOf: | ||
- $ref: '#/components/schemas/Entity' | ||
|
||
FooRef: | ||
type: object | ||
properties: | ||
foorefPropA: | ||
type: string | ||
allOf: | ||
- $ref: '#/components/schemas/EntityRef' | ||
|
||
requestBodies: | ||
Foo: | ||
description: The Foo to be created | ||
content: | ||
application/json;charset=utf-8: | ||
schema: | ||
$ref: '#/components/schemas/Foo' | ||
responses: | ||
'204': | ||
description: Deleted | ||
content: { } | ||
201Foo: | ||
description: Error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/FooRefOrValue' | ||
200FooArray: | ||
description: Success | ||
content: | ||
application/json;charset=utf-8: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/FooRefOrValue' |
Oops, something went wrong.