Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix discriminator override #1883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE
@Override
{{/parent}}
{{^parent}}
{{#isOverridden}}
{{#vendorExtensions.overridden}}
@Override
{{/isOverridden}}
{{/vendorExtensions.overridden}}
{{/parent}}
{{/isDiscriminator}}
public {{{vendorExtensions.typeWithEnumWithGenericAnnotations}}} {{getter}}() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1363,4 +1363,71 @@ void testSwaggerAnnotations() {
);
""");
}

@Test
void testDiscriminatorOverride() {

var codegen = new JavaMicronautClientCodegen();
codegen.setGenerateSwaggerAnnotations(true);
String outputPath = generateFiles(codegen, "src/test/resources/3_0/test-override-discriminator.yml", CodegenConstants.APIS, CodegenConstants.MODELS);
String path = outputPath + "src/main/java/org/openapitools/";

assertFileContains(path + "model/AnimalRequest.java",
"""
/**
* @return the valueType property value
*/
public String getValueType() {
return valueType;
}

/**
* Set the valueType property value
*
* @param valueType property value to set
*/
public void setValueType(String valueType) {
this.valueType = valueType;
}

/**
* Set valueType in a chainable fashion.
*
* @return The same instance of AnimalRequest for chaining.
*/
public AnimalRequest valueType(String valueType) {
this.valueType = valueType;
return this;
}
""");

assertFileContains(path + "model/AnimalResponse.java",
"""
/**
* @return the valueType property value
*/
public String getValueType() {
return valueType;
}

/**
* Set the valueType property value
*
* @param valueType property value to set
*/
public void setValueType(String valueType) {
this.valueType = valueType;
}

/**
* Set valueType in a chainable fashion.
*
* @return The same instance of AnimalResponse for chaining.
*/
public AnimalResponse valueType(String valueType) {
this.valueType = valueType;
return this;
}
""");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
openapi: 3.1.0
info:
version: '1.0.0'
title: 'OpenAPI BUG REST API'
servers:
- url: 'localhost:3000'

paths:
/api/v1/animals:
get:
tags: [ my-custom ]
operationId: "findAnimals"
responses:
"200":
description: "OK"
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/AnimalResponse'
post:
tags: [ my-custom ]
operationId: "saveAnimal"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/AnimalRequest"
responses:
"200":
description: "OK"

components:
schemas:

AnimalRequest:
type: object
properties:
name:
type: string
valueType:
type: string
discriminator:
propertyName: valueType
mapping:
catRq: '#/components/schemas/DogRequest'
dogRq: '#/components/schemas/CatRequest'

DogRequest:
allOf:
- $ref: '#/components/schemas/AnimalRequest'
- type: object
properties:
dogProperty:
type: string

CatRequest:
allOf:
- $ref: '#/components/schemas/AnimalRequest'
- type: object
properties:
catProperty:
type: string

AnimalResponse:
type: object
properties:
name:
type: string
valueType:
type: string
discriminator:
propertyName: valueType
mapping:
catRs: '#/components/schemas/DogResponse'
dogRs: '#/components/schemas/CatResponse'

DogResponse:
allOf:
- $ref: '#/components/schemas/AnimalResponse'
- type: object
properties:
dogProperty:
type: string

CatResponse:
allOf:
- $ref: '#/components/schemas/AnimalResponse'
- type: object
properties:
catProperty:
type: string

tags:
- name: my-custom
description: 'All API operations'
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public static boolean isIgnoredParameterType(ClassElement parameterType) {
// jax-rs
|| parameterType.isAssignable("jakarta.ws.rs.core.Application")
|| parameterType.isAssignable("jakarta.ws.rs.core.HttpHeaders")
|| parameterType.isAssignable("jakarta.ws.rs.core.Cookie")
|| parameterType.isAssignable("jakarta.ws.rs.core.Request")
|| parameterType.isAssignable("jakarta.ws.rs.core.SecurityContext")
|| parameterType.isAssignable("jakarta.ws.rs.core.UriInfo")
Expand Down
Loading