Skip to content

Commit

Permalink
test: Update examples and run integration test
Browse files Browse the repository at this point in the history
Running `./bin/generate-samples.sh ./bin/configs/manual/*.yaml`
updated all examples. Most of them contain changes to their previously
checked in version that are not related to the fix for #18554.
`mvn integration-test -f samples/server/petstore/rust-axum/pom.xml`
passes.
  • Loading branch information
Mert Yildiz committed May 4, 2024
1 parent f8b0109 commit b197ad1
Show file tree
Hide file tree
Showing 24 changed files with 1,513 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.5.0-SNAPSHOT
7.6.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.7
- Generator version: 7.5.0-SNAPSHOT
- Generator version: 7.6.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.5.0-SNAPSHOT
7.6.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.7
- Generator version: 7.5.0-SNAPSHOT
- Generator version: 7.6.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{convert::TryFrom, fmt, ops::Deref};
use std::{convert::TryFrom, fmt, ops::Deref, str::FromStr};

use chrono::{DateTime, Utc};
use http::HeaderValue;
Expand Down Expand Up @@ -195,3 +195,36 @@ impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
}
}
}

// uuid::Uuid

impl TryFrom<HeaderValue> for IntoHeaderValue<uuid::Uuid> {
type Error = String;

fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
match hdr_value.to_str() {
Ok(hdr_value) => match uuid::Uuid::from_str(hdr_value) {
Ok(uuid) => Ok(IntoHeaderValue(uuid)),
Err(e) => Err(format!("Unable to parse: {} as uuid - {}", hdr_value, e)),
},
Err(e) => Err(format!(
"Unable to convert header {:?} to string {}",
hdr_value, e
)),
}
}
}

impl TryFrom<IntoHeaderValue<uuid::Uuid>> for HeaderValue {
type Error = String;

fn try_from(hdr_value: IntoHeaderValue<uuid::Uuid>) -> Result<Self, Self::Error> {
match HeaderValue::from_bytes(hdr_value.0.as_bytes()) {
Ok(hdr_value) => Ok(hdr_value),
Err(e) => Err(format!(
"Unable to convert {:?} to a header: {}",
hdr_value, e
)),
}
}
}
17 changes: 17 additions & 0 deletions samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ pub enum UuidGetResponse {
Status200_DuplicateResponseLongText(uuid::Uuid),
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[must_use]
#[allow(clippy::large_enum_variant)]
pub enum UuidInHeaderGetResponse {
/// Test uuid deserialization from header value.
Status200_TestUuidDeserializationFromHeaderValue,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[must_use]
#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -440,6 +448,15 @@ pub trait Api {
cookies: CookieJar,
) -> Result<UuidGetResponse, String>;

/// UuidInHeaderGet - GET /uuid_in_header
async fn uuid_in_header_get(
&self,
method: Method,
host: Host,
cookies: CookieJar,
header_params: models::UuidInHeaderGetHeaderParams,
) -> Result<UuidInHeaderGetResponse, String>;

/// XmlExtraPost - POST /xml_extra
async fn xml_extra_post(
&self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ pub struct RegisterCallbackPostQueryParams {
pub url: String,
}

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct UuidInHeaderGetHeaderParams {
pub some_uid: uuid::Uuid,
}

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct GetRepoInfoPathParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use crate::{
MultigetGetResponse, MultipleAuthSchemeGetResponse, OneOfGetResponse,
OverrideServerGetResponse, ParamgetGetResponse, ReadonlyAuthSchemeGetResponse,
RegisterCallbackPostResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse,
Rfc7807GetResponse, UntypedPropertyGetResponse, UuidGetResponse, XmlExtraPostResponse,
XmlOtherPostResponse, XmlOtherPutResponse, XmlPostResponse, XmlPutResponse,
Rfc7807GetResponse, UntypedPropertyGetResponse, UuidGetResponse, UuidInHeaderGetResponse,
XmlExtraPostResponse, XmlOtherPostResponse, XmlOtherPutResponse, XmlPostResponse,
XmlPutResponse,
};

/// Setup API Server.
Expand Down Expand Up @@ -79,6 +80,7 @@ where
.route("/rfc7807", get(rfc7807_get::<I, A>))
.route("/untyped_property", get(untyped_property_get::<I, A>))
.route("/uuid", get(uuid_get::<I, A>))
.route("/uuid_in_header", get(uuid_in_header_get::<I, A>))
.route("/xml", post(xml_post::<I, A>).put(xml_put::<I, A>))
.route("/xml_extra", post(xml_extra_post::<I, A>))
.route(
Expand Down Expand Up @@ -1606,6 +1608,96 @@ where
})
}

