Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2420819
better support of inline schema in array item
wing328 Apr 10, 2022
699a858
update tests
wing328 Apr 10, 2022
86e4cf2
update samples
wing328 Apr 10, 2022
e0c409e
Merge remote-tracking branch 'origin/master' into inline-model-resolver1
wing328 Apr 10, 2022
287b589
regenerate samples
wing328 Apr 11, 2022
24335b4
fix allof naming, remove files
wing328 Apr 11, 2022
40846c6
add files
wing328 Apr 11, 2022
a278634
update samples
wing328 Apr 11, 2022
019e7c9
update readme
wing328 Apr 11, 2022
63b7d02
fix tests
wing328 Apr 17, 2022
43afbb3
Merge remote-tracking branch 'origin/master' into inline-model-resolver1
wing328 Apr 17, 2022
13deddc
update samples
wing328 Apr 17, 2022
33dc94b
update samples
wing328 Apr 17, 2022
89f4fda
add new files
wing328 Apr 17, 2022
0157114
update test spec
wing328 Apr 18, 2022
d87f512
add back tests
wing328 Apr 18, 2022
f52e1f4
remove unused files
wing328 Apr 18, 2022
53cf35c
comment out python test
wing328 Apr 18, 2022
63a04f2
update js test using own spec
wing328 Apr 18, 2022
e94decd
remove files
wing328 Apr 18, 2022
0c66fb5
Merge remote-tracking branch 'origin/master' into inline-model-resolver1
wing328 Apr 18, 2022
354eafe
remove unused files
wing328 Apr 18, 2022
1e58cbd
remove files
wing328 Apr 18, 2022
7cd1854
remove unused files
wing328 Apr 18, 2022
0ef336a
better handling of allOf with a single type
wing328 Apr 18, 2022
ce929ef
comment out go test
wing328 Apr 18, 2022
a6135cf
remove test_all_of_with_single_ref_single_ref_type.py
wing328 Apr 19, 2022
9190fbb
fix inline resolver, uncomment go test
wing328 Apr 19, 2022
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
Prev Previous commit
Next Next commit
better handling of allOf with a single type
  • Loading branch information
