Skip to content

Commit

Permalink
Fix handling of composed schema in inline model resolver (OpenAPITool…
Browse files Browse the repository at this point in the history
…s#17138)

* fix handling of composed schema in inline model resolver

* update samples
  • Loading branch information
wing328 committed Nov 19, 2023
1 parent 8e36014 commit 6d93b0e
Show file tree
Hide file tree
Showing 15 changed files with 1,310 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,15 @@ private void flattenProperties(OpenAPI openAPI, Map<String, Schema> properties,
ap.setItems(schema);
}
}
} else if (ModelUtils.isComposedSchema(inner)) {
String innerModelName = resolveModelName(inner.getTitle(), path + "_" + key);
gatherInlineModels(inner, innerModelName);
innerModelName = addSchemas(innerModelName, inner);
Schema schema = new Schema().$ref(innerModelName);
schema.setRequired(inner.getRequired());
ap.setItems(schema);
} else {
LOGGER.debug("Schema not yet handled in model resolver: {}", inner);
}
}
if (ModelUtils.isMapSchema(property)) {
Expand All @@ -833,6 +842,15 @@ private void flattenProperties(OpenAPI openAPI, Map<String, Schema> properties,
property.setAdditionalProperties(schema);
}
}
} else if (ModelUtils.isComposedSchema(inner)) {
String innerModelName = resolveModelName(inner.getTitle(), path + "_" + key);
gatherInlineModels(inner, innerModelName);
innerModelName = addSchemas(innerModelName, inner);
Schema schema = new Schema().$ref(innerModelName);
schema.setRequired(inner.getRequired());
property.setAdditionalProperties(schema);
} else {
LOGGER.debug("Schema not yet handled in model resolver: {}", inner);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2477,3 +2477,19 @@ components:
type: string
type_:
type: string
AllOfModelArrayAnyOf:
allOf:
- $ref: "#/components/schemas/Category"
- type: object
properties:
linkListColumn1:
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/User'
- $ref: '#/components/schemas/Tag'
required:
- value
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ api/openapi.yaml
build.gradle
build.sbt
docs/AdditionalPropertiesClass.md
docs/AllOfModelArrayAnyOf.md
docs/AllOfModelArrayAnyOfAllOfLinkListColumn1.md
docs/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.md
docs/Animal.md
docs/AnotherFakeApi.md
docs/Apple.md
Expand Down Expand Up @@ -138,6 +141,9 @@ 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/AdditionalPropertiesClass.java
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOf.java
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1.java
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java
src/main/java/org/openapitools/client/model/Animal.java
src/main/java/org/openapitools/client/model/Apple.java
src/main/java/org/openapitools/client/model/AppleReq.java
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/java/okhttp-gson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ Class | Method | HTTP request | Description
## Documentation for Models

- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [AllOfModelArrayAnyOf](docs/AllOfModelArrayAnyOf.md)
- [AllOfModelArrayAnyOfAllOfLinkListColumn1](docs/AllOfModelArrayAnyOfAllOfLinkListColumn1.md)
- [AllOfModelArrayAnyOfAllOfLinkListColumn1Value](docs/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.md)
- [Animal](docs/Animal.md)
- [Apple](docs/Apple.md)
- [AppleReq](docs/AppleReq.md)
Expand Down
21 changes: 21 additions & 0 deletions samples/client/petstore/java/okhttp-gson/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2471,6 +2471,13 @@ components:
type_:
type: string
type: object
AllOfModelArrayAnyOf:
allOf:
- $ref: '#/components/schemas/Category'
- properties:
linkListColumn1:
$ref: '#/components/schemas/AllOfModelArrayAnyOf_allOf_linkListColumn1'
type: object
_foo_get_default_response:
example:
string:
Expand Down Expand Up @@ -2654,6 +2661,20 @@ components:
required:
- name
type: object
AllOfModelArrayAnyOf_allOf_linkListColumn1_value:
anyOf:
- $ref: '#/components/schemas/User'
- $ref: '#/components/schemas/Tag'
AllOfModelArrayAnyOf_allOf_linkListColumn1:
properties:
value:
items:
$ref: '#/components/schemas/AllOfModelArrayAnyOf_allOf_linkListColumn1_value'
type: array
required:
- value
type: object
example: null
securitySchemes:
petstore_auth:
flows:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


# AllOfModelArrayAnyOf


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**id** | **Long** | | [optional] |
|**name** | **String** | | |
|**linkListColumn1** | [**AllOfModelArrayAnyOfAllOfLinkListColumn1**](AllOfModelArrayAnyOfAllOfLinkListColumn1.md) | | [optional] |



Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


# AllOfModelArrayAnyOfAllOfLinkListColumn1


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**value** | [**List&lt;AllOfModelArrayAnyOfAllOfLinkListColumn1Value&gt;**](AllOfModelArrayAnyOfAllOfLinkListColumn1Value.md) | | |



Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


# AllOfModelArrayAnyOfAllOfLinkListColumn1Value


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**id** | **Long** | | [optional] |
|**username** | **String** | | [optional] |
|**firstName** | **String** | | [optional] |
|**lastName** | **String** | | [optional] |
|**email** | **String** | | [optional] |
|**password** | **String** | | [optional] |
|**phone** | **String** | | [optional] |
|**userStatus** | **Integer** | User Status | [optional] |
|**objectWithNoDeclaredProps** | **Object** | test code generation for objects Value must be a map of strings to values. It cannot be the &#39;null&#39; value. | [optional] |
|**objectWithNoDeclaredPropsNullable** | **Object** | test code generation for nullable objects. Value must be a map of strings to values or the &#39;null&#39; value. | [optional] |
|**anyTypeProp** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional] |
|**anyTypePropNullable** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The &#39;nullable&#39; attribute does not change the allowed values. | [optional] |
|**name** | **String** | | [optional] |



Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri
gsonBuilder.registerTypeAdapter(LocalDate.class, localDateTypeAdapter);
gsonBuilder.registerTypeAdapter(byte[].class, byteArrayAdapter);
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesClass.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOf.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOfAllOfLinkListColumn1.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOfAllOfLinkListColumn1Value.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Apple.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AppleReq.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayDefault.CustomTypeAdapterFactory());
Expand Down
Loading

0 comments on commit 6d93b0e

Please sign in to comment.