Skip to content

Commit

Permalink
better handling of composed schema in inline model resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Nov 20, 2023
1 parent 6d93b0e commit 855fa11
Show file tree
Hide file tree
Showing 14 changed files with 859 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,7 @@ private void flattenProperties(OpenAPI openAPI, Map<String, Schema> properties,
} else {
LOGGER.debug("Schema not yet handled in model resolver: {}", inner);
}
}
if (ModelUtils.isMapSchema(property)) {
} else if (ModelUtils.isMapSchema(property)) {
Schema inner = ModelUtils.getAdditionalProperties(property);
if (inner instanceof ObjectSchema) {
ObjectSchema op = (ObjectSchema) inner;
Expand Down Expand Up @@ -852,6 +851,15 @@ private void flattenProperties(OpenAPI openAPI, Map<String, Schema> properties,
} else {
LOGGER.debug("Schema not yet handled in model resolver: {}", inner);
}
} else if (ModelUtils.isComposedSchema(property)) { // oneOf, anyOf, etc
String propertyModelName = resolveModelName(property.getTitle(), path + "_" + key);
gatherInlineModels(property, propertyModelName);
propertyModelName = addSchemas(propertyModelName, property);
Schema schema = new Schema().$ref(propertyModelName);
schema.setRequired(property.getRequired());
propsToUpdate.put(key, schema);
} else {
LOGGER.debug("Schema not yet handled in model resolver: {}", property);
}
}
if (propsToUpdate.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2493,3 +2493,10 @@ components:
- $ref: '#/components/schemas/Tag'
required:
- value
attributes:
type: object
properties:
C:
oneOf:
- $ref: '#/components/schemas/Pet'
- $ref: '#/components/schemas/Order'
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ build.gradle
build.sbt
docs/AdditionalPropertiesClass.md
docs/AllOfModelArrayAnyOf.md
docs/AllOfModelArrayAnyOfAllOfAttributes.md
docs/AllOfModelArrayAnyOfAllOfAttributesC.md
docs/AllOfModelArrayAnyOfAllOfLinkListColumn1.md
docs/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.md
docs/Animal.md
Expand Down Expand Up @@ -142,6 +144,8 @@ 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/AllOfModelArrayAnyOfAllOfAttributes.java
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.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
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/java/okhttp-gson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ Class | Method | HTTP request | Description

- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [AllOfModelArrayAnyOf](docs/AllOfModelArrayAnyOf.md)
- [AllOfModelArrayAnyOfAllOfAttributes](docs/AllOfModelArrayAnyOfAllOfAttributes.md)
- [AllOfModelArrayAnyOfAllOfAttributesC](docs/AllOfModelArrayAnyOfAllOfAttributesC.md)
- [AllOfModelArrayAnyOfAllOfLinkListColumn1](docs/AllOfModelArrayAnyOfAllOfLinkListColumn1.md)
- [AllOfModelArrayAnyOfAllOfLinkListColumn1Value](docs/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.md)
- [Animal](docs/Animal.md)
Expand Down
12 changes: 12 additions & 0 deletions samples/client/petstore/java/okhttp-gson/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,8 @@ components:
- properties:
linkListColumn1:
$ref: '#/components/schemas/AllOfModelArrayAnyOf_allOf_linkListColumn1'
attributes:
$ref: '#/components/schemas/AllOfModelArrayAnyOf_allOf_attributes'
type: object
_foo_get_default_response:
example:
Expand Down Expand Up @@ -2675,6 +2677,16 @@ components:
- value
type: object
example: null
AllOfModelArrayAnyOf_allOf_attributes_C:
oneOf:
- $ref: '#/components/schemas/Pet'
- $ref: '#/components/schemas/Order'
AllOfModelArrayAnyOf_allOf_attributes:
properties:
C:
$ref: '#/components/schemas/AllOfModelArrayAnyOf_allOf_attributes_C'
type: object
example: null
securitySchemes:
petstore_auth:
flows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
|**id** | **Long** | | [optional] |
|**name** | **String** | | |
|**linkListColumn1** | [**AllOfModelArrayAnyOfAllOfLinkListColumn1**](AllOfModelArrayAnyOfAllOfLinkListColumn1.md) | | [optional] |
|**attributes** | [**AllOfModelArrayAnyOfAllOfAttributes**](AllOfModelArrayAnyOfAllOfAttributes.md) | | [optional] |



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


# AllOfModelArrayAnyOfAllOfAttributes


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**C** | [**AllOfModelArrayAnyOfAllOfAttributesC**](AllOfModelArrayAnyOfAllOfAttributesC.md) | | [optional] |



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


# AllOfModelArrayAnyOfAllOfAttributesC


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**id** | **Long** | | [optional] |
|**category** | [**Category**](Category.md) | | [optional] |
|**name** | **String** | | |
|**photoUrls** | **List&lt;String&gt;** | | |
|**tags** | [**List&lt;Tag&gt;**](Tag.md) | | [optional] |
|**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional] |
|**petId** | **Long** | | [optional] |
|**quantity** | **Integer** | | [optional] |
|**shipDate** | **OffsetDateTime** | | [optional] |
|**complete** | **Boolean** | | [optional] |



