Skip to content

Commit 1c62f83

Browse files
Fixed Rust model files not matching module imports causing compiler errors (#21134)
* fix(rust): Fixed Rust model files not matching module imports causing compiler errors * chore(rust): Update samples with a duplicate model test * update samples --------- Co-authored-by: Ross Sullivan <rosssullivan101@gmail.com>
1 parent 178f1c9 commit 1c62f83

72 files changed

Lines changed: 876 additions & 1 deletion

File tree

Some content is hidden

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,12 @@ public String modelFileFolder() {
538538
return (outputFolder + File.separator + modelFolder).replace("/", File.separator);
539539
}
540540

541+
@Override
542+
public String modelFilename(String templateName, String modelName) {
543+
String suffix = modelTemplateFiles().get(templateName);
544+
return modelFileFolder() + File.separator + toModelFilename(modelName) + suffix;
545+
}
546+
541547
@Override
542548
public String apiDocFileFolder() {
543549
return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);

modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,4 +1078,13 @@ components:
10781078
required:
10791079
- type
10801080
- speed
1081-
1081+
DuplicateTest:
1082+
type: object
1083+
properties:
1084+
name:
1085+
type: string
1086+
Duplicatetest: # explicitly testing the same name with different casing
1087+
type: object
1088+
properties:
1089+
name:
1090+
type: string

samples/client/petstore/rust/hyper/petstore/.openapi-generator/FILES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ docs/ApiResponse.md
88
docs/ArrayItemRefTest.md
99
docs/Baz.md
1010
docs/Category.md
11+
docs/DuplicateTest.md
12+
docs/Duplicatetest.md
1113
docs/EnumArrayTesting.md
1214
docs/FakeApi.md
1315
docs/NullableArray.md
@@ -47,6 +49,8 @@ src/models/api_response.rs
4749
src/models/array_item_ref_test.rs
4850
src/models/baz.rs
4951
src/models/category.rs
52+
src/models/duplicate_test.rs
53+
src/models/duplicatetest.rs
5054
src/models/enum_array_testing.rs
5155
src/models/mod.rs
5256
src/models/model_ref.rs

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Class | Method | HTTP request | Description
6161
- [ArrayItemRefTest](docs/ArrayItemRefTest.md)
6262
- [Baz](docs/Baz.md)
6363
- [Category](docs/Category.md)
64+
- [DuplicateTest](docs/DuplicateTest.md)
65+
- [Duplicatetest](docs/Duplicatetest.md)
6466
- [EnumArrayTesting](docs/EnumArrayTesting.md)
6567
- [NullableArray](docs/NullableArray.md)
6668
- [NumericEnumTesting](docs/NumericEnumTesting.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# DuplicateTest
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**name** | Option<**String**> | | [optional]
8+
9+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10+
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Duplicatetest
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**name** | Option<**String**> | | [optional]
8+
9+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10+
11+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* OpenAPI Petstore
3+
*
4+
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
5+
*
6+
* The version of the OpenAPI document: 1.0.0
7+
*
8+
* Generated by: https://openapi-generator.tech
9+
*/
10+
11+
use crate::models;
12+
use serde::{Deserialize, Serialize};
13+
14+
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15+
pub struct DuplicateTest {
16+
#[serde(rename = "name", skip_serializing_if = "Option::is_none")]
17+
pub name: Option<String>,
18+
}
19+
20+
impl DuplicateTest {
21+
pub fn new() -> DuplicateTest {
22+
DuplicateTest {
23+
name: None,
24+
}
25+
}
26+
}
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* OpenAPI Petstore
3+
*
4+
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
5+
*
6+
* The version of the OpenAPI document: 1.0.0
7+
*
8+
* Generated by: https://openapi-generator.tech
9+
*/
10+
11+
use crate::models;
12+
use serde::{Deserialize, Serialize};
13+
14+
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15+
pub struct Duplicatetest {
16+
#[serde(rename = "name", skip_serializing_if = "Option::is_none")]
17+
pub name: Option<String>,
18+
}
19+
20+
impl Duplicatetest {
21+
pub fn new() -> Duplicatetest {
22+
Duplicatetest {
23+
name: None,
24+
}
25+
}
26+
}
27+

samples/client/petstore/rust/hyper/petstore/src/models/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ pub mod baz;
1010
pub use self::baz::Baz;
1111
pub mod category;
1212
pub use self::category::Category;
13+
pub mod duplicate_test;
14+
pub use self::duplicate_test::DuplicateTest;
15+
pub mod duplicatetest;
16+
pub use self::duplicatetest::Duplicatetest;
1317
pub mod enum_array_testing;
1418
pub use self::enum_array_testing::EnumArrayTesting;
1519
pub mod nullable_array;

samples/client/petstore/rust/hyper0x/petstore/.openapi-generator/FILES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ docs/ApiResponse.md
88
docs/ArrayItemRefTest.md
99
docs/Baz.md
1010
docs/Category.md
11+
docs/DuplicateTest.md
12+
docs/Duplicatetest.md
1113
docs/EnumArrayTesting.md
1214
docs/FakeApi.md
1315
docs/NullableArray.md
@@ -45,6 +47,8 @@ src/models/api_response.rs
4547
src/models/array_item_ref_test.rs
4648
src/models/baz.rs
4749
src/models/category.rs
50+
src/models/duplicate_test.rs
51+
src/models/duplicatetest.rs
4852
src/models/enum_array_testing.rs
4953
src/models/mod.rs
5054
src/models/model_ref.rs

0 commit comments

Comments
 (0)