Skip to content

Commit

Permalink
fixed nullable schemas after 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
etremblay committed Jun 27, 2022
1 parent b535f32 commit 7dee4c1
Show file tree
Hide file tree
Showing 119 changed files with 284 additions and 16,554 deletions.
1 change: 1 addition & 0 deletions docs/generators/typescript-angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-aurelia.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-axios.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-inversify.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-jquery.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-nestjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-redux-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript-rxjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>object</li>
<li>string</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>null</li>
<li>number</li>
<li>string</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private boolean isModelNeeded(Schema schema) {
if (m.getAnyOf() != null && !m.getAnyOf().isEmpty()) {
return true;
}
if (m.getOneOf() != null && !m.getOneOf().isEmpty()) {
if (m.getOneOf() != null && !m.getOneOf().isEmpty() && !isNullableOneOfComposedSchema(m)) {
return true;
}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
}
m.setAnyOf(newAnyOf);
}
if (m.getOneOf() != null) {
if (m.getOneOf() != null && !isNullableOneOfComposedSchema(m)) {
List<Schema> newOneOf = new ArrayList<Schema>();
for (Schema inner : m.getOneOf()) {
String schemaName = resolveModelName(inner.getTitle(), modelPrefix + "_oneOf");
Expand Down Expand Up @@ -876,5 +876,17 @@ private String addSchemas(String name, Schema schema) {
return name;
}

private boolean isNullableOneOfComposedSchema(ComposedSchema schema) {
// OAS 3.0 oneOf with nullable attribute and single oneOf element
if (Boolean.TRUE.equals(schema.getNullable()) && schema.getOneOf() != null && schema.getOneOf().size() == 1) {
return true;
}

// OAS 3.1 nullable schema
if (ModelUtils.isNullableComposedSchema(schema)) {
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4215,12 +4215,6 @@ public void testNullabelObjectProperties() {
String propertyName;
CodegenProperty property;

// Non regression on regular oneOf construct
propertyName = "nonNullableProperty";
property = codegen.fromProperty(propertyName, (Schema) schema.getProperties().get(propertyName));
assertEquals(property.openApiType, "oneOf<string,number>");
// oneOf property resolve to any type and is set to nullable

// openapi 3.0 nullable
propertyName = "propertyName30";
property = codegen.fromProperty(propertyName, (Schema) schema.getProperties().get(propertyName));
Expand All @@ -4232,5 +4226,12 @@ public void testNullabelObjectProperties() {
property = codegen.fromProperty(propertyName, (Schema) schema.getProperties().get(propertyName));
assertEquals(property.openApiType, "PropertyType");
assertTrue(property.isNullable);

// Non regression on regular oneOf construct
propertyName = "nonNullableProperty";
property = codegen.fromProperty(propertyName, (Schema) schema.getProperties().get(propertyName));
assertEquals(property.openApiType, "ModelWithNullableObjectProperty_nonNullableProperty");
assertFalse(property.isNullable);
// oneOf property resolve to any type and is set to nullable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.openapitools.codegen.languages.AbstractTypeScriptClientCodegen;
import org.testng.annotations.Test;

import static org.junit.Assert.assertFalse;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

Expand Down Expand Up @@ -39,7 +40,8 @@ public void testNullabelObjectProperties() {
// Non regression on regular oneOf construct
propertyName = "nonNullableProperty";
property = codegen.fromProperty(propertyName, (Schema) schema.getProperties().get(propertyName));
assertEquals(property.openApiType, "string | number");
assertFalse(property.isNullable);
// assertEquals(property.openApiType, "string | number"); // Worked before #12104
// oneOf property resolve to any type and is set to nullable
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.junit.Assert.assertFalse;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

Expand Down Expand Up @@ -107,7 +108,8 @@ public void testNullabelObjectProperties() {
// Non regression on regular oneOf construct
propertyName = "nonNullableProperty";
property = codegen.fromProperty(propertyName, (Schema) schema.getProperties().get(propertyName));
assertEquals(property.openApiType, "string | number");
assertFalse(property.isNullable);
// assertEquals(property.openApiType, "string | number"); // Worked before #12104
// oneOf property resolve to any type and is set to nullable
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.github/workflows/maven.yml
.gitignore
.openapi-generator-ignore
.travis.yml
README.md
api/openapi.yaml
Expand All @@ -8,8 +9,6 @@ build.sbt
docs/DefaultApi.md
docs/ModelWithNullableObjectProperty.md
docs/ModelWithNullableObjectPropertyNonNullableProperty.md
docs/ModelWithNullableObjectPropertyPropertyName30.md
docs/ModelWithNullableObjectPropertyPropertyName31.md
docs/ModelWithNullableObjectPropertyPropertyWithNullAndTwoTypes.md
docs/OtherPropertyType.md
docs/PropertyType.md
Expand All @@ -35,8 +34,12 @@ src/main/java/org/openapitools/client/api/DefaultApi.java
src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java
src/main/java/org/openapitools/client/model/ModelWithNullableObjectProperty.java
src/main/java/org/openapitools/client/model/ModelWithNullableObjectPropertyNonNullableProperty.java
src/main/java/org/openapitools/client/model/ModelWithNullableObjectPropertyPropertyName30.java
src/main/java/org/openapitools/client/model/ModelWithNullableObjectPropertyPropertyName31.java
src/main/java/org/openapitools/client/model/ModelWithNullableObjectPropertyPropertyWithNullAndTwoTypes.java
src/main/java/org/openapitools/client/model/OtherPropertyType.java
src/main/java/org/openapitools/client/model/PropertyType.java
src/test/java/org/openapitools/client/api/DefaultApiTest.java
src/test/java/org/openapitools/client/model/ModelWithNullableObjectPropertyNonNullablePropertyTest.java
src/test/java/org/openapitools/client/model/ModelWithNullableObjectPropertyPropertyWithNullAndTwoTypesTest.java
src/test/java/org/openapitools/client/model/ModelWithNullableObjectPropertyTest.java
src/test/java/org/openapitools/client/model/OtherPropertyTypeTest.java
src/test/java/org/openapitools/client/model/PropertyTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ Class | Method | HTTP request | Description

- [ModelWithNullableObjectProperty](docs/ModelWithNullableObjectProperty.md)
- [ModelWithNullableObjectPropertyNonNullableProperty](docs/ModelWithNullableObjectPropertyNonNullableProperty.md)
- [ModelWithNullableObjectPropertyPropertyName30](docs/ModelWithNullableObjectPropertyPropertyName30.md)
- [ModelWithNullableObjectPropertyPropertyName31](docs/ModelWithNullableObjectPropertyPropertyName31.md)
- [ModelWithNullableObjectPropertyPropertyWithNullAndTwoTypes](docs/ModelWithNullableObjectPropertyPropertyWithNullAndTwoTypes.md)
- [OtherPropertyType](docs/OtherPropertyType.md)
- [PropertyType](docs/PropertyType.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ components:
propertyName:
foo: foo
nonNullableProperty: null
propertyName31: null
propertyName30: null
propertyName31: ""
propertyName30: ""
propertyWithNullAndTwoTypes: null
properties:
propertyName:
$ref: '#/components/schemas/PropertyType'
propertyName30:
$ref: '#/components/schemas/ModelWithNullableObjectProperty_propertyName30'
nullable: true
oneOf:
- $ref: '#/components/schemas/PropertyType'
propertyName31:
$ref: '#/components/schemas/ModelWithNullableObjectProperty_propertyName31'
oneOf:
- type: "null"
- $ref: '#/components/schemas/PropertyType'
nonNullableProperty:
$ref: '#/components/schemas/ModelWithNullableObjectProperty_nonNullableProperty'
propertyWithNullAndTwoTypes:
Expand All @@ -47,14 +51,6 @@ components:
properties:
bar:
type: string
ModelWithNullableObjectProperty_propertyName30:
nullable: true
oneOf:
- $ref: '#/components/schemas/PropertyType'
ModelWithNullableObjectProperty_propertyName31:
oneOf:
- type: "null"
- $ref: '#/components/schemas/PropertyType'
ModelWithNullableObjectProperty_nonNullableProperty:
oneOf:
- type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**propertyName** | [**PropertyType**](PropertyType.md) | | [optional] |
|**propertyName30** | [**ModelWithNullableObjectPropertyPropertyName30**](ModelWithNullableObjectPropertyPropertyName30.md) | | [optional] |
|**propertyName31** | [**ModelWithNullableObjectPropertyPropertyName31**](ModelWithNullableObjectPropertyPropertyName31.md) | | [optional] |
|**propertyName30** | [**PropertyType**](PropertyType.md) | | [optional] |
|**propertyName31** | [**PropertyType**](PropertyType.md) | | [optional] |
|**nonNullableProperty** | [**ModelWithNullableObjectPropertyNonNullableProperty**](ModelWithNullableObjectPropertyNonNullableProperty.md) | | [optional] |
|**propertyWithNullAndTwoTypes** | [**ModelWithNullableObjectPropertyPropertyWithNullAndTwoTypes**](ModelWithNullableObjectPropertyPropertyWithNullAndTwoTypes.md) | | [optional] |

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<jackson-version>2.13.0</jackson-version>
<jackson-databind-nullable-version>0.2.2</jackson-databind-nullable-version>
<jackson-databind-nullable-version>0.2.3</jackson-databind-nullable-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
<junit-version>4.13.2</junit-version>
</properties>
Expand Down
Loading

0 comments on commit 7dee4c1

Please sign in to comment.