## Enum: StatusEnum

| Name | Value |
|---- | -----|
| PLACED | &quot;placed&quot; |
| APPROVED | &quot;approved&quot; |
| DELIVERED | &quot;delivered&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri
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.AllOfModelArrayAnyOfAllOfAttributes.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOfAllOfAttributesC.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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Arrays;
import org.openapitools.client.model.AllOfModelArrayAnyOfAllOfAttributes;
import org.openapitools.client.model.AllOfModelArrayAnyOfAllOfLinkListColumn1;

import com.google.gson.Gson;
Expand Down Expand Up @@ -64,6 +65,10 @@ public class AllOfModelArrayAnyOf {
@SerializedName(SERIALIZED_NAME_LINK_LIST_COLUMN1)
private AllOfModelArrayAnyOfAllOfLinkListColumn1 linkListColumn1;

public static final String SERIALIZED_NAME_ATTRIBUTES = "attributes";
@SerializedName(SERIALIZED_NAME_ATTRIBUTES)
private AllOfModelArrayAnyOfAllOfAttributes attributes;

public AllOfModelArrayAnyOf() {
}

Expand Down Expand Up @@ -123,6 +128,25 @@ public void setLinkListColumn1(AllOfModelArrayAnyOfAllOfLinkListColumn1 linkList
this.linkListColumn1 = linkListColumn1;
}


public AllOfModelArrayAnyOf attributes(AllOfModelArrayAnyOfAllOfAttributes attributes) {
this.attributes = attributes;
return this;
}

/**
* Get attributes
* @return attributes
**/
@javax.annotation.Nullable
public AllOfModelArrayAnyOfAllOfAttributes getAttributes() {
return attributes;
}

public void setAttributes(AllOfModelArrayAnyOfAllOfAttributes attributes) {
this.attributes = attributes;
}

/**
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
Expand Down Expand Up @@ -180,13 +204,14 @@ public boolean equals(Object o) {
AllOfModelArrayAnyOf allOfModelArrayAnyOf = (AllOfModelArrayAnyOf) o;
return Objects.equals(this.id, allOfModelArrayAnyOf.id) &&
Objects.equals(this.name, allOfModelArrayAnyOf.name) &&
Objects.equals(this.linkListColumn1, allOfModelArrayAnyOf.linkListColumn1)&&
Objects.equals(this.linkListColumn1, allOfModelArrayAnyOf.linkListColumn1) &&
Objects.equals(this.attributes, allOfModelArrayAnyOf.attributes)&&
Objects.equals(this.additionalProperties, allOfModelArrayAnyOf.additionalProperties);
}

@Override
public int hashCode() {
return Objects.hash(id, name, linkListColumn1, additionalProperties);
return Objects.hash(id, name, linkListColumn1, attributes, additionalProperties);
}

@Override
Expand All @@ -196,6 +221,7 @@ public String toString() {
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" linkListColumn1: ").append(toIndentedString(linkListColumn1)).append("\n");
sb.append(" attributes: ").append(toIndentedString(attributes)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
Expand All @@ -222,6 +248,7 @@ private String toIndentedString(Object o) {
openapiFields.add("id");
openapiFields.add("name");
openapiFields.add("linkListColumn1");
openapiFields.add("attributes");

// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
Expand Down Expand Up @@ -255,6 +282,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if (jsonObj.get("linkListColumn1") != null && !jsonObj.get("linkListColumn1").isJsonNull()) {
AllOfModelArrayAnyOfAllOfLinkListColumn1.validateJsonElement(jsonObj.get("linkListColumn1"));
}
// validate the optional field `attributes`
if (jsonObj.get("attributes") != null && !jsonObj.get("attributes").isJsonNull()) {
AllOfModelArrayAnyOfAllOfAttributes.validateJsonElement(jsonObj.get("attributes"));
}
}

public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
Expand Down
Loading

0 comments on commit 855fa11

Please sign in to comment.