Skip to content

Commit 85ab65c

Browse files
authored
Fixed allOf with only one model (#20716)
1 parent a79aad8 commit 85ab65c

File tree

33 files changed

+712
-7
lines changed

33 files changed

+712
-7
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7196,7 +7196,7 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
71967196
Schema original = null;
71977197
// check if it's allOf (only 1 sub schema) with or without default/nullable/etc set in the top level
71987198
if (ModelUtils.isAllOf(schema) && schema.getAllOf().size() == 1 &&
7199-
ModelUtils.getType(schema) == null) {
7199+
(ModelUtils.getType(schema) == null || "object".equals(ModelUtils.getType(schema)))) {
72007200
if (schema.getAllOf().get(0) instanceof Schema) {
72017201
original = schema;
72027202
schema = (Schema) schema.getAllOf().get(0);
@@ -7849,7 +7849,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
78497849
Schema original = null;
78507850
// check if it's allOf (only 1 sub schema) with or without default/nullable/etc set in the top level
78517851
if (ModelUtils.isAllOf(schema) && schema.getAllOf().size() == 1 &&
7852-
ModelUtils.getType(schema) == null) {
7852+
(ModelUtils.getType(schema) == null || "object".equals(ModelUtils.getType(schema)))) {
78537853
if (schema.getAllOf().get(0) instanceof Schema) {
78547854
original = schema;
78557855
schema = (Schema) schema.getAllOf().get(0);

modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,11 +3990,6 @@ public void testComposedRequestBodyTypes() {
39903990
CodegenOperation co;
39913991
CodegenParameter cp;
39923992

3993-
path = "/ComposedObject";
3994-
co = codegen.fromOperation(path, "GET", openAPI.getPaths().get(path).getGet(), null);
3995-
cp = co.bodyParam;
3996-
assertTrue(cp.getIsMap());
3997-
39983993
path = "/ComposedNumber";
39993994
co = codegen.fromOperation(path, "GET", openAPI.getPaths().get(path).getGet(), null);
40003995
cp = co.bodyParam;

modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,26 @@ paths:
676676
student: '#/components/schemas/Person'
677677
teacher: '#/components/schemas/Person'
678678
car: '#/components/schemas/Vehicle'
679+
'/tests/allOfWithOneModel':
680+
get:
681+
tags:
682+
- testing
683+
summary: 'Test for allOf with a single option. (One of the issues in #20500)'
684+
requestBody:
685+
required: true
686+
content:
687+
application/json:
688+
schema:
689+
type: object
690+
allOf:
691+
- $ref: '#/components/schemas/Person'
692+
responses:
693+
'200':
694+
description: successful operation
695+
content:
696+
application/json:
697+
schema:
698+
type: string
679699
externalDocs:
680700
description: Find out more about Swagger
681701
url: 'http://swagger.io'

samples/client/petstore/rust/hyper/petstore/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Class | Method | HTTP request | Description
3939
*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **Get** /store/inventory | Returns pet inventories by status
4040
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID
4141
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **Post** /store/order | Place an order for a pet
42+
*TestingApi* | [**tests_all_of_with_one_model_get**](docs/TestingApi.md#tests_all_of_with_one_model_get) | **Get** /tests/allOfWithOneModel | Test for allOf with a single option. (One of the issues in #20500)
4243
*TestingApi* | [**tests_discriminator_duplicate_enums_get**](docs/TestingApi.md#tests_discriminator_duplicate_enums_get) | **Get** /tests/discriminatorDuplicateEnums | Test for duplicate enums when using discriminator. (One of the issues in #20500)
4344
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **Get** /tests/fileResponse | Returns an image file
4445
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **Get** /tests/typeTesting | Route to test the TypeTesting schema

samples/client/petstore/rust/hyper/petstore/docs/TestingApi.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,41 @@ All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7+
[**tests_all_of_with_one_model_get**](TestingApi.md#tests_all_of_with_one_model_get) | **Get** /tests/allOfWithOneModel | Test for allOf with a single option. (One of the issues in #20500)
78
[**tests_discriminator_duplicate_enums_get**](TestingApi.md#tests_discriminator_duplicate_enums_get) | **Get** /tests/discriminatorDuplicateEnums | Test for duplicate enums when using discriminator. (One of the issues in #20500)
89
[**tests_file_response_get**](TestingApi.md#tests_file_response_get) | **Get** /tests/fileResponse | Returns an image file
910
[**tests_type_testing_get**](TestingApi.md#tests_type_testing_get) | **Get** /tests/typeTesting | Route to test the TypeTesting schema
1011

1112

1213

14+
## tests_all_of_with_one_model_get
15+
16+
> String tests_all_of_with_one_model_get(person)
17+
Test for allOf with a single option. (One of the issues in #20500)
18+
19+
### Parameters
20+
21+
22+
Name | Type | Description | Required | Notes
23+
------------- | ------------- | ------------- | ------------- | -------------
24+
**person** | [**Person**](Person.md) | | [required] |
25+
26+
### Return type
27+
28+
**String**
29+
30+
### Authorization
31+
32+
No authorization required
33+
34+
### HTTP request headers
35+
36+
- **Content-Type**: application/json
37+
- **Accept**: application/json
38+
39+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
40+
41+
1342
## tests_discriminator_duplicate_enums_get
1443

1544
> models::TestsDiscriminatorDuplicateEnumsGet200Response tests_discriminator_duplicate_enums_get()

samples/client/petstore/rust/hyper/petstore/src/apis/testing_api.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,23 @@ impl<C: Connect> TestingApiClient<C>
3737
}
3838

3939
pub trait TestingApi: Send + Sync {
40+
fn tests_all_of_with_one_model_get(&self, person: models::Person) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send>>;
4041
fn tests_discriminator_duplicate_enums_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::TestsDiscriminatorDuplicateEnumsGet200Response, Error>> + Send>>;
4142
fn tests_file_response_get(&self, ) -> Pin<Box<dyn Future<Output = Result<std::path::PathBuf, Error>> + Send>>;
4243
fn tests_type_testing_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::TypeTesting, Error>> + Send>>;
4344
}
4445

4546
impl<C: Connect>TestingApi for TestingApiClient<C>
4647
where C: Clone + std::marker::Send + Sync {
48+
#[allow(unused_mut)]
49+
fn tests_all_of_with_one_model_get(&self, person: models::Person) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send>> {
50+
let mut req = __internal_request::Request::new(hyper::Method::GET, "/tests/allOfWithOneModel".to_string())
51+
;
52+
req = req.with_body_param(person);
53+
54+
req.execute(self.configuration.borrow())
55+
}
56+
4757
#[allow(unused_mut)]
4858
fn tests_discriminator_duplicate_enums_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::TestsDiscriminatorDuplicateEnumsGet200Response, Error>> + Send>> {
4959
let mut req = __internal_request::Request::new(hyper::Method::GET, "/tests/discriminatorDuplicateEnums".to_string())

samples/client/petstore/rust/hyper0x/petstore/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Class | Method | HTTP request | Description
3939
*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **GET** /store/inventory | Returns pet inventories by status
4040
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **GET** /store/order/{orderId} | Find purchase order by ID
4141
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **POST** /store/order | Place an order for a pet
42+
*TestingApi* | [**tests_all_of_with_one_model_get**](docs/TestingApi.md#tests_all_of_with_one_model_get) | **GET** /tests/allOfWithOneModel | Test for allOf with a single option. (One of the issues in #20500)
4243
*TestingApi* | [**tests_discriminator_duplicate_enums_get**](docs/TestingApi.md#tests_discriminator_duplicate_enums_get) | **GET** /tests/discriminatorDuplicateEnums | Test for duplicate enums when using discriminator. (One of the issues in #20500)
4344
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file
4445
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema

samples/client/petstore/rust/hyper0x/petstore/docs/TestingApi.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,41 @@ All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7+
[**tests_all_of_with_one_model_get**](TestingApi.md#tests_all_of_with_one_model_get) | **GET** /tests/allOfWithOneModel | Test for allOf with a single option. (One of the issues in #20500)
78
[**tests_discriminator_duplicate_enums_get**](TestingApi.md#tests_discriminator_duplicate_enums_get) | **GET** /tests/discriminatorDuplicateEnums | Test for duplicate enums when using discriminator. (One of the issues in #20500)
89
[**tests_file_response_get**](TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file
910
[**tests_type_testing_get**](TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema
1011

1112

1213

14+
## tests_all_of_with_one_model_get
15+
16+
> String tests_all_of_with_one_model_get(person)
17+
Test for allOf with a single option. (One of the issues in #20500)
18+
19+
### Parameters
20+
21+
22+
Name | Type | Description | Required | Notes
23+
------------- | ------------- | ------------- | ------------- | -------------
24+
**person** | [**Person**](Person.md) | | [required] |
25+
26+
### Return type
27+
28+
**String**
29+
30+
### Authorization
31+
32+
No authorization required
33+
34+
### HTTP request headers
35+
36+
- **Content-Type**: application/json
37+
- **Accept**: application/json
38+
39+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
40+
41+
1342
## tests_discriminator_duplicate_enums_get
1443

1544
> models::TestsDiscriminatorDuplicateEnumsGet200Response tests_discriminator_duplicate_enums_get()

samples/client/petstore/rust/hyper0x/petstore/src/apis/testing_api.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,23 @@ impl<C: hyper::client::connect::Connect> TestingApiClient<C>
3636
}
3737

3838
pub trait TestingApi {
39+
fn tests_all_of_with_one_model_get(&self, person: models::Person) -> Pin<Box<dyn Future<Output = Result<String, Error>>>>;
3940
fn tests_discriminator_duplicate_enums_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::TestsDiscriminatorDuplicateEnumsGet200Response, Error>>>>;
4041
fn tests_file_response_get(&self, ) -> Pin<Box<dyn Future<Output = Result<std::path::PathBuf, Error>>>>;
4142
fn tests_type_testing_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::TypeTesting, Error>>>>;
4243
}
4344

4445
impl<C: hyper::client::connect::Connect>TestingApi for TestingApiClient<C>
4546
where C: Clone + std::marker::Send + Sync {
47+
#[allow(unused_mut)]
48+
fn tests_all_of_with_one_model_get(&self, person: models::Person) -> Pin<Box<dyn Future<Output = Result<String, Error>>>> {
49+
let mut req = __internal_request::Request::new(hyper::Method::GET, "/tests/allOfWithOneModel".to_string())
50+
;
51+
req = req.with_body_param(person);
52+
53+
req.execute(self.configuration.borrow())
54+
}
55+
4656
#[allow(unused_mut)]
4757
fn tests_discriminator_duplicate_enums_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::TestsDiscriminatorDuplicateEnumsGet200Response, Error>>>> {
4858
let mut req = __internal_request::Request::new(hyper::Method::GET, "/tests/discriminatorDuplicateEnums".to_string())

samples/client/petstore/rust/reqwest-trait/petstore/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Class | Method | HTTP request | Description
3939
*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **GET** /store/inventory | Returns pet inventories by status
4040
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **GET** /store/order/{orderId} | Find purchase order by ID
4141
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **POST** /store/order | Place an order for a pet
42+
*TestingApi* | [**tests_all_of_with_one_model_get**](docs/TestingApi.md#tests_all_of_with_one_model_get) | **GET** /tests/allOfWithOneModel | Test for allOf with a single option. (One of the issues in #20500)
4243
*TestingApi* | [**tests_discriminator_duplicate_enums_get**](docs/TestingApi.md#tests_discriminator_duplicate_enums_get) | **GET** /tests/discriminatorDuplicateEnums | Test for duplicate enums when using discriminator. (One of the issues in #20500)
4344
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file
4445
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema

0 commit comments

Comments
 (0)