Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rust] Fixed Rust default isAnyType causing compiler issues. #20631

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,18 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
List<CodegenOperation> operations = objectMap.getOperation();
for (CodegenOperation operation : operations) {
if (operation.pathParams != null && operation.pathParams.size() > 0) {

// For types with `isAnyType` we assume it's a `serde_json::Value` type.
// However for path, query, and headers it's unlikely to be JSON so we default to `String`.
// Note that we keep the default `serde_json::Value` for body parameters.
for (var param : operation.allParams) {
if (param.isAnyType && (param.isPathParam || param.isQueryParam || param.isHeaderParam)) {
param.dataType = "String";
param.isPrimitiveType = true;
param.isString = true;
}
}

for (var pathParam : operation.pathParams) {
if (!pathParam.baseName.contains("-")) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ paths:
description: To test escaping of parameters in rust code works
schema:
type: string
# For testing `isAnyType` types
- name: anyType
in: query
required: true
schema: {}
responses:
'200':
description: successful operation
Expand Down Expand Up @@ -996,3 +1001,9 @@ components:
properties:
dummy:
type: string
AnyTypeTest:
type: object
properties:
foo: {}
required: ["foo"]

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Cargo.toml
README.md
docs/ActionContainer.md
docs/AnyTypeTest.md
docs/ApiResponse.md
docs/ArrayItemRefTest.md
docs/Baz.md
Expand Down Expand Up @@ -37,6 +38,7 @@ src/apis/testing_api.rs
src/apis/user_api.rs
src/lib.rs
src/models/action_container.rs
src/models/any_type_test.rs
src/models/api_response.rs
src/models/array_item_ref_test.rs
src/models/baz.rs
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/rust/hyper/petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Class | Method | HTTP request | Description
## Documentation For Models

- [ActionContainer](docs/ActionContainer.md)
- [AnyTypeTest](docs/AnyTypeTest.md)
- [ApiResponse](docs/ApiResponse.md)
- [ArrayItemRefTest](docs/ArrayItemRefTest.md)
- [Baz](docs/Baz.md)
Expand Down
11 changes: 11 additions & 0 deletions samples/client/petstore/rust/hyper/petstore/docs/AnyTypeTest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AnyTypeTest

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**foo** | Option<[**serde_json::Value**](.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)


3 changes: 2 additions & 1 deletion samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Method | HTTP request | Description

## test_nullable_required_param

> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content)
> test_nullable_required_param(user_name, dummy_required_nullable_param, any_type, uppercase, content)
To test nullable required parameters


Expand All @@ -22,6 +22,7 @@ Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**user_name** | **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] |
**any_type** | **String** | | [required] |
**uppercase** | Option<**String**> | To test parameter names in upper case | |
**content** | Option<**String**> | To test escaping of parameters in rust code works | |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ impl<C: Connect> FakeApiClient<C>
}

pub trait FakeApi: Send + Sync {
fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, any_type: &str, uppercase: Option<&str>, content: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
}

