Skip to content

Commit

Permalink
[BugFix] [Rust*] model-name-prefix causing invalid generated code (Op…
Browse files Browse the repository at this point in the history
…enAPITools#19922)

* [BugFix] [Rust*] model-name-prefix causing invalid generated code]

* Update

* Fix

* Update

* Update
  • Loading branch information
linxGnu authored Oct 21, 2024
1 parent 266193f commit 52610e0
Show file tree
Hide file tree
Showing 64 changed files with 3,374 additions and 157 deletions.
1 change: 1 addition & 0 deletions bin/configs/manual/rust-axum-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ generateAliasAsModel: true
additionalProperties:
hideGenerationTimestamp: "true"
packageName: rust-server-test
modelNamePrefix: "Foo"
globalProperties:
skipFormModel: false
enablePostProcessFile: true
11 changes: 11 additions & 0 deletions bin/configs/rust-reqwest-petstore-model-name-prefix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: rust
outputDir: samples/client/petstore/rust/reqwest/petstore-model-name-prefix
library: reqwest
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/rust
additionalProperties:
supportAsync: false
packageName: petstore-reqwest-model-name-prefix
modelNamePrefix: "Foo"
enumNameMappings:
delivered: shipped
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ public String getTypeDeclaration(Schema p) {
} else if (!org.apache.commons.lang3.StringUtils.isEmpty(p.get$ref())) {
String datatype;
try {
datatype = toModelName(ModelUtils.getSimpleRef(p.get$ref()));
datatype = "models::" + toModelName(datatype);
datatype = "models::" + toModelName(ModelUtils.getSimpleRef(p.get$ref()));
} catch (Exception e) {
LOGGER.warn("Error obtaining the datatype from schema (model):{}. Datatype default to Object", p);
datatype = "Object";
Expand Down Expand Up @@ -438,6 +437,6 @@ public String escapeReservedWord(String name) {
if (this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return "r#"+ name;
return "r#" + name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target/
**/*.rs.bk
Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.gitignore
.travis.yml
Cargo.toml
README.md
docs/FakeApi.md
docs/FooActionContainer.md
docs/FooApiResponse.md
docs/FooArrayItemRefTest.md
docs/FooBaz.md
docs/FooCategory.md
docs/FooEnumArrayTesting.md
docs/FooNullableArray.md
docs/FooNumericEnumTesting.md
docs/FooOptionalTesting.md
docs/FooOrder.md
docs/FooPet.md
docs/FooPropertyTest.md
docs/FooRef.md
docs/FooReturn.md
docs/FooTag.md
docs/FooTypeTesting.md
docs/FooUniqueItemArrayTesting.md
docs/FooUser.md
docs/PetApi.md
docs/StoreApi.md
docs/TestingApi.md
docs/UserApi.md
git_push.sh
src/apis/configuration.rs
src/apis/fake_api.rs
src/apis/mod.rs
src/apis/pet_api.rs
src/apis/store_api.rs
src/apis/testing_api.rs
src/apis/user_api.rs
src/lib.rs
src/models/foo_action_container.rs
src/models/foo_api_response.rs
src/models/foo_array_item_ref_test.rs
src/models/foo_baz.rs
src/models/foo_category.rs
src/models/foo_enum_array_testing.rs
src/models/foo_nullable_array.rs
src/models/foo_numeric_enum_testing.rs
src/models/foo_optional_testing.rs
src/models/foo_order.rs
src/models/foo_pet.rs
src/models/foo_property_test.rs
src/models/foo_ref.rs
src/models/foo_return.rs
src/models/foo_tag.rs
src/models/foo_type_testing.rs
src/models/foo_unique_item_array_testing.rs
src/models/foo_user.rs
src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.10.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: rust
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "petstore-reqwest-model-name-prefix"
version = "1.0.0"
authors = ["OpenAPI Generator team and contributors"]
description = "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters."
license = "Apache-2.0"
edition = "2021"

[dependencies]
serde = { version = "^1.0", features = ["derive"] }
serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] }
serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.5"
uuid = { version = "^1.8", features = ["serde", "v4"] }
reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] }
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Rust API client for petstore-reqwest-model-name-prefix

This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.


## Overview

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.

- API version: 1.0.0
- Package version: 1.0.0
- Generator version: 7.10.0-SNAPSHOT
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`

## Installation

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]`:

```
petstore-reqwest-model-name-prefix = { path = "./petstore-reqwest-model-name-prefix" }
```

## Documentation for API Endpoints

All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FakeApi* | [**test_nullable_required_param**](docs/FakeApi.md#test_nullable_required_param) | **GET** /fake/user/{username} | To test nullable required parameters
*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status
*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **GET** /pet/{petId} | Find pet by ID
*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **PUT** /pet | Update an existing pet
*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image
*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **GET** /store/order/{orderId} | Find purchase order by ID
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **POST** /store/order | Place an order for a pet
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema
*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **POST** /user | Create user
*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
*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
*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **DELETE** /user/{username} | Delete user
*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **GET** /user/{username} | Get user by user name
*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **GET** /user/login | Logs user into the system
*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **GET** /user/logout | Logs out current logged in user session
*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **PUT** /user/{username} | Updated user


## Documentation For Models

- [FooActionContainer](docs/FooActionContainer.md)
- [FooApiResponse](docs/FooApiResponse.md)
- [FooArrayItemRefTest](docs/FooArrayItemRefTest.md)
- [FooBaz](docs/FooBaz.md)
- [FooCategory](docs/FooCategory.md)
- [FooEnumArrayTesting](docs/FooEnumArrayTesting.md)
- [FooNullableArray](docs/FooNullableArray.md)
- [FooNumericEnumTesting](docs/FooNumericEnumTesting.md)
- [FooOptionalTesting](docs/FooOptionalTesting.md)
- [FooOrder](docs/FooOrder.md)
- [FooPet](docs/FooPet.md)
- [FooPropertyTest](docs/FooPropertyTest.md)
- [FooRef](docs/FooRef.md)
- [FooReturn](docs/FooReturn.md)
- [FooTag](docs/FooTag.md)
- [FooTypeTesting](docs/FooTypeTesting.md)
- [FooUniqueItemArrayTesting](docs/FooUniqueItemArrayTesting.md)
- [FooUser](docs/FooUser.md)


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

```
cargo doc --open
```

## Author



Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# \FakeApi

All URIs are relative to *http://petstore.swagger.io/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**test_nullable_required_param**](FakeApi.md#test_nullable_required_param) | **GET** /fake/user/{username} | To test nullable required parameters



## test_nullable_required_param

> test_nullable_required_param(username, dummy_required_nullable_param, uppercase)
To test nullable required parameters



### Parameters


Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**username** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] |
**dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] |
**uppercase** | Option<**String**> | To test parameter names in upper case | |

### Return type

(empty response body)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: Not defined

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# FooActionContainer

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**action** | [**models::FooBaz**](Baz.md) | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# FooApiResponse

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**code** | Option<**i32**> | | [optional]
**r#type** | Option<**String**> | | [optional]
**message** | 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)


Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# FooArrayItemRefTest

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**list_with_array_ref** | [**Vec<Vec<String>>**](Vec.md) | |
**list_with_object_ref** | [**Vec<std::collections::HashMap<String, serde_json::Value>>**](std::collections::HashMap.md) | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# FooBaz

## Enum Variants

| Name | Value |
|---- | -----|
| A | A |
| B | B |
| Empty | |


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# FooCategory

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | Option<**i64**> | | [optional]
**name** | 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)


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# FooEnumArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**required_enums** | **Vec<String>** | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# FooNullableArray

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**array_nullable** | Option<**Vec<String>**> | | [optional]
**just_array** | Option<**Vec<String>**> | | [optional]
**nullable_string** | Option<**String**> | | [optional]
**just_string** | 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)


Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# FooNumericEnumTesting

## Enum Variants

| Name | Value |
|---- | -----|
| Variant0 | 0 |
| Variant1 | 1 |
| Variant2 | 2 |
| Variant3 | 3 |


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# FooOptionalTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**optional_nonnull** | Option<**String**> | | [optional]
**required_nonnull** | **String** | |
**optional_nullable** | Option<**String**> | | [optional]
**required_nullable** | Option<**String**> | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Loading

0 comments on commit 52610e0

Please sign in to comment.