Skip to content

Commit 79e2c2d

Browse files
committed
Add model name mapping option to rust generators (OpenAPITools#21282)
* add model name mapping option to rust generators * update package name * update samples
1 parent 8723d0e commit 79e2c2d

File tree

767 files changed

+623
-34098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

767 files changed

+623
-34098
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: rust
2+
outputDir: samples/client/petstore/rust/hyper/test-duplicates
3+
library: hyper
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/test_duplicates.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/rust
6+
additionalProperties:
7+
supportAsync: "false"
8+
packageName: test-duplicates-hyper
9+
modelNameMappings:
10+
Duplicatetest: another_test
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
generatorName: rust
2+
outputDir: samples/client/petstore/rust/reqwest/test-duplicates
3+
library: reqwest
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/test_duplicates.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/rust
6+
additionalProperties:
7+
supportAsync: false
8+
packageName: test-duplicates-reqwest
9+
enumNameMappings:
10+
delivered: shipped
11+
modelNameMappings:
12+
Duplicatetest: another_test

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ protected String addModelNamePrefixAndSuffix(String name) {
346346

347347
@Override
348348
public String toModelName(String name) {
349+
if (modelNameMapping.containsKey(name)) {
350+
return modelNameMapping.get(name);
351+
}
352+
349353
return sanitizeIdentifier(addModelNamePrefixAndSuffix(name), CasingType.CAMEL_CASE, "model", "model", false);
350354
}
351355

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

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -656,26 +656,6 @@ paths:
656656
application/json:
657657
schema:
658658
$ref: '#/components/schemas/TypeTesting'
659-
'/tests/discriminatorDuplicateEnums':
660-
get:
661-
tags:
662-
- testing
663-
summary: 'Test for duplicate enums when using discriminator. (One of the issues in #20500)'
664-
responses:
665-
'200':
666-
description: test
667-
content:
668-
application/json:
669-
schema:
670-
anyOf:
671-
- $ref: '#/components/schemas/Person'
672-
- $ref: '#/components/schemas/Vehicle'
673-
discriminator:
674-
propertyName: objectType
675-
mapping:
676-
student: '#/components/schemas/Person'
677-
teacher: '#/components/schemas/Person'
678-
car: '#/components/schemas/Vehicle'
679659
'/tests/allOfWithOneModel':
680660
get:
681661
tags:
@@ -1078,16 +1058,6 @@ components:
10781058
required:
10791059
- type
10801060
- speed
1081-
DuplicateTest:
1082-
type: object
1083-
properties:
1084-
name:
1085-
type: string
1086-
Duplicatetest: # explicitly testing the same name with different casing
1087-
type: object
1088-
properties:
1089-
name:
1090-
type: string
10911061
existing_tags_array:
10921062
type: array
10931063
items:
@@ -1107,3 +1077,30 @@ components:
11071077
allOf:
11081078
- $ref: '#/components/schemas/existing_tags_array'
11091079
- description: This is a test for allOf with metadata only fields
1080+
WithInnerOneOf:
1081+
type: object
1082+
properties:
1083+
foo:
1084+
type: object
1085+
oneOf:
1086+
- $ref: '#/components/schemas/Order'
1087+
- $ref: '#/components/schemas/Order'
1088+
Page:
1089+
type: object
1090+
properties:
1091+
page:
1092+
type: integer
1093+
format: int32
1094+
perPage:
1095+
type: integer
1096+
format: int32
1097+
parameters:
1098+
PageExplode:
1099+
name: pageExplode
1100+
in: query
1101+
description: Object containing page `size` and page `number`.
1102+
required: false
1103+
style: deepObject
1104+
explode: true
1105+
schema:
1106+
$ref: '#/components/schemas/Page'
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: 'http://petstore.swagger.io/v2'
4+
info:
5+
description: To test duplicates
6+
version: 1.0.0
7+
title: OpenAPI Petstore
8+
license:
9+
name: Apache-2.0
10+
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
11+
tags:
12+
- name: pet
13+
description: Everything about your Pets
14+
- name: store
15+
description: Access to Petstore orders
16+
- name: user
17+
description: Operations about user
18+
paths:
19+
'/tests/discriminatorDuplicateEnums':
20+
get:
21+
tags:
22+
- testing
23+
summary: 'Test for duplicate enums when using discriminator. (One of the issues in #20500)'
24+
responses:
25+
'200':
26+
description: test
27+
content:
28+
application/json:
29+
schema:
30+
anyOf:
31+
- $ref: '#/components/schemas/Person'
32+
- $ref: '#/components/schemas/Vehicle'
33+
discriminator:
34+
propertyName: objectType
35+
mapping:
36+
student: '#/components/schemas/Person'
37+
teacher: '#/components/schemas/Person'
38+
car: '#/components/schemas/Vehicle'
39+
externalDocs:
40+
description: Find out more about Swagger
41+
url: 'http://swagger.io'
42+
components:
43+
schemas:
44+
DuplicateTest:
45+
type: object
46+
properties:
47+
name:
48+
type: string
49+
Duplicatetest: # explicitly testing the same name with different casing
50+
type: object
51+
properties:
52+
name:
53+
type: string
54+
DuplicateOneOf:
55+
type: object
56+
oneOf:
57+
- $ref: '#/components/schemas/Person'
58+
- $ref: '#/components/schemas/Person'
59+
Person:
60+
type: object
61+
properties:
62+
type:
63+
type: string
64+
name:
65+
type: string
66+
required:
67+
- type
68+
- name
69+
Vehicle:
70+
type: object
71+
properties:
72+
type:
73+
type: string
74+
speed:
75+
type: number
76+
required:
77+
- type
78+
- speed

samples/client/petstore/rust/hyper/petstore/.openapi-generator/FILES

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ docs/ApiResponse.md
88
docs/ArrayItemRefTest.md
99
docs/Baz.md
1010
docs/Category.md
11-
docs/DuplicateTest.md
12-
docs/Duplicatetest.md
1311
docs/EnumArrayTesting.md
1412
docs/FakeApi.md
1513
docs/NullableArray.md
1614
docs/NumericEnumTesting.md
1715
docs/OptionalTesting.md
1816
docs/Order.md
17+
docs/Page.md
1918
docs/Person.md
2019
docs/Pet.md
2120
docs/PetApi.md
@@ -26,12 +25,12 @@ docs/StoreApi.md
2625
docs/Tag.md
2726
docs/TestAllOfWithMultiMetadataOnly.md
2827
docs/TestingApi.md
29-
docs/TestsDiscriminatorDuplicateEnumsGet200Response.md
3028
docs/TypeTesting.md
3129
docs/UniqueItemArrayTesting.md
3230
docs/User.md
3331
docs/UserApi.md
3432
docs/Vehicle.md
33+
docs/WithInnerOneOf.md
3534
git_push.sh
3635
src/apis/client.rs
3736
src/apis/configuration.rs
@@ -43,15 +42,12 @@ src/apis/store_api.rs
4342
src/apis/testing_api.rs
4443
src/apis/user_api.rs
4544
src/lib.rs
46-
src/models/_tests_discriminator_duplicate_enums_get_200_response.rs
4745
src/models/action_container.rs
4846
src/models/any_type_test.rs
4947
src/models/api_response.rs
5048
src/models/array_item_ref_test.rs
5149
src/models/baz.rs
5250
src/models/category.rs
53-
src/models/duplicate_test.rs
54-
src/models/duplicatetest.rs
5551
src/models/enum_array_testing.rs
5652
src/models/mod.rs
5753
src/models/model_ref.rs
@@ -60,6 +56,7 @@ src/models/nullable_array.rs
6056
src/models/numeric_enum_testing.rs
6157
src/models/optional_testing.rs
6258
src/models/order.rs
59+
src/models/page.rs
6360
src/models/person.rs
6461
src/models/pet.rs
6562
src/models/property_test.rs
@@ -69,3 +66,4 @@ src/models/type_testing.rs
6966
src/models/unique_item_array_testing.rs
7067
src/models/user.rs
7168
src/models/vehicle.rs
69+
src/models/with_inner_one_of.rs

samples/client/petstore/rust/hyper/petstore/.openapi-generator/VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
99

1010
- API version: 1.0.0
1111
- Package version: 1.0.0
12-
- Generator version: 7.13.0-SNAPSHOT
12+
- Generator version: 7.14.0-SNAPSHOT
1313
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`
1414

1515
## Installation
@@ -32,6 +32,8 @@ Class | Method | HTTP request | Description
3232
*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **Get** /pet/findByStatus | Finds Pets by status
3333
*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **Get** /pet/findByTags | Finds Pets by tags
3434
*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **Get** /pet/{petId} | Find pet by ID
35+
*PetApi* | [**pets_explode_post**](docs/PetApi.md#pets_explode_post) | **Post** /pets/explode | List all pets
36+
*PetApi* | [**pets_post**](docs/PetApi.md#pets_post) | **Post** /pets | List all pets
3537
*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **Put** /pet | Update an existing pet
3638
*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **Post** /pet/{petId} | Updates a pet in the store with form data
3739
*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **Post** /pet/{petId}/uploadImage | uploads an image
@@ -40,7 +42,6 @@ Class | Method | HTTP request | Description
4042
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID
4143
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **Post** /store/order | Place an order for a pet
4244
*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)
43-
*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)
4445
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **Get** /tests/fileResponse | Returns an image file
4546
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **Get** /tests/typeTesting | Route to test the TypeTesting schema
4647
*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **Post** /user | Create user
@@ -61,25 +62,24 @@ Class | Method | HTTP request | Description
6162
- [ArrayItemRefTest](docs/ArrayItemRefTest.md)
6263
- [Baz](docs/Baz.md)
6364
- [Category](docs/Category.md)
64-
- [DuplicateTest](docs/DuplicateTest.md)
65-
- [Duplicatetest](docs/Duplicatetest.md)
6665
- [EnumArrayTesting](docs/EnumArrayTesting.md)
6766
- [NullableArray](docs/NullableArray.md)
6867
- [NumericEnumTesting](docs/NumericEnumTesting.md)
6968
- [OptionalTesting](docs/OptionalTesting.md)
7069
- [Order](docs/Order.md)
70+
- [Page](docs/Page.md)
7171
- [Person](docs/Person.md)
7272
- [Pet](docs/Pet.md)
7373
- [PropertyTest](docs/PropertyTest.md)
7474
- [Ref](docs/Ref.md)
7575
- [Return](docs/Return.md)
7676
- [Tag](docs/Tag.md)
7777
- [TestAllOfWithMultiMetadataOnly](docs/TestAllOfWithMultiMetadataOnly.md)
78-
- [TestsDiscriminatorDuplicateEnumsGet200Response](docs/TestsDiscriminatorDuplicateEnumsGet200Response.md)
7978
- [TypeTesting](docs/TypeTesting.md)
8079
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
8180
- [User](docs/User.md)
8281
- [Vehicle](docs/Vehicle.md)
82+
- [WithInnerOneOf](docs/WithInnerOneOf.md)
8383

8484

8585
To get access to the crate's generated documentation, use:

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)