Skip to content

Commit cba1936

Browse files
authored
feat: Added doc comments to Rust reqwest-trait template (OpenAPITools#20591)
1 parent 8998d83 commit cba1936

24 files changed

Lines changed: 116 additions & 38 deletions

File tree

modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ use super::{Error, configuration};
1818
pub trait {{{classname}}}: Send + Sync {
1919
{{#operations}}
2020
{{#operation}}
21+
22+
/// {{{httpMethod}}} {{{path}}}
23+
{{^notes.empty}}
24+
///
25+
/// {{{notes}}}
26+
{{/notes.empty}}
2127
{{#vendorExtensions.x-group-parameters}}
2228
async fn {{{operationId}}}(&self, {{#allParams}}{{#-first}} params: {{{operationIdCamelCase}}}Params {{/-first}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>>;
2329
{{/vendorExtensions.x-group-parameters}}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ paths:
2323
tags:
2424
- pet
2525
summary: Add a new pet to the store
26-
description: ''
26+
description: This is the description for the addPet operation
2727
operationId: addPet
2828
responses:
2929
'200':
@@ -76,7 +76,9 @@ paths:
7676
tags:
7777
- pet
7878
summary: Finds Pets by status
79-
description: Multiple status values can be provided with comma separated strings
79+
description: |
80+
Multiple status values can be provided with comma separated strings.
81+
This is also a multi-line description to test rust doc comments
8082
operationId: findPetsByStatus
8183
parameters:
8284
- name: status

samples/client/petstore/rust/hyper/petstore/docs/PetApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Method | HTTP request | Description
2020
> models::Pet add_pet(pet)
2121
Add a new pet to the store
2222

23-
23+
This is the description for the addPet operation
2424

2525
### Parameters
2626

@@ -81,7 +81,7 @@ Name | Type | Description | Required | Notes
8181
> Vec<models::Pet> find_pets_by_status(status, r#type)
8282
Finds Pets by status
8383

84-
Multiple status values can be provided with comma separated strings
84+
Multiple status values can be provided with comma separated strings. This is also a multi-line description to test rust doc comments
8585

8686
### Parameters
8787

samples/client/petstore/rust/hyper0x/petstore/docs/PetApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Method | HTTP request | Description
2020
> models::Pet add_pet(pet)
2121
Add a new pet to the store
2222

23-
23+
This is the description for the addPet operation
2424

2525
### Parameters
2626

@@ -81,7 +81,7 @@ Name | Type | Description | Required | Notes
8181
> Vec<models::Pet> find_pets_by_status(status, r#type)
8282
Finds Pets by status
8383

84-
Multiple status values can be provided with comma separated strings
84+
Multiple status values can be provided with comma separated strings. This is also a multi-line description to test rust doc comments
8585

8686
### Parameters
8787

samples/client/petstore/rust/reqwest-trait/petstore/docs/PetApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Method | HTTP request | Description
2020
> models::Pet add_pet(pet)
2121
Add a new pet to the store
2222

23-
23+
This is the description for the addPet operation
2424

2525
### Parameters
2626

@@ -81,7 +81,7 @@ Name | Type | Description | Required | Notes
8181
> Vec<models::Pet> find_pets_by_status(status, r#type)
8282
Finds Pets by status
8383

84-
Multiple status values can be provided with comma separated strings
84+
Multiple status values can be provided with comma separated strings. This is also a multi-line description to test rust doc comments
8585

8686
### Parameters
8787

samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use super::{Error, configuration};
2121
#[cfg_attr(feature = "mockall", automock)]
2222
#[async_trait]
2323
pub trait FakeApi: Send + Sync {
24+
25+
/// GET /fake/user/{user_name}
2426
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>>;
2527
}
2628

samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,37 @@ use super::{Error, configuration};
2121
#[cfg_attr(feature = "mockall", automock)]
2222
#[async_trait]
2323
pub trait PetApi: Send + Sync {
24+
25+
/// POST /pet
26+
///
27+
/// This is the description for the addPet operation
2428
async fn add_pet<'pet>(&self, pet: models::Pet) -> Result<models::Pet, Error<AddPetError>>;
29+
30+
/// DELETE /pet/{petId}
2531
async fn delete_pet<'pet_id, 'api_key>(&self, pet_id: i64, api_key: Option<&'api_key str>) -> Result<(), Error<DeletePetError>>;
32+
33+
/// GET /pet/findByStatus
34+
///
35+
/// Multiple status values can be provided with comma separated strings. This is also a multi-line description to test rust doc comments
2636
async fn find_pets_by_status<'status, 'r_type>(&self, status: Vec<String>, r#type: Option<Vec<String>>) -> Result<Vec<models::Pet>, Error<FindPetsByStatusError>>;
37+
38+
/// GET /pet/findByTags
39+
///
40+
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
2741
async fn find_pets_by_tags<'tags>(&self, tags: Vec<String>) -> Result<Vec<models::Pet>, Error<FindPetsByTagsError>>;
42+
43+
/// GET /pet/{petId}
44+
///
45+
/// Returns a single pet
2846
async fn get_pet_by_id<'pet_id>(&self, pet_id: i64) -> Result<models::Pet, Error<GetPetByIdError>>;
47+
48+
/// PUT /pet
2949
async fn update_pet<'pet>(&self, pet: models::Pet) -> Result<models::Pet, Error<UpdatePetError>>;
50+
51+
/// POST /pet/{petId}
3052
async fn update_pet_with_form<'pet_id, 'name, 'status>(&self, pet_id: i64, name: Option<&'name str>, status: Option<&'status str>) -> Result<(), Error<UpdatePetWithFormError>>;
53+
54+
/// POST /pet/{petId}/uploadImage
3155
async fn upload_file<'pet_id, 'additional_metadata, 'file>(&self, pet_id: i64, additional_metadata: Option<&'additional_metadata str>, file: Option<std::path::PathBuf>) -> Result<models::ApiResponse, Error<UploadFileError>>;
3256
}
3357

@@ -45,7 +69,7 @@ impl PetApiClient {
4569

4670
#[async_trait]
4771
impl PetApi for PetApiClient {
48-
///
72+
/// This is the description for the addPet operation
4973
async fn add_pet<'pet>(&self, pet: models::Pet) -> Result<models::Pet, Error<AddPetError>> {
5074
let local_var_configuration = &self.configuration;
5175

@@ -111,7 +135,7 @@ impl PetApi for PetApiClient {
111135
}
112136
}
113137

114-
/// Multiple status values can be provided with comma separated strings
138+
/// Multiple status values can be provided with comma separated strings. This is also a multi-line description to test rust doc comments
115139
async fn find_pets_by_status<'status, 'r_type>(&self, status: Vec<String>, r#type: Option<Vec<String>>) -> Result<Vec<models::Pet>, Error<FindPetsByStatusError>> {
116140
let local_var_configuration = &self.configuration;
117141

samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,23 @@ use super::{Error, configuration};
2121
#[cfg_attr(feature = "mockall", automock)]
2222
#[async_trait]
2323
pub trait StoreApi: Send + Sync {
24+
25+
/// DELETE /store/order/{orderId}
26+
///
27+
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
2428
async fn delete_order<'order_id>(&self, order_id: &'order_id str) -> Result<(), Error<DeleteOrderError>>;
29+
30+
/// GET /store/inventory
31+
///
32+
/// Returns a map of status codes to quantities
2533
async fn get_inventory<>(&self, ) -> Result<std::collections::HashMap<String, i32>, Error<GetInventoryError>>;
34+
35+
/// GET /store/order/{orderId}
36+
///
37+
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
2638
async fn get_order_by_id<'order_id>(&self, order_id: i64) -> Result<models::Order, Error<GetOrderByIdError>>;
39+
40+
/// POST /store/order
2741
async fn place_order<'order>(&self, order: models::Order) -> Result<models::Order, Error<PlaceOrderError>>;
2842
}
2943

samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ use super::{Error, configuration};
2121
#[cfg_attr(feature = "mockall", automock)]
2222
#[async_trait]
2323
pub trait TestingApi: Send + Sync {
24+
25+
/// GET /tests/fileResponse
26+
///
27+
///
2428
async fn tests_file_response_get<>(&self, ) -> Result<std::path::PathBuf, Error<TestsFileResponseGetError>>;
29+
30+
/// GET /tests/typeTesting
31+
///
32+
///
2533
async fn tests_type_testing_get<>(&self, ) -> Result<models::TypeTesting, Error<TestsTypeTestingGetError>>;
2634
}
2735

samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,35 @@ use super::{Error, configuration};
2121
#[cfg_attr(feature = "mockall", automock)]
2222
#[async_trait]
2323
pub trait UserApi: Send + Sync {
24+
25+
/// POST /user
26+
///
27+
/// This can only be done by the logged in user.
2428
async fn create_user<'user>(&self, user: models::User) -> Result<(), Error<CreateUserError>>;
29+
30+
/// POST /user/createWithArray
2531
async fn create_users_with_array_input<'user>(&self, user: Vec<models::User>) -> Result<(), Error<CreateUsersWithArrayInputError>>;
32+
33+
/// POST /user/createWithList
2634
async fn create_users_with_list_input<'user>(&self, user: Vec<models::User>) -> Result<(), Error<CreateUsersWithListInputError>>;
35+
36+
/// DELETE /user/{username}
37+
///
38+
/// This can only be done by the logged in user.
2739
async fn delete_user<'username>(&self, username: &'username str) -> Result<(), Error<DeleteUserError>>;
40+
41+
/// GET /user/{username}
2842
async fn get_user_by_name<'username>(&self, username: &'username str) -> Result<models::User, Error<GetUserByNameError>>;
43+
44+
/// GET /user/login
2945
async fn login_user<'username, 'password>(&self, username: &'username str, password: &'password str) -> Result<String, Error<LoginUserError>>;
46+
47+
/// GET /user/logout
3048
async fn logout_user<>(&self, ) -> Result<(), Error<LogoutUserError>>;
49+
50+
/// PUT /user/{username}
51+
///
52+
/// This can only be done by the logged in user.
3153
async fn update_user<'username, 'user>(&self, username: &'username str, user: models::User) -> Result<(), Error<UpdateUserError>>;
3254
}
3355

0 commit comments

Comments
 (0)