Skip to content

Commit 0dbfdbb

Browse files
committed
add model name mapping option to rust generators
1 parent 4089438 commit 0dbfdbb

File tree

234 files changed

+1445
-4129
lines changed

Some content is hidden

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

234 files changed

+1445
-4129
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: petstore-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: petstore-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
Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +0,0 @@
1-
/*
2-
* OpenAPI Petstore
3-
*
4-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5-
*
6-
* The version of the OpenAPI document: 1.0.0
7-
* Generated by: https://github.com/openapitools/openapi-generator.git
8-
*/
9-
10-
11-
using System;
12-
using System.Collections;
13-
using System.Collections.Generic;
14-
using System.Collections.ObjectModel;
15-
using System.Linq;
16-
using System.IO;
17-
using System.Runtime.Serialization;
18-
using System.Text;
19-
using System.Text.RegularExpressions;
20-
using Newtonsoft.Json;
21-
using Newtonsoft.Json.Converters;
22-
using Newtonsoft.Json.Linq;
23-
using System.ComponentModel.DataAnnotations;
24-
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
25-
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
26-
27-
namespace Org.OpenAPITools.Model
28-
{
29-
/// <summary>
30-
/// SpecialModelName
31-
/// </summary>
32-
[DataContract(Name = "_special_model.name_")]
33-
public partial class SpecialModelName : IEquatable<SpecialModelName>, IValidatableObject
34-
{
35-
/// <summary>
36-
/// Initializes a new instance of the <see cref="SpecialModelName" /> class.
37-
/// </summary>
38-
/// <param name="specialPropertyName">specialPropertyName.</param>
39-
/// <param name="varSpecialModelName">varSpecialModelName.</param>
40-
public SpecialModelName(long specialPropertyName = default, string varSpecialModelName = default)
41-
{
42-
this.SpecialPropertyName = specialPropertyName;
43-
this.VarSpecialModelName = varSpecialModelName;
44-
this.AdditionalProperties = new Dictionary<string, object>();
45-
}
46-
47-
/// <summary>
48-
/// Gets or Sets SpecialPropertyName
49-
/// </summary>
50-
[DataMember(Name = "$special[property.name]", EmitDefaultValue = false)]
51-
public long SpecialPropertyName { get; set; }
52-
53-
/// <summary>
54-
/// Gets or Sets VarSpecialModelName
55-
/// </summary>
56-
[DataMember(Name = "_special_model.name_", EmitDefaultValue = false)]
57-
public string VarSpecialModelName { get; set; }
58-
59-
/// <summary>
60-
/// Gets or Sets additional properties
61-
/// </summary>
62-
[JsonExtensionData]
63-
public IDictionary<string, object> AdditionalProperties { get; set; }
64-
65-
/// <summary>
66-
/// Returns the string presentation of the object
67-
/// </summary>
68-
/// <returns>String presentation of the object</returns>
69-
public override string ToString()
70-
{
71-
StringBuilder sb = new StringBuilder();
72-
sb.Append("class SpecialModelName {\n");
73-
sb.Append(" SpecialPropertyName: ").Append(SpecialPropertyName).Append("\n");
74-
sb.Append(" VarSpecialModelName: ").Append(VarSpecialModelName).Append("\n");
75-
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
76-
sb.Append("}\n");
77-
return sb.ToString();
78-
}
79-
80-
/// <summary>
81-
/// Returns the JSON string presentation of the object
82-
/// </summary>
83-
/// <returns>JSON string presentation of the object</returns>
84-
public virtual string ToJson()
85-
{
86-
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
87-
}
88-
89-
/// <summary>
90-
/// Returns true if objects are equal
91-
/// </summary>
92-
/// <param name="input">Object to be compared</param>
93-
/// <returns>Boolean</returns>
94-
public override bool Equals(object input)
95-
{
96-
return OpenAPIClientUtils.compareLogic.Compare(this, input as SpecialModelName).AreEqual;
97-
}
98-
99-
/// <summary>
100-
/// Returns true if SpecialModelName instances are equal
101-
/// </summary>
102-
/// <param name="input">Instance of SpecialModelName to be compared</param>
103-
/// <returns>Boolean</returns>
104-
public bool Equals(SpecialModelName input)
105-
{
106-
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
107-
}
108-
109-
/// <summary>
110-
/// Gets the hash code
111-
/// </summary>
112-
/// <returns>Hash code</returns>
113-
public override int GetHashCode()
114-
{
115-
unchecked // Overflow is fine, just wrap
116-
{
117-
int hashCode = 41;
118-
hashCode = (hashCode * 59) + this.SpecialPropertyName.GetHashCode();
119-
if (this.VarSpecialModelName != null)
120-
{
121-
hashCode = (hashCode * 59) + this.VarSpecialModelName.GetHashCode();
122-
}
123-
if (this.AdditionalProperties != null)
124-
{
125-
hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode();
126-
}
127-
return hashCode;
128-
}
129-
}
130-
131-
/// <summary>
132-
/// To validate all properties of the instance
133-
/// </summary>
134-
/// <param name="validationContext">Validation context</param>
135-
/// <returns>Validation Result</returns>
136-
IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
137-
{
138-
yield break;
139-
}
140-
}
141-
142-
}

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)

0 commit comments

Comments
 (0)