Skip to content

Commit 0bfce24

Browse files
authored
Add model name mapping option to rust generators (#21282)
* add model name mapping option to rust generators * update package name * update samples
1 parent 4089438 commit 0bfce24

File tree

233 files changed

+1444
-3987
lines changed

Some content is hidden

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

233 files changed

+1444
-3987
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: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -699,26 +699,6 @@ paths:
699699
application/json:
700700
schema:
701701
$ref: '#/components/schemas/TypeTesting'
702-
'/tests/discriminatorDuplicateEnums':
703-
get:
704-
tags:
705-
- testing
706-
summary: 'Test for duplicate enums when using discriminator. (One of the issues in #20500)'
707-
responses:
708-
'200':
709-
description: test
710-
content:
711-
application/json:
712-
schema:
713-
anyOf:
714-
- $ref: '#/components/schemas/Person'
715-
- $ref: '#/components/schemas/Vehicle'
716-
discriminator:
717-
propertyName: objectType
718-
mapping:
719-
student: '#/components/schemas/Person'
720-
teacher: '#/components/schemas/Person'
721-
car: '#/components/schemas/Vehicle'
722702
'/tests/allOfWithOneModel':
723703
get:
724704
tags:
@@ -1121,16 +1101,6 @@ components:
11211101
required:
11221102
- type
11231103
- speed
1124-
DuplicateTest:
1125-
type: object
1126-
properties:
1127-
name:
1128-
type: string
1129-
Duplicatetest: # explicitly testing the same name with different casing
1130-
type: object
1131-
properties:
1132-
name:
1133-
type: string
11341104
existing_tags_array:
11351105
type: array
11361106
items:
@@ -1150,11 +1120,6 @@ components:
11501120
allOf:
11511121
- $ref: '#/components/schemas/existing_tags_array'
11521122
- description: This is a test for allOf with metadata only fields
1153-
DuplicateOneOf:
1154-
type: object
1155-
oneOf:
1156-
- $ref: '#/components/schemas/Order'
1157-
- $ref: '#/components/schemas/Order'
11581123
WithInnerOneOf:
11591124
type: object
11601125
properties:
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: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ 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
@@ -27,7 +25,6 @@ docs/StoreApi.md
2725
docs/Tag.md
2826
docs/TestAllOfWithMultiMetadataOnly.md
2927
docs/TestingApi.md
30-
docs/TestsDiscriminatorDuplicateEnumsGet200Response.md
3128
docs/TypeTesting.md
3229
docs/UniqueItemArrayTesting.md
3330
docs/User.md
@@ -45,15 +42,12 @@ src/apis/store_api.rs
4542
src/apis/testing_api.rs
4643
src/apis/user_api.rs
4744
src/lib.rs
48-
src/models/_tests_discriminator_duplicate_enums_get_200_response.rs
4945
src/models/action_container.rs
5046
src/models/any_type_test.rs
5147
src/models/api_response.rs
5248
src/models/array_item_ref_test.rs
5349
src/models/baz.rs
5450
src/models/category.rs
55-
src/models/duplicate_test.rs
56-
src/models/duplicatetest.rs
5751
src/models/enum_array_testing.rs
5852
src/models/mod.rs
5953
src/models/model_ref.rs

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Class | Method | HTTP request | Description
4242
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID
4343
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **Post** /store/order | Place an order for a pet
4444
*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)
45-
*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)
4645
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **Get** /tests/fileResponse | Returns an image file
4746
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **Get** /tests/typeTesting | Route to test the TypeTesting schema
4847
*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **Post** /user | Create user
@@ -63,8 +62,6 @@ Class | Method | HTTP request | Description
6362
- [ArrayItemRefTest](docs/ArrayItemRefTest.md)
6463
- [Baz](docs/Baz.md)
6564
- [Category](docs/Category.md)
66-
- [DuplicateTest](docs/DuplicateTest.md)
67-
- [Duplicatetest](docs/Duplicatetest.md)
6865
- [EnumArrayTesting](docs/EnumArrayTesting.md)
6966
- [NullableArray](docs/NullableArray.md)
7067
- [NumericEnumTesting](docs/NumericEnumTesting.md)
@@ -78,7 +75,6 @@ Class | Method | HTTP request | Description
7875
- [Return](docs/Return.md)
7976
- [Tag](docs/Tag.md)
8077
- [TestAllOfWithMultiMetadataOnly](docs/TestAllOfWithMultiMetadataOnly.md)
81-
- [TestsDiscriminatorDuplicateEnumsGet200Response](docs/TestsDiscriminatorDuplicateEnumsGet200Response.md)
8278
- [TypeTesting](docs/TypeTesting.md)
8379
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
8480
- [User](docs/User.md)

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

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

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

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

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

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

0 commit comments

Comments
 (0)