Skip to content
Open
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public BarRef atType(@jakarta.annotation.Nonnull String atType) {
return this;
}

@Override
public BarRef name(@jakarta.annotation.Nullable String name) {
this.setName(name);
return this;
}

@Override
public BarRef atReferredType(@jakarta.annotation.Nullable String atReferredType) {
this.setAtReferredType(atReferredType);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ public FooRef atType(@jakarta.annotation.Nonnull String atType) {
return this;
}

@Override
public FooRef name(@jakarta.annotation.Nullable String name) {
this.setName(name);
return this;
}

@Override
public FooRef atReferredType(@jakarta.annotation.Nullable String atReferredType) {
this.setAtReferredType(atReferredType);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public PizzaSpeziale atType(@jakarta.annotation.Nonnull String atType) {
return this;
}

@Override
public PizzaSpeziale pizzaSize(@jakarta.annotation.Nullable BigDecimal pizzaSize) {
this.setPizzaSize(pizzaSize);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ public void setFoo(@javax.annotation.Nullable FooRefOrValue foo) {
}


@Override
public Bar href(@javax.annotation.Nullable String href) {
this.setHref(href);
return this;
}

@Override
public Bar atSchemaLocation(@javax.annotation.Nullable String atSchemaLocation) {
this.setAtSchemaLocation(atSchemaLocation);
return this;
}

@Override
public Bar atBaseType(@javax.annotation.Nullable String atBaseType) {
this.setAtBaseType(atBaseType);
return this;
}

@Override
public Bar atType(@javax.annotation.Nonnull String atType) {
this.setAtType(atType);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,36 @@ public void setFoo(@javax.annotation.Nullable FooRefOrValue foo) {
}


@Override
public BarCreate href(@javax.annotation.Nullable String href) {
this.setHref(href);
return this;
}

@Override
public BarCreate id(@javax.annotation.Nullable String id) {
this.setId(id);
return this;
}

@Override
public BarCreate atSchemaLocation(@javax.annotation.Nullable String atSchemaLocation) {
this.setAtSchemaLocation(atSchemaLocation);
return this;
}

@Override
public BarCreate atBaseType(@javax.annotation.Nullable String atBaseType) {
this.setAtBaseType(atBaseType);
return this;
}

@Override
public BarCreate atType(@javax.annotation.Nonnull String atType) {
this.setAtType(atType);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,48 @@ public BarRef() {
}


@Override
public BarRef href(@javax.annotation.Nullable String href) {
this.setHref(href);
return this;
}

@Override
public BarRef id(@javax.annotation.Nullable String id) {
this.setId(id);
return this;
}

@Override
public BarRef atSchemaLocation(@javax.annotation.Nullable String atSchemaLocation) {
this.setAtSchemaLocation(atSchemaLocation);
return this;
}

@Override
public BarRef atBaseType(@javax.annotation.Nullable String atBaseType) {
this.setAtBaseType(atBaseType);
return this;
}

@Override
public BarRef atType(@javax.annotation.Nonnull String atType) {
this.setAtType(atType);
return this;
}

@Override
public BarRef name(@javax.annotation.Nullable String name) {
this.setName(name);
return this;
}

@Override
public BarRef atReferredType(@javax.annotation.Nullable String atReferredType) {
this.setAtReferredType(atReferredType);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,36 @@ public void setFooPropB(@javax.annotation.Nullable String fooPropB) {
}


@Override
public Foo href(@javax.annotation.Nullable String href) {
this.setHref(href);
return this;
}

@Override
public Foo id(@javax.annotation.Nullable String id) {
this.setId(id);
return this;
}

@Override
public Foo atSchemaLocation(@javax.annotation.Nullable String atSchemaLocation) {
this.setAtSchemaLocation(atSchemaLocation);
return this;
}

@Override
public Foo atBaseType(@javax.annotation.Nullable String atBaseType) {
this.setAtBaseType(atBaseType);
return this;
}

@Override
public Foo atType(@javax.annotation.Nonnull String atType) {
this.setAtType(atType);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,48 @@ public void setFoorefPropA(@javax.annotation.Nullable String foorefPropA) {
}


@Override
public FooRef href(@javax.annotation.Nullable String href) {
this.setHref(href);
return this;
}

@Override
public FooRef id(@javax.annotation.Nullable String id) {
this.setId(id);
return this;
}

@Override
public FooRef atSchemaLocation(@javax.annotation.Nullable String atSchemaLocation) {
this.setAtSchemaLocation(atSchemaLocation);
return this;
}

@Override
public FooRef atBaseType(@javax.annotation.Nullable String atBaseType) {
this.setAtBaseType(atBaseType);
return this;
}

@Override
public FooRef atType(@javax.annotation.Nonnull String atType) {
this.setAtType(atType);
return this;
}

@Override
public FooRef name(@javax.annotation.Nullable String name) {
this.setName(name);
return this;
}

@Override
public FooRef atReferredType(@javax.annotation.Nullable String atReferredType) {
this.setAtReferredType(atReferredType);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ public void setVendor(@javax.annotation.Nullable String vendor) {
}


@Override
public Pasta href(@javax.annotation.Nullable String href) {
this.setHref(href);
return this;
}

@Override
public Pasta id(@javax.annotation.Nullable String id) {
this.setId(id);
return this;
}

@Override
public Pasta atSchemaLocation(@javax.annotation.Nullable String atSchemaLocation) {
this.setAtSchemaLocation(atSchemaLocation);
return this;
}

@Override
public Pasta atBaseType(@javax.annotation.Nullable String atBaseType) {
this.setAtBaseType(atBaseType);
return this;
}

@Override
public Pasta atType(@javax.annotation.Nonnull String atType) {
this.setAtType(atType);
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Loading
Loading