wing328 committed Apr 18, 2022
commit 0ef336a777b69032b70843badf95f357d5a037da
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ private boolean isModelNeeded(Schema schema) {
// allOf, anyOf, oneOf
ComposedSchema m = (ComposedSchema) schema;
if (m.getAllOf() != null && !m.getAllOf().isEmpty()) {
return true;
// check to ensure at least of the allOf item is model
for (Schema inner : m.getAllOf()) {
if (isModelNeeded(inner)) {
return true;
}
}
// allOf items are all non-model (e.g. type: string) only
return false;
}
if (m.getAnyOf() != null && !m.getAnyOf().isEmpty()) {
return true;
Expand Down Expand Up @@ -176,6 +183,10 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
//Schema refSchema = this.makeSchemaResolve(modelPrefix, StringUtils.camelize(propName), prop);
Schema refSchema = this.makeSchemaResolve(modelPrefix, "_" + propName, prop);
props.put(propName, refSchema);
} else if (prop instanceof ComposedSchema && ((ComposedSchema)prop).getAllOf().size() == 1) {
// allOf with only 1 type
LOGGER.info("allOf schema used by the property `{}` replaced by its only item (a type).", propName);
props.put(propName, ((ComposedSchema)prop).getAllOf().get(0));
}
}
}
Expand Down Expand Up @@ -227,17 +238,30 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
ComposedSchema m = (ComposedSchema) schema;
if (m.getAllOf() != null) {
List<Schema> newAllOf = new ArrayList<Schema>();
boolean atLeastOneModel = false;
for (Schema inner : m.getAllOf()) {
// Recurse to create $refs for inner models
gatherInlineModels(inner, modelPrefix + "_allOf");
if (isModelNeeded(inner)) {
Schema refSchema = this.makeSchemaResolve(modelPrefix, "_allOf", inner);
newAllOf.add(refSchema); // replace with ref
atLeastOneModel = true;
} else {
newAllOf.add(inner);
}
}
m.setAllOf(newAllOf);
if (atLeastOneModel) {
m.setAllOf(newAllOf);
} else {
// allOf is just one or more types only so do not generate the inline allOf model
if (m.getAllOf().size() == 1) {
// handle earlier in this function when looping through properites
} else if (m.getAllOf().size() > 1) {
LOGGER.warn("allOf schema `{}` containing multiple types (not model) is not supported at the moment.", schema.getName());
} else {
LOGGER.error("allOf schema `{}` contains no items.", schema.getName());
}
}
}
if (m.getAnyOf() != null) {
List<Schema> newAnyOf = new ArrayList<Schema>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ build.bat
build.sh
docs/AdditionalPropertiesClass.md
docs/AllOfWithSingleRef.md
docs/AllOfWithSingleRefSingleRefType.md
docs/Animal.md
docs/AnotherFakeApi.md
docs/ApiResponse.md
Expand Down Expand Up @@ -81,7 +80,6 @@ src/Org.OpenAPITools/Client/IReadableConfiguration.cs
src/Org.OpenAPITools/Client/OpenAPIDateConverter.cs
src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs
src/Org.OpenAPITools/Model/AllOfWithSingleRef.cs
src/Org.OpenAPITools/Model/AllOfWithSingleRefSingleRefType.cs
src/Org.OpenAPITools/Model/Animal.cs
src/Org.OpenAPITools/Model/ApiResponse.cs
src/Org.OpenAPITools/Model/ArrayOfArrayOfNumberOnly.cs
Expand Down
1 change: 0 additions & 1 deletion samples/client/petstore/csharp/OpenAPIClient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ Class | Method | HTTP request | Description

- [Model.AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [Model.AllOfWithSingleRef](docs/AllOfWithSingleRef.md)
- [Model.AllOfWithSingleRefSingleRefType](docs/AllOfWithSingleRefSingleRefType.md)
- [Model.Animal](docs/Animal.md)
- [Model.ApiResponse](docs/ApiResponse.md)
- [Model.ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Username** | **string** | | [optional]
**SingleRefType** | [**AllOfWithSingleRefSingleRefType**](AllOfWithSingleRefSingleRefType.md) | | [optional]
**SingleRefType** | **SingleRefType** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models)
[[Back to API list]](../README.md#documentation-for-api-endpoints)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ namespace Org.OpenAPITools.Model
[DataContract]
public partial class AllOfWithSingleRef : IEquatable<AllOfWithSingleRef>, IValidatableObject
{
/// <summary>
/// Gets or Sets SingleRefType
/// </summary>
[DataMember(Name="SingleRefType", EmitDefaultValue=false)]
public SingleRefType? SingleRefType { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="AllOfWithSingleRef" /> class.
/// </summary>
/// <param name="username">username.</param>
/// <param name="singleRefType">singleRefType.</param>
public AllOfWithSingleRef(string username = default(string), AllOfWithSingleRefSingleRefType singleRefType = default(AllOfWithSingleRefSingleRefType))
public AllOfWithSingleRef(string username = default(string), SingleRefType? singleRefType = default(SingleRefType?))
{
this.Username = username;
this.SingleRefType = singleRefType;
Expand All @@ -47,11 +52,6 @@ public partial class AllOfWithSingleRef : IEquatable<AllOfWithSingleRef>, IVali
[DataMember(Name="username", EmitDefaultValue=false)]
public string Username { get; set; }

/// <summary>
/// Gets or Sets SingleRefType
/// </summary>
[DataMember(Name="SingleRefType", EmitDefaultValue=false)]
public AllOfWithSingleRefSingleRefType SingleRefType { get; set; }

/// <summary>
/// Returns the string presentation of the object
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion samples/client/petstore/elixir/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ lib/openapi_petstore/deserializer.ex
lib/openapi_petstore/model/_special_model_name_.ex
lib/openapi_petstore/model/additional_properties_class.ex
lib/openapi_petstore/model/all_of_with_single_ref.ex
lib/openapi_petstore/model/all_of_with_single_ref_single_ref_type.ex
lib/openapi_petstore/model/animal.ex
lib/openapi_petstore/model/api_response.ex
lib/openapi_petstore/model/array_of_array_of_number_only.ex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ defmodule OpenapiPetstore.Model.AllOfWithSingleRef do

@type t :: %__MODULE__{
:"username" => String.t | nil,
:"SingleRefType" => OpenapiPetstore.Model.AllOfWithSingleRefSingleRefType.t | nil
:"SingleRefType" => OpenapiPetstore.Model.SingleRefType.t | nil
}
end

defimpl Poison.Decoder, for: OpenapiPetstore.Model.AllOfWithSingleRef do
import OpenapiPetstore.Deserializer
def decode(value, options) do
value
|> deserialize(:"SingleRefType", :struct, OpenapiPetstore.Model.AllOfWithSingleRefSingleRefType, options)
|> deserialize(:"SingleRefType", :struct, OpenapiPetstore.Model.SingleRefType, options)
end
end

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ src/main/java/org/openapitools/client/auth/OauthClientCredentialsGrant.java
src/main/java/org/openapitools/client/auth/OauthPasswordGrant.java
src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java
src/main/java/org/openapitools/client/model/AllOfWithSingleRef.java
src/main/java/org/openapitools/client/model/AllOfWithSingleRefSingleRefType.java
src/main/java/org/openapitools/client/model/Animal.java
src/main/java/org/openapitools/client/model/ApiResponse.java
src/main/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnly.java
Expand Down
5 changes: 1 addition & 4 deletions samples/client/petstore/java/feign/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,7 @@ components:
username:
type: string
SingleRefType:
$ref: '#/components/schemas/AllOfWithSingleRef_SingleRefType'
$ref: '#/components/schemas/SingleRefType'
type: object
SingleRefType:
enum:
Expand Down Expand Up @@ -2280,9 +2280,6 @@ components:
declawed:
type: boolean
type: object
AllOfWithSingleRef_SingleRefType:
allOf:
- $ref: '#/components/schemas/SingleRefType'
securitySchemes:
petstore_auth:
flows:
Expand Down
Loading