Override escape reserved word in abstract rust (#17440)

* override escape reserved word in abstract rust

* add tests for ref, improve verion lambda

* add files
This commit is contained in:
William Cheng 2024-03-19 18:33:29 +08:00 committed by GitHub
parent b7ea139f77
commit 191dc1a6ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 285 additions and 0 deletions

View File

@ -436,4 +436,12 @@ public abstract class AbstractRustCodegen extends DefaultCodegen implements Code
public String addRegularExpressionDelimiter(String pattern) { public String addRegularExpressionDelimiter(String pattern) {
return pattern; return pattern;
} }
@Override
public String escapeReservedWord(String name) {
if (this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return "r#"+ name;
}
} }

View File

@ -392,6 +392,13 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
// remove v or V // remove v or V
content = content.trim().replace("v", ""); content = content.trim().replace("v", "");
content = content.replace("V", ""); content = content.replace("V", "");
// convert 5.2 to 5.2.0 for example
String[] contents = content.split("[.]");
if (contents.length == 2) {
content += ".0";
}
writer.write(content); writer.write(content);
} }
}); });

View File

@ -955,3 +955,9 @@ components:
nullable: true nullable: true
just_string: just_string:
type: string type: string
ref:
description: using reserved word as model name
type: object
properties:
dummy:
type: string

View File

@ -15,6 +15,7 @@ docs/Order.md
docs/Pet.md docs/Pet.md
docs/PetApi.md docs/PetApi.md
docs/PropertyTest.md docs/PropertyTest.md
docs/Ref.md
docs/Return.md docs/Return.md
docs/StoreApi.md docs/StoreApi.md
docs/Tag.md docs/Tag.md
@ -41,6 +42,7 @@ src/models/baz.rs
src/models/category.rs src/models/category.rs
src/models/enum_array_testing.rs src/models/enum_array_testing.rs
src/models/mod.rs src/models/mod.rs
src/models/model_ref.rs
src/models/model_return.rs src/models/model_return.rs
src/models/nullable_array.rs src/models/nullable_array.rs
src/models/optional_testing.rs src/models/optional_testing.rs

View File

@ -64,6 +64,7 @@ Class | Method | HTTP request | Description
- [Order](docs/Order.md) - [Order](docs/Order.md)
- [Pet](docs/Pet.md) - [Pet](docs/Pet.md)
- [PropertyTest](docs/PropertyTest.md) - [PropertyTest](docs/PropertyTest.md)
- [Ref](docs/Ref.md)
- [Return](docs/Return.md) - [Return](docs/Return.md)
- [Tag](docs/Tag.md) - [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md) - [TypeTesting](docs/TypeTesting.md)

View File

@ -0,0 +1,11 @@
# Ref
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**dummy** | Option<**String**> | | [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)

View File

@ -20,6 +20,8 @@ pub mod pet;
pub use self::pet::Pet; pub use self::pet::Pet;
pub mod property_test; pub mod property_test;
pub use self::property_test::PropertyTest; pub use self::property_test::PropertyTest;
pub mod model_ref;
pub use self::model_ref::Ref;
pub mod model_return; pub mod model_return;
pub use self::model_return::Return; pub use self::model_return::Return;
pub mod tag; pub mod tag;

View File

