-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
89 changed files
with
7,468 additions
and
1,213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- schemars-v1 | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use apistos_models::paths::{MediaType, Response, Responses}; | ||
use apistos_models::reference_or::ReferenceOr; | ||
use apistos_models::{ApistosSchema, OpenApiVersion, VersionSpecificSchema}; | ||
|
||
pub fn response_from_schema( | ||
oas_version: OpenApiVersion, | ||
status: &str, | ||
schema: Option<(String, ReferenceOr<ApistosSchema>)>, | ||
) -> Option<Responses> { | ||
schema.map(|(name, schema)| match schema { | ||
ReferenceOr::Reference { _ref } => Responses { | ||
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Reference { _ref })]), | ||
..Default::default() | ||
}, | ||
ReferenceOr::Object(sch) => { | ||
let schema = match oas_version { | ||
OpenApiVersion::OAS3_0 => VersionSpecificSchema::OAS3_0(ReferenceOr::Reference { | ||
_ref: format!("#/components/schemas/{}", name), | ||
}), | ||
OpenApiVersion::OAS3_1 => VersionSpecificSchema::OAS3_1(sch), | ||
}; | ||
let response = Response { | ||
content: BTreeMap::from_iter(vec![( | ||
"application/json".to_string(), | ||
MediaType { | ||
schema: Some(schema), | ||
..Default::default() | ||
}, | ||
)]), | ||
..Default::default() | ||
}; | ||
Responses { | ||
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(response))]), | ||
..Default::default() | ||
} | ||
} | ||
}) | ||
} | ||
|
||
pub fn response_from_raw_schema( | ||
oas_version: OpenApiVersion, | ||
status: &str, | ||
raw_schema: Option<ReferenceOr<ApistosSchema>>, | ||
) -> Option<Responses> { | ||
raw_schema.map(|schema| match schema { | ||
ReferenceOr::Reference { _ref } => Responses { | ||
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Reference { _ref })]), | ||
..Default::default() | ||
}, | ||
ReferenceOr::Object(sch) => { | ||
let schema = match oas_version { | ||
OpenApiVersion::OAS3_0 => VersionSpecificSchema::OAS3_0(sch.into()), | ||
OpenApiVersion::OAS3_1 => VersionSpecificSchema::OAS3_1(sch), | ||
}; | ||
let response = Response { | ||
content: BTreeMap::from_iter(vec![( | ||
"application/json".to_string(), | ||
MediaType { | ||
schema: Some(schema), | ||
..Default::default() | ||
}, | ||
)]), | ||
..Default::default() | ||
}; | ||
Responses { | ||
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(response))]), | ||
..Default::default() | ||
} | ||
} | ||
}) | ||
} | ||
|
||
pub fn response_for_status(status: &str) -> Responses { | ||
Responses { | ||
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(Default::default()))]), | ||
..Default::default() | ||
} | ||
} |
Oops, something went wrong.