Skip to content

Commit d9636b8

Browse files
author
Bradford Hovinen
committed
Support deprecated API endpoints in reqwest-based Rust clients
Previously, if an API endpoint was marked deprecated, this fact was not reflected in the generated Rust clients using the reqwest library. We want to know exactly when our client code is using a deprecated endpoint, so marking the corresponding functions with the `#[deprecatd]` attribute would be very helpful. Uses of the endpoint would then be picked up by linters so that we can react. This adds a line to the template which marks functions generated from deprecated endpoints with the `#[deprecated]` attribute. This does not touch any of the other client generators for Rust or any other language, since they are out of scope for our needs. Unfortunately, even after about a dozen attempts, I was unable to coax Mustache into not introducing an extra vertical whitespace when the `#[deprecated]` attribute is absent. This has no effect on functionality of the generated code, but is visually unappealing.
1 parent 1240d10 commit d9636b8

46 files changed

Lines changed: 196 additions & 0 deletions

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/resources/rust/reqwest/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub enum {{{operationIdCamelCase}}}Error {
9999
{{#notes}}
100100
/// {{{.}}}
101101
{{/notes}}
102+
{{#isDeprecated}}#[deprecated]{{/isDeprecated}}
102103
{{#vendorExtensions.x-group-parameters}}
103104
pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration{{#allParams}}{{#-first}}, {{!
104105
### Params

samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum ReproError {
2323
}
2424

2525

26+
2627
pub fn repro(configuration: &configuration::Configuration, ) -> Result<models::Parent, Error<ReproError>> {
2728

2829
let uri_str = format!("{}/repro", configuration.base_path);

samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum DemoColorGetError {
2323
}
2424

2525

26+
2627
pub async fn demo_color_get(configuration: &configuration::Configuration, color: models::Color) -> Result<(), Error<DemoColorGetError>> {
2728
// add a prefix to parameters to efficiently prevent name collisions
2829
let p_path_color = color;

samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum GetStateError {
3030
}
3131

3232

33+
3334
pub fn create_state(configuration: &configuration::Configuration, create_state_request: models::CreateStateRequest) -> Result<(), Error<CreateStateError>> {
3435
// add a prefix to parameters to efficiently prevent name collisions
3536
let p_body_create_state_request = create_state_request;
@@ -56,6 +57,7 @@ pub fn create_state(configuration: &configuration::Configuration, create_state_r
5657
}
5758
}
5859

60+
5961
pub fn get_state(configuration: &configuration::Configuration, ) -> Result<models::GetState200Response, Error<GetStateError>> {
6062

6163
let uri_str = format!("{}/state", configuration.base_path);

samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum EndpointGetError {
2323
}
2424

2525

26+
2627
pub fn endpoint_get(configuration: &configuration::Configuration, ) -> Result<models::EmptyObject, Error<EndpointGetError>> {
2728

2829
let uri_str = format!("{}/endpoint", configuration.base_path);

samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum TestError {
3030
}
3131

3232

33+
3334
pub fn root_get(configuration: &configuration::Configuration, ) -> Result<models::Fruit, Error<RootGetError>> {
3435

3536
let uri_str = format!("{}/", configuration.base_path);
@@ -64,6 +65,7 @@ pub fn root_get(configuration: &configuration::Configuration, ) -> Result<models
6465
}
6566
}
6667

68+
6769
pub fn test(configuration: &configuration::Configuration, body: Option<serde_json::Value>) -> Result<(), Error<TestError>> {
6870
// add a prefix to parameters to efficiently prevent name collisions
6971
let p_body_body = body;

samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum GetFruitError {
2323
}
2424

2525

26+
2627
pub fn get_fruit(configuration: &configuration::Configuration, ) -> Result<models::Fruit, Error<GetFruitError>> {
2728

2829
let uri_str = format!("{}/example", configuration.base_path);

samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum CreateBarError {
2323
}
2424

2525

26+
2627
pub fn create_bar(configuration: &configuration::Configuration, bar_create: models::BarCreate) -> Result<models::Bar, Error<CreateBarError>> {
2728
// add a prefix to parameters to efficiently prevent name collisions
2829
let p_body_bar_create = bar_create;

samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum GetAllFoosError {
3030
}
3131

3232

33+
3334
pub fn create_foo(configuration: &configuration::Configuration, foo: Option<models::Foo>) -> Result<models::FooRefOrValue, Error<CreateFooError>> {
3435
// add a prefix to parameters to efficiently prevent name collisions
3536
let p_body_foo = foo;
@@ -67,6 +68,7 @@ pub fn create_foo(configuration: &configuration::Configuration, foo: Option<mode
6768
}
6869
}
6970

71+
7072
pub fn get_all_foos(configuration: &configuration::Configuration, ) -> Result<Vec<models::FooRefOrValue>, Error<GetAllFoosError>> {
7173

7274
let uri_str = format!("{}/foo", configuration.base_path);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum GetParameterNameMappingError {
2323
}
2424

2525

26+
2627
pub fn get_parameter_name_mapping(configuration: &configuration::Configuration, underscore_type: i64, r#type: &str, type_with_underscore: &str, dash_type: &str, http_debug_option: &str) -> Result<(), Error<GetParameterNameMappingError>> {
2728
// add a prefix to parameters to efficiently prevent name collisions
2829
let p_header_underscore_type = underscore_type;

0 commit comments

Comments
 (0)