mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 13:02:28 +00:00
attempt to add query params to openapi
This commit is contained in:
parent
0153b2e22f
commit
d025183a09
1 changed files with 62 additions and 19 deletions
|
@ -177,23 +177,33 @@ fn schema_to_content(schema : ReferenceOr<Schema>) -> IndexMap<String, MediaType
|
||||||
content
|
content
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_operation(default_status : hyper::StatusCode, schema : ReferenceOr<Schema>, path_params : Vec<&str>, body_schema : Option<ReferenceOr<Schema>>) -> Operation
|
#[derive(Default)]
|
||||||
|
struct OperationParams<'a>
|
||||||
{
|
{
|
||||||
let content = match default_status.as_u16() {
|
path_params : Vec<&'a str>,
|
||||||
204 => IndexMap::new(),
|
query_params : Option<OpenapiSchema>
|
||||||
_ => schema_to_content(schema)
|
}
|
||||||
};
|
|
||||||
|
|
||||||
let mut responses : IndexMap<StatusCode, ReferenceOr<Response>> = IndexMap::new();
|
impl<'a> OperationParams<'a>
|
||||||
responses.insert(StatusCode::Code(default_status.as_u16()), Item(Response {
|
{
|
||||||
description: default_status.canonical_reason().map(|d| d.to_string()).unwrap_or_default(),
|
fn new(path_params : Vec<&'a str>, query_params : Option<OpenapiSchema>) -> Self
|
||||||
headers: IndexMap::new(),
|
{
|
||||||
content,
|
Self { path_params, query_params }
|
||||||
links: IndexMap::new()
|
}
|
||||||
}));
|
|
||||||
|
|
||||||
let mut params : Vec<ReferenceOr<Parameter>> = Vec::new();
|
fn from_path_params(path_params : Vec<&'a str>) -> Self
|
||||||
for param in path_params
|
{
|
||||||
|
Self::new(path_params, None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_query_params(query_params : OpenapiSchema) -> Self
|
||||||
|
{
|
||||||
|
Self::new(Vec::new(), Some(query_params))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_path_params(&self, params : &mut Vec<ReferenceOr<Parameter>>)
|
||||||
|
{
|
||||||
|
for param in self.path_params
|
||||||
{
|
{
|
||||||
params.push(Item(Parameter::Path {
|
params.push(Item(Parameter::Path {
|
||||||
parameter_data: ParameterData {
|
parameter_data: ParameterData {
|
||||||
|
@ -208,6 +218,39 @@ fn new_operation(default_status : hyper::StatusCode, schema : ReferenceOr<Schema
|
||||||
style: PathStyle::default(),
|
style: PathStyle::default(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_query_params(&self, params : &mut Vec<ReferenceOr<Parameter>>)
|
||||||
|
{
|
||||||
|
let query_params = match self.query_params {
|
||||||
|
Some(qp) => qp,
|
||||||
|
None => return
|
||||||
|
};
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
fn params(&self) -> Vec<ReferenceOr<Parameter>>
|
||||||
|
{
|
||||||
|
let mut params : Vec<ReferenceOr<Parameter>> = Vec::new();
|
||||||
|
self.add_path_params(&mut params);
|
||||||
|
params
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_operation(default_status : hyper::StatusCode, schema : ReferenceOr<Schema>, params : OperationParams, body_schema : Option<ReferenceOr<Schema>>) -> Operation
|
||||||
|
{
|
||||||
|
let content = match default_status.as_u16() {
|
||||||
|
204 => IndexMap::new(),
|
||||||
|
_ => schema_to_content(schema)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut responses : IndexMap<StatusCode, ReferenceOr<Response>> = IndexMap::new();
|
||||||
|
responses.insert(StatusCode::Code(default_status.as_u16()), Item(Response {
|
||||||
|
description: default_status.canonical_reason().map(|d| d.to_string()).unwrap_or_default(),
|
||||||
|
headers: IndexMap::new(),
|
||||||
|
content,
|
||||||
|
links: IndexMap::new()
|
||||||
|
}));
|
||||||
|
|
||||||
let request_body = body_schema.map(|schema| Item(RequestBody {
|
let request_body = body_schema.map(|schema| Item(RequestBody {
|
||||||
description: None,
|
description: None,
|
||||||
|
@ -221,7 +264,7 @@ fn new_operation(default_status : hyper::StatusCode, schema : ReferenceOr<Schema
|
||||||
description: None,
|
description: None,
|
||||||
external_documentation: None,
|
external_documentation: None,
|
||||||
operation_id: None, // TODO
|
operation_id: None, // TODO
|
||||||
parameters: params,
|
parameters: params.params(),
|
||||||
request_body,
|
request_body,
|
||||||
responses: Responses {
|
responses: Responses {
|
||||||
default: None,
|
default: None,
|
||||||
|
|
Loading…
Add table
Reference in a new issue