impl<C: Connect>FakeApi for FakeApiClient<C>
where C: Clone + std::marker::Send + Sync {
#[allow(unused_mut)]
fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> {
fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, any_type: &str, uppercase: Option<&str>, content: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> {
let mut req = __internal_request::Request::new(hyper::Method::GET, "/fake/user/{user_name}".to_string())
;
if let Some(ref s) = content {
let query_value = s.to_string();
req = req.with_query_param("content".to_string(), query_value);
}
req = req.with_query_param("anyType".to_string(), any_type.to_string());
req = req.with_path_param("user_name".to_string(), user_name.to_string());
match dummy_required_nullable_param {
Some(param_value) => { req = req.with_header_param("dummy_required_nullable_param".to_string(), param_value.to_string()); },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct AnyTypeTest {
#[serde(rename = "foo", deserialize_with = "Option::deserialize")]
pub foo: Option<serde_json::Value>,
}

impl AnyTypeTest {
pub fn new(foo: Option<serde_json::Value>) -> AnyTypeTest {
AnyTypeTest {
foo,
}
}
}

2 changes: 2 additions & 0 deletions samples/client/petstore/rust/hyper/petstore/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod action_container;
pub use self::action_container::ActionContainer;
pub mod any_type_test;
pub use self::any_type_test::AnyTypeTest;
pub mod api_response;
pub use self::api_response::ApiResponse;
pub mod array_item_ref_test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod tests {
let handle = thread::spawn(move || {
let _ = client
.fake_api()
.test_nullable_required_param("username", None, None, None);
.test_nullable_required_param("username", None, "any_type", None, None);
});

handle.join().expect("Thread panicked!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Cargo.toml
README.md
docs/ActionContainer.md
docs/AnyTypeTest.md
docs/ApiResponse.md
docs/ArrayItemRefTest.md
docs/Baz.md
Expand Down Expand Up @@ -35,6 +36,7 @@ src/apis/testing_api.rs
src/apis/user_api.rs
src/lib.rs
src/models/action_container.rs
src/models/any_type_test.rs
src/models/api_response.rs
src/models/array_item_ref_test.rs
src/models/baz.rs
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/rust/hyper0x/petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Class | Method | HTTP request | Description
## Documentation For Models

- [ActionContainer](docs/ActionContainer.md)
- [AnyTypeTest](docs/AnyTypeTest.md)
- [ApiResponse](docs/ApiResponse.md)
- [ArrayItemRefTest](docs/ArrayItemRefTest.md)
- [Baz](docs/Baz.md)
Expand Down
11 changes: 11 additions & 0 deletions samples/client/petstore/rust/hyper0x/petstore/docs/AnyTypeTest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AnyTypeTest

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**foo** | Option<[**serde_json::Value**](.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
Expand Up @@ -10,7 +10,7 @@ Method | HTTP request | Description

## test_nullable_required_param

> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content)
> test_nullable_required_param(user_name, dummy_required_nullable_param, any_type, uppercase, content)
To test nullable required parameters


Expand All @@ -22,6 +22,7 @@ Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**user_name** | **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] |
**any_type** | **String** | | [required] |
**uppercase** | Option<**String**> | To test parameter names in upper case | |
**content** | Option<**String**> | To test escaping of parameters in rust code works | |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ impl<C: hyper::client::connect::Connect> FakeApiClient<C>
}

pub trait FakeApi {
fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;
fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, any_type: &str, uppercase: Option<&str>, content: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;
}

impl<C: hyper::client::connect::Connect>FakeApi for FakeApiClient<C>
where C: Clone + std::marker::Send + Sync {
#[allow(unused_mut)]
fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> {
fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, any_type: &str, uppercase: Option<&str>, content: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> {
let mut req = __internal_request::Request::new(hyper::Method::GET, "/fake/user/{user_name}".to_string())
;
if let Some(ref s) = content {
let query_value = s.to_string();
req = req.with_query_param("content".to_string(), query_value);
}
req = req.with_query_param("anyType".to_string(), any_type.to_string());
req = req.with_path_param("user_name".to_string(), user_name.to_string());
match dummy_required_nullable_param {
Some(param_value) => { req = req.with_header_param("dummy_required_nullable_param".to_string(), param_value.to_string()); },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct AnyTypeTest {
#[serde(rename = "foo", deserialize_with = "Option::deserialize")]
pub foo: Option<serde_json::Value>,
}

impl AnyTypeTest {
pub fn new(foo: Option<serde_json::Value>) -> AnyTypeTest {
AnyTypeTest {
foo,
}
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod action_container;
pub use self::action_container::ActionContainer;
pub mod any_type_test;
pub use self::any_type_test::AnyTypeTest;
pub mod api_response;
pub use self::api_response::ApiResponse;
pub mod array_item_ref_test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Cargo.toml
README.md
docs/ActionContainer.md
docs/AnyTypeTest.md
docs/ApiResponse.md
docs/ArrayItemRefTest.md
docs/Baz.md
Expand Down Expand Up @@ -35,6 +36,7 @@ src/apis/testing_api.rs
src/apis/user_api.rs
src/lib.rs
src/models/action_container.rs
src/models/any_type_test.rs
src/models/api_response.rs
src/models/array_item_ref_test.rs
src/models/baz.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Class | Method | HTTP request | Description
## Documentation For Models

- [ActionContainer](docs/ActionContainer.md)
- [AnyTypeTest](docs/AnyTypeTest.md)
- [ApiResponse](docs/ApiResponse.md)
- [ArrayItemRefTest](docs/ArrayItemRefTest.md)
- [Baz](docs/Baz.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AnyTypeTest

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**foo** | Option<[**serde_json::Value**](.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
Expand Up @@ -10,7 +10,7 @@ Method | HTTP request | Description

## test_nullable_required_param

> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content)
> test_nullable_required_param(user_name, dummy_required_nullable_param, any_type, uppercase, content)
To test nullable required parameters


Expand All @@ -22,6 +22,7 @@ Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**user_name** | **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] |
**any_type** | **String** | | [required] |
**uppercase** | Option<**String**> | To test parameter names in upper case | |
**content** | Option<**String**> | To test escaping of parameters in rust code works | |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::{Error, configuration};
pub trait FakeApi: Send + Sync {

/// GET /fake/user/{user_name}
async fn test_nullable_required_param<'user_name, 'dummy_required_nullable_param, 'uppercase, 'content>(&self, user_name: &'user_name str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, uppercase: Option<&'uppercase str>, content: Option<&'content str>) -> Result<(), Error<TestNullableRequiredParamError>>;
async fn test_nullable_required_param<'user_name, 'dummy_required_nullable_param, 'any_type, 'uppercase, 'content>(&self, user_name: &'user_name str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, any_type: &'any_type str, uppercase: Option<&'uppercase str>, content: Option<&'content str>) -> Result<(), Error<TestNullableRequiredParamError>>;
}

pub struct FakeApiClient {
Expand All @@ -41,7 +41,7 @@ impl FakeApiClient {
#[async_trait]
impl FakeApi for FakeApiClient {
///
async fn test_nullable_required_param<'user_name, 'dummy_required_nullable_param, 'uppercase, 'content>(&self, user_name: &'user_name str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, uppercase: Option<&'uppercase str>, content: Option<&'content str>) -> Result<(), Error<TestNullableRequiredParamError>> {
async fn test_nullable_required_param<'user_name, 'dummy_required_nullable_param, 'any_type, 'uppercase, 'content>(&self, user_name: &'user_name str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, any_type: &'any_type str, uppercase: Option<&'uppercase str>, content: Option<&'content str>) -> Result<(), Error<TestNullableRequiredParamError>> {
let local_var_configuration = &self.configuration;

let local_var_client = &local_var_configuration.client;
Expand All @@ -52,6 +52,7 @@ impl FakeApi for FakeApiClient {
if let Some(ref local_var_str) = content {
local_var_req_builder = local_var_req_builder.query(&[("content", &local_var_str.to_string())]);
}
local_var_req_builder = local_var_req_builder.query(&[("anyType", &any_type.to_string())]);
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct AnyTypeTest {
#[serde(rename = "foo", deserialize_with = "Option::deserialize")]
pub foo: Option<serde_json::Value>,
}

impl AnyTypeTest {
pub fn new(foo: Option<serde_json::Value>) -> AnyTypeTest {
AnyTypeTest {
foo,
}
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod action_container;
pub use self::action_container::ActionContainer;
pub mod any_type_test;
pub use self::any_type_test::AnyTypeTest;
pub mod api_response;
pub use self::api_response::ApiResponse;
pub mod array_item_ref_test;
Expand Down
Loading
Loading