Skip to content

Commit

Permalink
fix null type check in normalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Jan 13, 2024
1 parent 51dbd32 commit 1a9a3db
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,17 @@ private boolean isNullTypeSchema(Schema schema) {
return true;
}

if ((schema.getType() == null || schema.getType().equals("null")) && schema.get$ref() == null) {
if (schema.getTypes() != null && !schema.getTypes().isEmpty()) {
// 3.1 spec
if (schema.getTypes().size() ==1) { // 1 type only
String type = (String) schema.getTypes().iterator().next();
return type == null || "null".equals(type);
} else { // more than 1 type so must not be just null
return false;
}
}

if ((schema.getType() == null || schema.getType().equals("null"))) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,3 +889,11 @@ components:
properties: {}
type: object
title: HTTPValidationError
AnyOfArray:
anyOf:
- type: array
items:
type: string
- type: array
items:
type: integer
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ api/openapi.yaml
build.gradle
build.sbt
docs/Animal.md
docs/AnyOfArray.md
docs/AnyTypeTest.md
docs/Cat.md
docs/Category.md
Expand Down Expand Up @@ -57,6 +58,7 @@ src/main/java/org/openapitools/client/auth/OAuthOkHttpClient.java
src/main/java/org/openapitools/client/auth/RetryingOAuth.java
src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java
src/main/java/org/openapitools/client/model/Animal.java
src/main/java/org/openapitools/client/model/AnyOfArray.java
src/main/java/org/openapitools/client/model/AnyTypeTest.java
src/main/java/org/openapitools/client/model/Cat.java
src/main/java/org/openapitools/client/model/Category.java
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Class | Method | HTTP request | Description
## Documentation for Models

- [Animal](docs/Animal.md)
- [AnyOfArray](docs/AnyOfArray.md)
- [AnyTypeTest](docs/AnyTypeTest.md)
- [Cat](docs/Cat.md)
- [Category](docs/Category.md)
Expand Down
6 changes: 6 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,12 @@ components:
properties: {}
title: HTTPValidationError
type: object
AnyOfArray:
anyOf:
- items:
type: string
- items:
type: integer
updatePetWithForm_request:
properties:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri
gsonBuilder.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter);
gsonBuilder.registerTypeAdapter(LocalDate.class, localDateTypeAdapter);
gsonBuilder.registerTypeAdapter(byte[].class, byteArrayAdapter);
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AnyOfArray.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AnyTypeTest.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Cat.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Category.CustomTypeAdapterFactory());
Expand Down

0 comments on commit 1a9a3db

Please sign in to comment.