forked from loafle/openapi-generator-original
[Rust Server] Return 405 Method Not Allowed (#5563)
* Return 405 Method Not Allowed if the path matches, but the method doesn't. * Update samples
This commit is contained in:
committed by
GitHub
parent
4aefc9ba33
commit
058d1d2aa0
@@ -38,6 +38,11 @@ use {{{operationId}}}Response;
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
{{#callbacks}}
|
||||
{{#pathSet}}
|
||||
_ if path.matched(paths::ID_{{PATH_ID}}) => method_not_allowed(),
|
||||
{{/pathSet}}
|
||||
{{/callbacks}}
|
||||
{{>server-service-footer}}
|
||||
/// Request parser for `Api`.
|
||||
pub struct ApiRequestParser;
|
||||
|
||||
@@ -19,6 +19,9 @@ pub mod callbacks;
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
{{#pathSet}}
|
||||
_ if path.matched(paths::ID_{{PATH_ID}}) => method_not_allowed(),
|
||||
{{/pathSet}}
|
||||
{{>server-service-footer}}
|
||||
/// Request parser for `Api`.
|
||||
pub struct ApiRequestParser;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
type ServiceFuture = Box<dyn Future<Item = Response<Body>, Error = Error> + Send>;
|
||||
|
||||
fn method_not_allowed() -> ServiceFuture {
|
||||
Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
|
||||
.body(Body::empty())
|
||||
.expect("Unable to create Method Not Allowed response")
|
||||
))
|
||||
}
|
||||
|
||||
pub struct Service<T, RC> {
|
||||
api_impl: T,
|
||||
marker: PhantomData<RC>,
|
||||
@@ -23,7 +33,7 @@ where
|
||||
type ReqBody = ContextualPayload<Body, C>;
|
||||
type ResBody = Body;
|
||||
type Error = Error;
|
||||
type Future = Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send>;
|
||||
type Future = ServiceFuture;
|
||||
|
||||
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
|
||||
let api_impl = self.api_impl.clone();
|
||||
|
||||
@@ -84,6 +84,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
type ServiceFuture = Box<dyn Future<Item = Response<Body>, Error = Error> + Send>;
|
||||
|
||||
fn method_not_allowed() -> ServiceFuture {
|
||||
Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
|
||||
.body(Body::empty())
|
||||
.expect("Unable to create Method Not Allowed response")
|
||||
))
|
||||
}
|
||||
|
||||
pub struct Service<T, RC> {
|
||||
api_impl: T,
|
||||
marker: PhantomData<RC>,
|
||||
@@ -109,7 +119,7 @@ where
|
||||
type ReqBody = ContextualPayload<Body, C>;
|
||||
type ResBody = Body;
|
||||
type Error = Error;
|
||||
type Future = Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send>;
|
||||
type Future = ServiceFuture;
|
||||
|
||||
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
|
||||
let api_impl = self.api_impl.clone();
|
||||
@@ -425,6 +435,8 @@ where
|
||||
)
|
||||
},
|
||||
|
||||
_ if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_MULTIPART_REQUEST) => method_not_allowed(),
|
||||
_ => Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::NOT_FOUND)
|
||||
.body(Body::empty())
|
||||
|
||||
@@ -91,6 +91,16 @@ where
|
||||
}
|
||||
|
||||
|
||||
type ServiceFuture = Box<dyn Future<Item = Response<Body>, Error = Error> + Send>;
|
||||
|
||||
fn method_not_allowed() -> ServiceFuture {
|
||||
Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
|
||||
.body(Body::empty())
|
||||
.expect("Unable to create Method Not Allowed response")
|
||||
))
|
||||
}
|
||||
|
||||
pub struct Service<T, RC> {
|
||||
api_impl: T,
|
||||
marker: PhantomData<RC>,
|
||||
@@ -116,7 +126,7 @@ where
|
||||
type ReqBody = ContextualPayload<Body, C>;
|
||||
type ResBody = Body;
|
||||
type Error = Error;
|
||||
type Future = Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send>;
|
||||
type Future = ServiceFuture;
|
||||
|
||||
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
|
||||
let api_impl = self.api_impl.clone();
|
||||
@@ -230,6 +240,8 @@ where
|
||||
}) as Self::Future
|
||||
},
|
||||
|
||||
_ if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => method_not_allowed(),
|
||||
_ => Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::NOT_FOUND)
|
||||
.body(Body::empty())
|
||||
|
||||
@@ -134,6 +134,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
type ServiceFuture = Box<dyn Future<Item = Response<Body>, Error = Error> + Send>;
|
||||
|
||||
fn method_not_allowed() -> ServiceFuture {
|
||||
Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
|
||||
.body(Body::empty())
|
||||
.expect("Unable to create Method Not Allowed response")
|
||||
))
|
||||
}
|
||||
|
||||
pub struct Service<T, RC> {
|
||||
api_impl: T,
|
||||
marker: PhantomData<RC>,
|
||||
@@ -159,7 +169,7 @@ where
|
||||
type ReqBody = ContextualPayload<Body, C>;
|
||||
type ResBody = Body;
|
||||
type Error = Error;
|
||||
type Future = Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send>;
|
||||
type Future = ServiceFuture;
|
||||
|
||||
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
|
||||
let api_impl = self.api_impl.clone();
|
||||
@@ -1404,6 +1414,23 @@ where
|
||||
) as Self::Future
|
||||
},
|
||||
|
||||
_ if path.matched(paths::ID_CALLBACK_WITH_HEADER) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_MERGE_PATCH_JSON) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_MULTIGET) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_PARAMGET) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_READONLY_AUTH_SCHEME) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_REGISTER_CALLBACK) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_RFC7807) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_UNTYPED_PROPERTY) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_UUID) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_XML) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_XML_EXTRA) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_XML_OTHER) => method_not_allowed(),
|
||||
_ => Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::NOT_FOUND)
|
||||
.body(Body::empty())
|
||||
|
||||
@@ -183,6 +183,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
type ServiceFuture = Box<dyn Future<Item = Response<Body>, Error = Error> + Send>;
|
||||
|
||||
fn method_not_allowed() -> ServiceFuture {
|
||||
Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
|
||||
.body(Body::empty())
|
||||
.expect("Unable to create Method Not Allowed response")
|
||||
))
|
||||
}
|
||||
|
||||
pub struct Service<T, RC> {
|
||||
api_impl: T,
|
||||
marker: PhantomData<RC>,
|
||||
@@ -208,7 +218,7 @@ where
|
||||
type ReqBody = ContextualPayload<Body, C>;
|
||||
type ResBody = Body;
|
||||
type Error = Error;
|
||||
type Future = Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send>;
|
||||
type Future = ServiceFuture;
|
||||
|
||||
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
|
||||
let api_impl = self.api_impl.clone();
|
||||
@@ -1552,6 +1562,43 @@ where
|
||||
}) as Self::Future
|
||||
},
|
||||
|
||||
_ if path.matched(paths::ID_OP1) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP10) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP11) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP12) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP13) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP14) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP15) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP16) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP17) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP18) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP19) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP2) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP20) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP21) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP22) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP23) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP24) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP25) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP26) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP27) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP28) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP29) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP3) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP30) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP31) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP32) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP33) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP34) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP35) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP36) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP37) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP4) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP5) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP6) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP7) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP8) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_OP9) => method_not_allowed(),
|
||||
_ => Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::NOT_FOUND)
|
||||
.body(Body::empty())
|
||||
|
||||
@@ -190,6 +190,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
type ServiceFuture = Box<dyn Future<Item = Response<Body>, Error = Error> + Send>;
|
||||
|
||||
fn method_not_allowed() -> ServiceFuture {
|
||||
Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
|
||||
.body(Body::empty())
|
||||
.expect("Unable to create Method Not Allowed response")
|
||||
))
|
||||
}
|
||||
|
||||
pub struct Service<T, RC> {
|
||||
api_impl: T,
|
||||
marker: PhantomData<RC>,
|
||||
@@ -215,7 +225,7 @@ where
|
||||
type ReqBody = ContextualPayload<Body, C>;
|
||||
type ResBody = Body;
|
||||
type Error = Error;
|
||||
type Future = Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send>;
|
||||
type Future = ServiceFuture;
|
||||
|
||||
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
|
||||
let api_impl = self.api_impl.clone();
|
||||
@@ -3061,6 +3071,33 @@ where
|
||||
) as Self::Future
|
||||
},
|
||||
|
||||
_ if path.matched(paths::ID_ANOTHER_FAKE_DUMMY) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_INLINE_ADDITIONALPROPERTIES) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_JSONFORMDATA) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_OPERATION_WITH_NUMERIC_ID) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_OUTER_BOOLEAN) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_OUTER_COMPOSITE) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_OUTER_NUMBER) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_OUTER_STRING) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_RESPONSE_WITH_NUMERICAL_DESCRIPTION) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FAKE_CLASSNAME_TEST) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_PET) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_PET_FINDBYSTATUS) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_PET_FINDBYTAGS) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_PET_PETID) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_PET_PETID_UPLOADIMAGE) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_STORE_INVENTORY) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_STORE_ORDER) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_USER) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_USER_CREATEWITHARRAY) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_USER_CREATEWITHLIST) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_USER_LOGIN) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_USER_LOGOUT) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_USER_USERNAME) => method_not_allowed(),
|
||||
_ => Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::NOT_FOUND)
|
||||
.body(Body::empty())
|
||||
|
||||
@@ -97,6 +97,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
type ServiceFuture = Box<dyn Future<Item = Response<Body>, Error = Error> + Send>;
|
||||
|
||||
fn method_not_allowed() -> ServiceFuture {
|
||||
Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
|
||||
.body(Body::empty())
|
||||
.expect("Unable to create Method Not Allowed response")
|
||||
))
|
||||
}
|
||||
|
||||
pub struct Service<T, RC> {
|
||||
api_impl: T,
|
||||
marker: PhantomData<RC>,
|
||||
@@ -122,7 +132,7 @@ where
|
||||
type ReqBody = ContextualPayload<Body, C>;
|
||||
type ResBody = Body;
|
||||
type Error = Error;
|
||||
type Future = Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send>;
|
||||
type Future = ServiceFuture;
|
||||
|
||||
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
|
||||
let api_impl = self.api_impl.clone();
|
||||
@@ -641,6 +651,14 @@ where
|
||||
) as Self::Future
|
||||
},
|
||||
|
||||
_ if path.matched(paths::ID_ALLOF) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_DUMMY) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_FILE_RESPONSE) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_GET_STRUCTURED_YAML) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_HTML) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_POST_YAML) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_RAW_JSON) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_SOLO_OBJECT) => method_not_allowed(),
|
||||
_ => Box::new(future::ok(
|
||||
Response::builder().status(StatusCode::NOT_FOUND)
|
||||
.body(Body::empty())
|
||||
|
||||
Reference in New Issue
Block a user