#[tracing::instrument(skip_all)]
fn uuid_in_header_get_validation(
header_params: models::UuidInHeaderGetHeaderParams,
) -> std::result::Result<(models::UuidInHeaderGetHeaderParams,), ValidationErrors> {
header_params.validate()?;

Ok((header_params,))
}
/// UuidInHeaderGet - GET /uuid_in_header
#[tracing::instrument(skip_all)]
async fn uuid_in_header_get<I, A>(
method: Method,
host: Host,
cookies: CookieJar,
headers: HeaderMap,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
I: AsRef<A> + Send + Sync,
A: Api,
{
// Header parameters
let header_params = {
let header_some_uid = headers.get(HeaderName::from_static("some_uid"));

let header_some_uid = match header_some_uid {
Some(v) => match header::IntoHeaderValue::<uuid::Uuid>::try_from((*v).clone()) {
Ok(result) => result.0,
Err(err) => {
return Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Invalid header some_uid - {}", err)))
.map_err(|e| {
error!(error = ?e);
StatusCode::INTERNAL_SERVER_ERROR
});
}
},
None => {
return Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Missing required header some_uid"))
.map_err(|e| {
error!(error = ?e);
StatusCode::INTERNAL_SERVER_ERROR
});
}
};

models::UuidInHeaderGetHeaderParams {
some_uid: header_some_uid,
}
};

let validation = uuid_in_header_get_validation(header_params);

let Ok((header_params,)) = validation else {
return Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(validation.unwrap_err().to_string()))
.map_err(|_| StatusCode::BAD_REQUEST);
};

let result = api_impl
.as_ref()
.uuid_in_header_get(method, host, cookies, header_params)
.await;

let mut response = Response::builder();

let resp = match result {
Ok(rsp) => match rsp {
UuidInHeaderGetResponse::Status200_TestUuidDeserializationFromHeaderValue => {
let mut response = response.status(200);
response.body(Body::empty())
}
},
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
response.status(500).body(Body::empty())
}
};

resp.map_err(|e| {
error!(error = ?e);
StatusCode::INTERNAL_SERVER_ERROR
})
}

#[derive(validator::Validate)]
#[allow(dead_code)]
struct XmlExtraPostBodyValidator<'a> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.5.0-SNAPSHOT
7.6.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/server/petstore/rust-axum/output/ops-v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 0.0.1
- Generator version: 7.5.0-SNAPSHOT
- Generator version: 7.6.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.5.0-SNAPSHOT
7.6.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.0
- Generator version: 7.5.0-SNAPSHOT
- Generator version: 7.6.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ pub trait Api {
method: Method,
host: Host,
cookies: CookieJar,
body: models::TestEndpointParametersRequest,
) -> Result<TestEndpointParametersResponse, String>;

/// To test enum parameters.
Expand All @@ -457,6 +458,7 @@ pub trait Api {
cookies: CookieJar,
header_params: models::TestEnumParametersHeaderParams,
query_params: models::TestEnumParametersQueryParams,
body: Option<models::TestEnumParametersRequest>,
) -> Result<TestEnumParametersResponse, String>;

/// test inline additionalProperties.
Expand All @@ -478,6 +480,7 @@ pub trait Api {
method: Method,
host: Host,
cookies: CookieJar,
body: models::TestJsonFormDataRequest,
) -> Result<TestJsonFormDataResponse, String>;

/// To test class name in snake case.
Expand Down Expand Up @@ -567,6 +570,7 @@ pub trait Api {
host: Host,
cookies: CookieJar,
path_params: models::UpdatePetWithFormPathParams,
body: Option<models::UpdatePetWithFormRequest>,
) -> Result<UpdatePetWithFormResponse, String>;

/// uploads an image.
Expand Down
Loading

0 comments on commit b197ad1

Please sign in to comment.