Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.responses.ApiResponses;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -417,7 +418,18 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
if (schema.getAllOf().size() == 1) {
// handle earlier in this function when looping through properties
} else if (schema.getAllOf().size() > 1) {
LOGGER.warn("allOf schema `{}` containing multiple types (not model) is not supported at the moment.", schema.getName());
// Check if there is only one "non metadata" schema.
// For example, there may be an `description` only schema that is used to override the descrption.
// In these cases, we can simply discard those schemas.
List<Schema> nonMetadataOnlySchemas = (List<Schema>) schema.getAllOf().stream()
.filter(v -> ModelUtils.isMetadataOnlySchema((Schema) v))
.collect(Collectors.toList());

if (nonMetadataOnlySchemas.size() == 1) {
schema.setAllOf(nonMetadataOnlySchemas);
} else {
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,32 @@ public static boolean isUnsupportedSchema(OpenAPI openAPI, Schema schema) {
return false;
}

/**
* Returns true if a schema is only metadata and not an actual type.
* For example, a schema that only has a `description` without any `properties` or `$ref` defined.
*
* @param schema the schema
* @return if the schema is only metadata and not an actual type
*/
public static boolean isMetadataOnlySchema(Schema schema) {
return schema.get$ref() != null ||
schema.getProperties() != null ||
schema.getType() != null ||
schema.getAdditionalProperties() != null ||
schema.getAllOf() != null ||
schema.getAnyOf() != null ||
schema.getOneOf() != null ||
schema.getPrefixItems() != null ||
schema.getItems() != null ||
schema.getTypes() != null ||
schema.getPatternProperties() != null ||
schema.getContains() != null ||
schema.get$dynamicAnchor() != null ||
schema.get$anchor() != null ||
schema.getContentSchema() != null;
}


@FunctionalInterface
private interface OpenAPISchemaVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,3 +1088,22 @@ components:
properties:
name:
type: string
existing_tags_array:
type: array
items:
type: string
nullable: true
description: 'existing_tags_array'
example:
- base-image
- prod
TestAllOfWithMultiMetadataOnly:
type: object
properties:
id:
type: integer
format: int64
foo:
allOf:
- $ref: '#/components/schemas/existing_tags_array'
- description: This is a test for allOf with metadata only fields
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class_name DemoActionContainerModel

# Required: True
# isArray: false
@export var action: DemoBazModel:
@export var action: Baz:
set(value):
__action__was__set = true
action = value
Expand All @@ -37,7 +37,7 @@ func bzz_normalize() -> Dictionary:
static func bzz_denormalize_single(from_dict: Dictionary):
var me := new()
if from_dict.has("action"):
me.action = DemoBazModel.bzz_denormalize_single(from_dict["action"])
me.action = from_dict["action"]
return me


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ docs/Ref.md
docs/Return.md
docs/StoreApi.md
docs/Tag.md
docs/TestAllOfWithMultiMetadataOnly.md
docs/TestingApi.md
docs/TestsDiscriminatorDuplicateEnumsGet200Response.md
docs/TypeTesting.md
Expand Down Expand Up @@ -63,6 +64,7 @@ src/models/person.rs
src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/test_all_of_with_multi_metadata_only.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/rust/hyper/petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Class | Method | HTTP request | Description
- [Ref](docs/Ref.md)
- [Return](docs/Return.md)
- [Tag](docs/Tag.md)
- [TestAllOfWithMultiMetadataOnly](docs/TestAllOfWithMultiMetadataOnly.md)
- [TestsDiscriminatorDuplicateEnumsGet200Response](docs/TestsDiscriminatorDuplicateEnumsGet200Response.md)
- [TypeTesting](docs/TypeTesting.md)
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# TestAllOfWithMultiMetadataOnly

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | Option<**i64**> | | [optional]
**foo** | Option<**Vec<String>**> | existing_tags_array | [optional]

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


Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct ActionContainer {
#[serde(rename = "action")]
pub action: Box<models::Baz>,
pub action: models::Baz,
}

impl ActionContainer {
pub fn new(action: models::Baz) -> ActionContainer {
ActionContainer {
action: Box::new(action),
action,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/rust/hyper/petstore/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod model_return;
pub use self::model_return::Return;
pub mod tag;
pub use self::tag::Tag;
pub mod test_all_of_with_multi_metadata_only;
pub use self::test_all_of_with_multi_metadata_only::TestAllOfWithMultiMetadataOnly;
pub mod _tests_discriminator_duplicate_enums_get_200_response;
pub use self::_tests_discriminator_duplicate_enums_get_200_response::TestsDiscriminatorDuplicateEnumsGet200Response;
pub mod type_testing;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TestAllOfWithMultiMetadataOnly {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>,
/// existing_tags_array
#[serde(rename = "foo", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub foo: Option<Option<Vec<String>>>,
}

impl TestAllOfWithMultiMetadataOnly {
pub fn new() -> TestAllOfWithMultiMetadataOnly {
TestAllOfWithMultiMetadataOnly {
id: None,
foo: None,
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ docs/Ref.md
docs/Return.md
docs/StoreApi.md
docs/Tag.md
docs/TestAllOfWithMultiMetadataOnly.md
docs/TestingApi.md
docs/TestsDiscriminatorDuplicateEnumsGet200Response.md
docs/TypeTesting.md
Expand Down Expand Up @@ -61,6 +62,7 @@ src/models/person.rs
src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/test_all_of_with_multi_metadata_only.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/rust/hyper0x/petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Class | Method | HTTP request | Description
- [Ref](docs/Ref.md)
- [Return](docs/Return.md)
- [Tag](docs/Tag.md)
- [TestAllOfWithMultiMetadataOnly](docs/TestAllOfWithMultiMetadataOnly.md)
- [TestsDiscriminatorDuplicateEnumsGet200Response](docs/TestsDiscriminatorDuplicateEnumsGet200Response.md)
- [TypeTesting](docs/TypeTesting.md)
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# TestAllOfWithMultiMetadataOnly

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | Option<**i64**> | | [optional]
**foo** | Option<**Vec<String>**> | existing_tags_array | [optional]

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


Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct ActionContainer {
#[serde(rename = "action")]
pub action: Box<models::Baz>,
pub action: models::Baz,
}

impl ActionContainer {
pub fn new(action: models::Baz) -> ActionContainer {
ActionContainer {
action: Box::new(action),
action,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod model_return;
pub use self::model_return::Return;
pub mod tag;
pub use self::tag::Tag;
pub mod test_all_of_with_multi_metadata_only;
pub use self::test_all_of_with_multi_metadata_only::TestAllOfWithMultiMetadataOnly;
pub mod _tests_discriminator_duplicate_enums_get_200_response;
pub use self::_tests_discriminator_duplicate_enums_get_200_response::TestsDiscriminatorDuplicateEnumsGet200Response;
pub mod type_testing;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TestAllOfWithMultiMetadataOnly {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>,
/// existing_tags_array
#[serde(rename = "foo", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub foo: Option<Option<Vec<String>>>,
}

impl TestAllOfWithMultiMetadataOnly {
pub fn new() -> TestAllOfWithMultiMetadataOnly {
TestAllOfWithMultiMetadataOnly {
id: None,
foo: None,
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ docs/Ref.md
docs/Return.md
docs/StoreApi.md
docs/Tag.md
docs/TestAllOfWithMultiMetadataOnly.md
docs/TestingApi.md
docs/TestsDiscriminatorDuplicateEnumsGet200Response.md
docs/TypeTesting.md
Expand Down Expand Up @@ -61,6 +62,7 @@ src/models/person.rs
src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/test_all_of_with_multi_metadata_only.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Class | Method | HTTP request | Description
- [Ref](docs/Ref.md)
- [Return](docs/Return.md)
- [Tag](docs/Tag.md)
- [TestAllOfWithMultiMetadataOnly](docs/TestAllOfWithMultiMetadataOnly.md)
- [TestsDiscriminatorDuplicateEnumsGet200Response](docs/TestsDiscriminatorDuplicateEnumsGet200Response.md)
- [TypeTesting](docs/TypeTesting.md)
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# TestAllOfWithMultiMetadataOnly

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | Option<**i64**> | | [optional]
**foo** | Option<**Vec<String>**> | existing_tags_array | [optional]

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


Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct ActionContainer {
#[serde(rename = "action")]
pub action: Box<models::Baz>,
pub action: models::Baz,
}

impl ActionContainer {
pub fn new(action: models::Baz) -> ActionContainer {
ActionContainer {
action: Box::new(action),
action,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod model_return;
pub use self::model_return::Return;
pub mod tag;
pub use self::tag::Tag;
pub mod test_all_of_with_multi_metadata_only;
pub use self::test_all_of_with_multi_metadata_only::TestAllOfWithMultiMetadataOnly;
pub mod _tests_discriminator_duplicate_enums_get_200_response;
pub use self::_tests_discriminator_duplicate_enums_get_200_response::TestsDiscriminatorDuplicateEnumsGet200Response;
pub mod type_testing;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TestAllOfWithMultiMetadataOnly {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>,
/// existing_tags_array
#[serde(rename = "foo", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub foo: Option<Option<Vec<String>>>,
}

impl TestAllOfWithMultiMetadataOnly {
pub fn new() -> TestAllOfWithMultiMetadataOnly {
TestAllOfWithMultiMetadataOnly {
id: None,
foo: None,
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ docs/Ref.md
docs/Return.md
docs/StoreApi.md
docs/Tag.md
docs/TestAllOfWithMultiMetadataOnly.md
docs/TestingApi.md
docs/TestsDiscriminatorDuplicateEnumsGet200Response.md
docs/TypeTesting.md
Expand Down Expand Up @@ -61,6 +62,7 @@ src/models/person.rs
src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/test_all_of_with_multi_metadata_only.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
Expand Down
Loading
Loading