1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-23 04:52:28 +00:00

attempt to add query params to openapi

This commit is contained in:
Dominic 2019-10-13 23:12:12 +02:00
parent 0153b2e22f
commit d025183a09
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -177,23 +177,33 @@ fn schema_to_content(schema : ReferenceOr<Schema>) -> IndexMap<String, MediaType
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() {
204 => IndexMap::new(),
_ => schema_to_content(schema)
};
path_params : Vec<&'a str>,
query_params : Option<OpenapiSchema>
}
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()
}));
impl<'a> OperationParams<'a>
{
fn new(path_params : Vec<&'a str>, query_params : Option<OpenapiSchema>) -> Self
{
Self { path_params, query_params }
}
let mut params : Vec<ReferenceOr<Parameter>> = Vec::new();
for param in path_params
fn from_path_params(path_params : Vec<&'a str>) -> Self
{
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 {
parameter_data: ParameterData {
@ -208,6 +218,39 @@ fn new_operation(default_status : hyper::StatusCode, schema : ReferenceOr<Schema
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 {
description: None,
@ -221,7 +264,7 @@ fn new_operation(default_status : hyper::StatusCode, schema : ReferenceOr<Schema
description: None,
external_documentation: None,
operation_id: None, // TODO
parameters: params,
parameters: params.params(),
request_body,
responses: Responses {
default: None,