Skip to content

Commit 52610e0

Browse files
authored
[BugFix] [Rust*] model-name-prefix causing invalid generated code (#19922)
* [BugFix] [Rust*] model-name-prefix causing invalid generated code] * Update * Fix * Update * Update
1 parent 266193f commit 52610e0

Some content is hidden

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

64 files changed

+3374
-157
lines changed

bin/configs/manual/rust-axum-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ generateAliasAsModel: true
66
additionalProperties:
77
hideGenerationTimestamp: "true"
88
packageName: rust-server-test
9+
modelNamePrefix: "Foo"
910
globalProperties:
1011
skipFormModel: false
1112
enablePostProcessFile: true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
generatorName: rust
2+
outputDir: samples/client/petstore/rust/reqwest/petstore-model-name-prefix
3+
library: reqwest
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/rust
6+
additionalProperties:
7+
supportAsync: false
8+
packageName: petstore-reqwest-model-name-prefix
9+
modelNamePrefix: "Foo"
10+
enumNameMappings:
11+
delivered: shipped

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ public String getTypeDeclaration(Schema p) {
245245
} else if (!org.apache.commons.lang3.StringUtils.isEmpty(p.get$ref())) {
246246
String datatype;
247247
try {
248-
datatype = toModelName(ModelUtils.getSimpleRef(p.get$ref()));
249-
datatype = "models::" + toModelName(datatype);
248+
datatype = "models::" + toModelName(ModelUtils.getSimpleRef(p.get$ref()));
250249
} catch (Exception e) {
251250
LOGGER.warn("Error obtaining the datatype from schema (model):{}. Datatype default to Object", p);
252251
datatype = "Object";
@@ -438,6 +437,6 @@ public String escapeReservedWord(String name) {
438437
if (this.reservedWordsMappings().containsKey(name)) {
439438
return this.reservedWordsMappings().get(name);
440439
}
441-
return "r#"+ name;
440+
return "r#" + name;
442441
}
443442
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target/
2+
**/*.rs.bk
3+
Cargo.lock
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.gitignore
2+
.travis.yml
3+
Cargo.toml
4+
README.md
5+
docs/FakeApi.md
6+
docs/FooActionContainer.md
7+
docs/FooApiResponse.md
8+
docs/FooArrayItemRefTest.md
9+
docs/FooBaz.md
10+
docs/FooCategory.md
11+
docs/FooEnumArrayTesting.md
12+
docs/FooNullableArray.md
13+
docs/FooNumericEnumTesting.md
14+
docs/FooOptionalTesting.md
15+
docs/FooOrder.md
16+
docs/FooPet.md
17+
docs/FooPropertyTest.md
18+
docs/FooRef.md
19+
docs/FooReturn.md
20+
docs/FooTag.md
21+
docs/FooTypeTesting.md
22+
docs/FooUniqueItemArrayTesting.md
23+
docs/FooUser.md
24+
docs/PetApi.md
25+
docs/StoreApi.md
26+
docs/TestingApi.md
27+
docs/UserApi.md
28+
git_push.sh
29+
src/apis/configuration.rs
30+
src/apis/fake_api.rs
31+
src/apis/mod.rs
32+
src/apis/pet_api.rs
33+
src/apis/store_api.rs
34+
src/apis/testing_api.rs
35+
src/apis/user_api.rs
36+
src/lib.rs
37+
src/models/foo_action_container.rs
38+
src/models/foo_api_response.rs
39+
src/models/foo_array_item_ref_test.rs
40+
src/models/foo_baz.rs
41+
src/models/foo_category.rs
42+
src/models/foo_enum_array_testing.rs
43+
src/models/foo_nullable_array.rs
44+
src/models/foo_numeric_enum_testing.rs
45+
src/models/foo_optional_testing.rs
46+
src/models/foo_order.rs
47+
src/models/foo_pet.rs
48+
src/models/foo_property_test.rs
49+
src/models/foo_ref.rs
50+
src/models/foo_return.rs
51+
src/models/foo_tag.rs
52+
src/models/foo_type_testing.rs
53+
src/models/foo_unique_item_array_testing.rs
54+
src/models/foo_user.rs
55+
src/models/mod.rs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.10.0-SNAPSHOT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: rust
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "petstore-reqwest-model-name-prefix"
3+
version = "1.0.0"
4+
authors = ["OpenAPI Generator team and contributors"]
5+
description = "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters."
6+
license = "Apache-2.0"
7+
edition = "2021"
8+
9+
[dependencies]
10+
serde = { version = "^1.0", features = ["derive"] }
11+
serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] }
12+
serde_json = "^1.0"
13+
serde_repr = "^0.1"
14+
url = "^2.5"
15+
uuid = { version = "^1.8", features = ["serde", "v4"] }
16+
reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] }
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Rust API client for petstore-reqwest-model-name-prefix
2+
3+
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
4+
5+
6+
## Overview
7+
8+
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.
9+
10+
- API version: 1.0.0
11+
- Package version: 1.0.0
12+
- Generator version: 7.10.0-SNAPSHOT
13+
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`
14+
15+
## Installation
16+
17+
Put the package under your project folder in a directory named `petstore-reqwest-model-name-prefix` and add the following to `Cargo.toml` under `[dependencies]`:
18+
19+
```
20+
petstore-reqwest-model-name-prefix = { path = "./petstore-reqwest-model-name-prefix" }
21+
```
22+
23+
## Documentation for API Endpoints
24+
25+
All URIs are relative to *http://petstore.swagger.io/v2*
26+
27+
Class | Method | HTTP request | Description
28+
------------ | ------------- | ------------- | -------------
29+
*FakeApi* | [**test_nullable_required_param**](docs/FakeApi.md#test_nullable_required_param) | **GET** /fake/user/{username} | To test nullable required parameters
30+
*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
31+
*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet
32+
*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status
33+
*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **GET** /pet/findByTags | Finds Pets by tags
34+
*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **GET** /pet/{petId} | Find pet by ID
35+
*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **PUT** /pet | Update an existing pet
36+
*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data
37+
*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image
38+
*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
39+
*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **GET** /store/inventory | Returns pet inventories by status
40+
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **GET** /store/order/{orderId} | Find purchase order by ID
41+
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **POST** /store/order | Place an order for a pet
42+
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file
43+
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema
44+
*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **POST** /user | Create user
45+
*UserApi* | [**create_users_with_array_input**](docs/UserApi.md#create_users_with_array_input) | **POST** /user/createWithArray | Creates list of users with given input array
46+
*UserApi* | [**create_users_with_list_input**](docs/UserApi.md#create_users_with_list_input) | **POST** /user/createWithList | Creates list of users with given input array
47+
*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **DELETE** /user/{username} | Delete user
48+
*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **GET** /user/{username} | Get user by user name
49+
*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **GET** /user/login | Logs user into the system
50+
*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **GET** /user/logout | Logs out current logged in user session
51+
*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **PUT** /user/{username} | Updated user
52+
53+
54+
## Documentation For Models
55+
56+
- [FooActionContainer](docs/FooActionContainer.md)
57+
- [FooApiResponse](docs/FooApiResponse.md)
58+
- [FooArrayItemRefTest](docs/FooArrayItemRefTest.md)
59+
- [FooBaz](docs/FooBaz.md)
60+
- [FooCategory](docs/FooCategory.md)
61+
- [FooEnumArrayTesting](docs/FooEnumArrayTesting.md)
62+
- [FooNullableArray](docs/FooNullableArray.md)
63+
- [FooNumericEnumTesting](docs/FooNumericEnumTesting.md)
64+
- [FooOptionalTesting](docs/FooOptionalTesting.md)
65+
- [FooOrder](docs/FooOrder.md)
66+
- [FooPet](docs/FooPet.md)
67+
- [FooPropertyTest](docs/FooPropertyTest.md)
68+
- [FooRef](docs/FooRef.md)
69+
- [FooReturn](docs/FooReturn.md)
70+
- [FooTag](docs/FooTag.md)
71+
- [FooTypeTesting](docs/FooTypeTesting.md)
72+
- [FooUniqueItemArrayTesting](docs/FooUniqueItemArrayTesting.md)
73+
- [FooUser](docs/FooUser.md)
74+
75+
76+
To get access to the crate's generated documentation, use:
77+
78+
```
79+
cargo doc --open
80+
```
81+
82+
## Author
83+
84+
85+

0 commit comments

Comments
 (0)