Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -6331,8 +6331,12 @@ protected void addVars(IJsonSchemaValidationProperties m, List<CodegenProperty>
cp = fromProperty(key, prop, mandatory.contains(key));
}

if (cm != null && cm.allVars == vars && cp.isOverridden == null) { // processing allVars and it's a parent property
cp.isOverridden = true;
if (cm != null && cm.allVars == vars) {
// Processing allVars: a property is overridden when it comes from the parent rather than
// being declared by this model. fromProperty caches CodegenProperty instances, so the flag
// must be assigned rather than only filled in when unset - a cached instance may already
// carry a value from whichever model happened to be processed first.
cp.isOverridden = !varsMap.containsKey(key);
}

vars.add(cp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,23 @@ public void testIsOverriddenProperty() {
Assertions.assertEquals(cp1.isOverridden, false);
}

@Test
public void testOverrideSetterWhenChildIsDeclaredBeforeParent() {
final Path output = newTempFolder();
OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/3_0/allOf_composition_discriminator_child_first.yaml", null, null)
.getOpenAPI();

JavaClientCodegen codegen = new JavaClientCodegen();
codegen.setOutputDir(output.toString());
codegen.setLibrary(JavaClientCodegen.APACHE);

new DefaultGenerator().opts(new ClientOptInput().openAPI(openAPI).config(codegen)).generate();

assertThat(output.resolve("src/main/java/org/openapitools/client/model/Cat.java")).content()
.contains(" @Override\n public Cat petType(@javax.annotation.Nonnull String petType) {");
}

@Test
public void testForJavaApacheHttpClientOverrideSetter() {
final Path output = newTempFolder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
openapi: 3.0.2
info:
title: OAI Specification example for Polymorphism
version: 1.0.0
paths:
/pet:
get:
responses:
'200':
description: desc
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
MyPets:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: petType
Pet:
type: object
required:
- petType
properties:
petType:
type: string
discriminator:
propertyName: petType
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
name:
type: string
characteristics:
$ref: '#/components/schemas/Characteristics'
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
bark:
type: string
Characteristics:
type: object
properties:
canHunt:
type: boolean
Loading