@ -0,0 +1,28 @@
/*
* 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;
/// Ref : using reserved word as model name
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Ref {
#[serde(rename = "dummy", skip_serializing_if = "Option::is_none")]
pub dummy: Option<String>,
}
impl Ref {
/// using reserved word as model name
pub fn new() -> Ref {
Ref {
dummy: None,
}
}
}

View File

@ -15,6 +15,7 @@ docs/Order.md
docs/Pet.md docs/Pet.md
docs/PetApi.md docs/PetApi.md
docs/PropertyTest.md docs/PropertyTest.md
docs/Ref.md
docs/Return.md docs/Return.md
docs/StoreApi.md docs/StoreApi.md
docs/Tag.md docs/Tag.md
@ -39,6 +40,7 @@ src/models/baz.rs
src/models/category.rs src/models/category.rs
src/models/enum_array_testing.rs src/models/enum_array_testing.rs
src/models/mod.rs src/models/mod.rs
src/models/model_ref.rs
src/models/model_return.rs src/models/model_return.rs
src/models/nullable_array.rs src/models/nullable_array.rs
src/models/optional_testing.rs src/models/optional_testing.rs

View File

@ -64,6 +64,7 @@ Class | Method | HTTP request | Description
- [Order](docs/Order.md) - [Order](docs/Order.md)
- [Pet](docs/Pet.md) - [Pet](docs/Pet.md)
- [PropertyTest](docs/PropertyTest.md) - [PropertyTest](docs/PropertyTest.md)
- [Ref](docs/Ref.md)
- [Return](docs/Return.md) - [Return](docs/Return.md)
- [Tag](docs/Tag.md) - [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md) - [TypeTesting](docs/TypeTesting.md)

View File

@ -0,0 +1,11 @@
# Ref
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**dummy** | Option<**String**> | | [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)

View File

@ -20,6 +20,8 @@ pub mod pet;
pub use self::pet::Pet; pub use self::pet::Pet;
pub mod property_test; pub mod property_test;
pub use self::property_test::PropertyTest; pub use self::property_test::PropertyTest;
pub mod model_ref;
pub use self::model_ref::Ref;
pub mod model_return; pub mod model_return;
pub use self::model_return::Return; pub use self::model_return::Return;
pub mod tag; pub mod tag;

View File

@ -0,0 +1,28 @@
/*
* 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;
/// Ref : using reserved word as model name
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Ref {
#[serde(rename = "dummy", skip_serializing_if = "Option::is_none")]
pub dummy: Option<String>,
}
impl Ref {
/// using reserved word as model name
pub fn new() -> Ref {
Ref {
dummy: None,
}
}
}

View File

@ -15,6 +15,7 @@ docs/Order.md
docs/Pet.md docs/Pet.md
docs/PetApi.md docs/PetApi.md
docs/PropertyTest.md docs/PropertyTest.md
docs/Ref.md
docs/Return.md docs/Return.md
docs/StoreApi.md docs/StoreApi.md
docs/Tag.md docs/Tag.md
@ -39,6 +40,7 @@ src/models/baz.rs
src/models/category.rs src/models/category.rs
src/models/enum_array_testing.rs src/models/enum_array_testing.rs
src/models/mod.rs src/models/mod.rs
src/models/model_ref.rs
src/models/model_return.rs src/models/model_return.rs
src/models/nullable_array.rs src/models/nullable_array.rs
src/models/optional_testing.rs src/models/optional_testing.rs

View File

@ -64,6 +64,7 @@ Class | Method | HTTP request | Description
- [Order](docs/Order.md) - [Order](docs/Order.md)
- [Pet](docs/Pet.md) - [Pet](docs/Pet.md)
- [PropertyTest](docs/PropertyTest.md) - [PropertyTest](docs/PropertyTest.md)
- [Ref](docs/Ref.md)
- [Return](docs/Return.md) - [Return](docs/Return.md)
- [Tag](docs/Tag.md) - [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md) - [TypeTesting](docs/TypeTesting.md)

View File

@ -0,0 +1,11 @@
# Ref
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**dummy** | Option<**String**> | | [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)

View File

@ -20,6 +20,8 @@ pub mod pet;
pub use self::pet::Pet; pub use self::pet::Pet;
pub mod property_test; pub mod property_test;
pub use self::property_test::PropertyTest; pub use self::property_test::PropertyTest;
pub mod model_ref;
pub use self::model_ref::Ref;
pub mod model_return; pub mod model_return;
pub use self::model_return::Return; pub use self::model_return::Return;
pub mod tag; pub mod tag;

View File

@ -0,0 +1,28 @@
/*
* 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;
/// Ref : using reserved word as model name
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Ref {
#[serde(rename = "dummy", skip_serializing_if = "Option::is_none")]
pub dummy: Option<String>,
}
impl Ref {
/// using reserved word as model name
pub fn new() -> Ref {
Ref {
dummy: None,
}
}
}

View File

@ -15,6 +15,7 @@ docs/Order.md
docs/Pet.md docs/Pet.md
docs/PetApi.md docs/PetApi.md
docs/PropertyTest.md docs/PropertyTest.md
docs/Ref.md
docs/Return.md docs/Return.md
docs/StoreApi.md docs/StoreApi.md
docs/Tag.md docs/Tag.md
@ -39,6 +40,7 @@ src/models/baz.rs
src/models/category.rs src/models/category.rs
src/models/enum_array_testing.rs src/models/enum_array_testing.rs
src/models/mod.rs src/models/mod.rs
src/models/model_ref.rs
src/models/model_return.rs src/models/model_return.rs
src/models/nullable_array.rs src/models/nullable_array.rs
src/models/optional_testing.rs src/models/optional_testing.rs

View File

@ -64,6 +64,7 @@ Class | Method | HTTP request | Description
- [Order](docs/Order.md) - [Order](docs/Order.md)
- [Pet](docs/Pet.md) - [Pet](docs/Pet.md)
- [PropertyTest](docs/PropertyTest.md) - [PropertyTest](docs/PropertyTest.md)
- [Ref](docs/Ref.md)
- [Return](docs/Return.md) - [Return](docs/Return.md)
- [Tag](docs/Tag.md) - [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md) - [TypeTesting](docs/TypeTesting.md)

View File

@ -0,0 +1,11 @@
# Ref
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**dummy** | Option<**String**> | | [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)

View File

@ -20,6 +20,8 @@ pub mod pet;
pub use self::pet::Pet; pub use self::pet::Pet;
pub mod property_test; pub mod property_test;
pub use self::property_test::PropertyTest; pub use self::property_test::PropertyTest;
pub mod model_ref;
pub use self::model_ref::Ref;
pub mod model_return; pub mod model_return;
pub use self::model_return::Return; pub use self::model_return::Return;
pub mod tag; pub mod tag;

View File

@ -0,0 +1,28 @@
/*
* 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;
/// Ref : using reserved word as model name
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Ref {
#[serde(rename = "dummy", skip_serializing_if = "Option::is_none")]
pub dummy: Option<String>,
}
impl Ref {
/// using reserved word as model name
pub fn new() -> Ref {
Ref {
dummy: None,
}
}
}

View File

@ -15,6 +15,7 @@ docs/Order.md
docs/Pet.md docs/Pet.md
docs/PetApi.md docs/PetApi.md
docs/PropertyTest.md docs/PropertyTest.md
docs/Ref.md
docs/Return.md docs/Return.md
docs/StoreApi.md docs/StoreApi.md
docs/Tag.md docs/Tag.md
@ -39,6 +40,7 @@ src/models/baz.rs
src/models/category.rs src/models/category.rs
src/models/enum_array_testing.rs src/models/enum_array_testing.rs
src/models/mod.rs src/models/mod.rs
src/models/model_ref.rs
src/models/model_return.rs src/models/model_return.rs
src/models/nullable_array.rs src/models/nullable_array.rs
src/models/optional_testing.rs src/models/optional_testing.rs

View File

@ -64,6 +64,7 @@ Class | Method | HTTP request | Description
- [Order](docs/Order.md) - [Order](docs/Order.md)
- [Pet](docs/Pet.md) - [Pet](docs/Pet.md)
- [PropertyTest](docs/PropertyTest.md) - [PropertyTest](docs/PropertyTest.md)
- [Ref](docs/Ref.md)
- [Return](docs/Return.md) - [Return](docs/Return.md)
- [Tag](docs/Tag.md) - [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md) - [TypeTesting](docs/TypeTesting.md)

View File

@ -0,0 +1,11 @@
# Ref
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**dummy** | Option<**String**> | | [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)

View File

@ -20,6 +20,8 @@ pub mod pet;
pub use self::pet::Pet; pub use self::pet::Pet;
pub mod property_test; pub mod property_test;
pub use self::property_test::PropertyTest; pub use self::property_test::PropertyTest;
pub mod model_ref;
pub use self::model_ref::Ref;
pub mod model_return; pub mod model_return;
pub use self::model_return::Return; pub use self::model_return::Return;
pub mod tag; pub mod tag;

View File

@ -0,0 +1,28 @@
/*
* 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;
/// Ref : using reserved word as model name
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Ref {
#[serde(rename = "dummy", skip_serializing_if = "Option::is_none")]
pub dummy: Option<String>,
}
impl Ref {
/// using reserved word as model name
pub fn new() -> Ref {
Ref {
dummy: None,
}
}
}

View File

@ -15,6 +15,7 @@ docs/Order.md
docs/Pet.md docs/Pet.md
docs/PetApi.md docs/PetApi.md
docs/PropertyTest.md docs/PropertyTest.md
docs/Ref.md
docs/Return.md docs/Return.md
docs/StoreApi.md docs/StoreApi.md
docs/Tag.md docs/Tag.md
@ -39,6 +40,7 @@ src/models/baz.rs
src/models/category.rs src/models/category.rs
src/models/enum_array_testing.rs src/models/enum_array_testing.rs
src/models/mod.rs src/models/mod.rs
src/models/model_ref.rs
src/models/model_return.rs src/models/model_return.rs
src/models/nullable_array.rs src/models/nullable_array.rs
src/models/optional_testing.rs src/models/optional_testing.rs

View File

@ -64,6 +64,7 @@ Class | Method | HTTP request | Description
- [Order](docs/Order.md) - [Order](docs/Order.md)
- [Pet](docs/Pet.md) - [Pet](docs/Pet.md)
- [PropertyTest](docs/PropertyTest.md) - [PropertyTest](docs/PropertyTest.md)
- [Ref](docs/Ref.md)
- [Return](docs/Return.md) - [Return](docs/Return.md)
- [Tag](docs/Tag.md) - [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md) - [TypeTesting](docs/TypeTesting.md)

View File

@ -0,0 +1,11 @@
# Ref
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**dummy** | Option<**String**> | | [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)

View File

@ -20,6 +20,8 @@ pub mod pet;
pub use self::pet::Pet; pub use self::pet::Pet;
pub mod property_test; pub mod property_test;
pub use self::property_test::PropertyTest; pub use self::property_test::PropertyTest;
pub mod model_ref;
pub use self::model_ref::Ref;
pub mod model_return; pub mod model_return;
pub use self::model_return::Return; pub use self::model_return::Return;
pub mod tag; pub mod tag;

View File

@ -0,0 +1,28 @@
/*
* 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;
/// Ref : using reserved word as model name
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Ref {
#[serde(rename = "dummy", skip_serializing_if = "Option::is_none")]
pub dummy: Option<String>,
}
impl Ref {
/// using reserved word as model name
pub fn new() -> Ref {
Ref {
dummy: None,
}
}
}