chore: moved schema file to torn-api crate
This commit is contained in:
parent
11c5d71bf6
commit
6d57f275a2
10 changed files with 33 additions and 34 deletions
|
|
@ -9,14 +9,14 @@ pub enum ParameterLocation {
|
|||
Path,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
pub enum OpenApiParameterDefault<'a> {
|
||||
Int(i32),
|
||||
Str(&'a str),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub struct OpenApiParameterSchema<'a> {
|
||||
#[serde(rename = "$ref")]
|
||||
pub ref_path: Option<&'a str>,
|
||||
|
|
@ -29,7 +29,7 @@ pub struct OpenApiParameterSchema<'a> {
|
|||
pub items: Option<Box<OpenApiParameterSchema<'a>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub struct OpenApiParameter<'a> {
|
||||
pub name: &'a str,
|
||||
pub description: Option<Cow<'a, str>>,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
use super::parameter::OpenApiParameter;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
pub enum OpenApiPathParameter<'a> {
|
||||
Link {
|
||||
|
|
@ -14,13 +14,13 @@ pub enum OpenApiPathParameter<'a> {
|
|||
Inline(OpenApiParameter<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub struct SchemaLink<'a> {
|
||||
#[serde(rename = "$ref")]
|
||||
pub ref_path: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
pub enum OpenApiResponseBody<'a> {
|
||||
Schema(SchemaLink<'a>),
|
||||
|
|
@ -30,6 +30,9 @@ pub enum OpenApiResponseBody<'a> {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub struct OperationId(pub String);
|
||||
|
||||
fn deserialize_response_body<'de, D>(deserializer: D) -> Result<OpenApiResponseBody<'de>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
|
|
@ -60,7 +63,8 @@ where
|
|||
Ok(responses.ok.content.json.schema)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct OpenApiPathBody<'a> {
|
||||
pub summary: Option<Cow<'a, str>>,
|
||||
pub description: Option<Cow<'a, str>>,
|
||||
|
|
@ -72,6 +76,7 @@ pub struct OpenApiPathBody<'a> {
|
|||
deserialize_with = "deserialize_response_body"
|
||||
)]
|
||||
pub response_content: OpenApiResponseBody<'a>,
|
||||
pub operation_id: Option<OperationId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
|
|
|
|||
|
|
@ -19,20 +19,12 @@ pub struct OpenApiSchema<'a> {
|
|||
pub components: Components<'a>,
|
||||
}
|
||||
|
||||
impl OpenApiSchema<'_> {
|
||||
pub fn read() -> Result<Self, serde_json::Error> {
|
||||
let s = include_str!("../../openapi.json");
|
||||
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
pub(crate) mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn read() {
|
||||
OpenApiSchema::read().unwrap();
|
||||
pub(crate) fn get_schema() -> OpenApiSchema<'static> {
|
||||
let s = include_str!("../../../torn-api/openapi.json");
|
||||
serde_json::from_str(s).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue