chore: moved schema file to torn-api crate
This commit is contained in:
parent
6482c951a1
commit
b6c74d17be
|
@ -61,11 +61,11 @@ impl Model {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::openapi::schema::OpenApiSchema;
|
use crate::openapi::schema::test::get_schema;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_newtypes() {
|
fn resolve_newtypes() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let user_id_schema = schema.components.schemas.get("UserId").unwrap();
|
let user_id_schema = schema.components.schemas.get("UserId").unwrap();
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_all() {
|
fn resolve_all() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let mut unresolved = vec![];
|
let mut unresolved = vec![];
|
||||||
let total = schema.components.schemas.len();
|
let total = schema.components.schemas.len();
|
||||||
|
|
|
@ -420,11 +420,11 @@ impl ObjectNamespace<'_> {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::openapi::schema::OpenApiSchema;
|
use crate::openapi::schema::test::get_schema;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_object() {
|
fn resolve_object() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let attack = schema.components.schemas.get("FactionUpgrades").unwrap();
|
let attack = schema.components.schemas.get("FactionUpgrades").unwrap();
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_objects() {
|
fn resolve_objects() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let mut objects = 0;
|
let mut objects = 0;
|
||||||
let mut unresolved = vec![];
|
let mut unresolved = vec![];
|
||||||
|
|
|
@ -342,13 +342,13 @@ The default value [Self::{}](self::{}#variant.{})"#,
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::openapi::{path::OpenApiPathParameter, schema::OpenApiSchema};
|
use crate::openapi::{path::OpenApiPathParameter, schema::test::get_schema};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_components() {
|
fn resolve_components() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let mut parameters = 0;
|
let mut parameters = 0;
|
||||||
let mut unresolved = vec![];
|
let mut unresolved = vec![];
|
||||||
|
@ -376,7 +376,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_inline() {
|
fn resolve_inline() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let mut params = 0;
|
let mut params = 0;
|
||||||
let mut unresolved = Vec::new();
|
let mut unresolved = Vec::new();
|
||||||
|
@ -404,7 +404,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn codegen_inline() {
|
fn codegen_inline() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let mut params = 0;
|
let mut params = 0;
|
||||||
let mut unresolved = Vec::new();
|
let mut unresolved = Vec::new();
|
||||||
|
|
|
@ -592,11 +592,11 @@ impl PathNamespace<'_> {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::openapi::schema::OpenApiSchema;
|
use crate::openapi::schema::test::get_schema;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_paths() {
|
fn resolve_paths() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let mut paths = 0;
|
let mut paths = 0;
|
||||||
let mut unresolved = vec![];
|
let mut unresolved = vec![];
|
||||||
|
@ -624,7 +624,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn codegen_paths() {
|
fn codegen_paths() {
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let schema = get_schema();
|
||||||
|
|
||||||
let mut paths = 0;
|
let mut paths = 0;
|
||||||
let mut unresolved = vec![];
|
let mut unresolved = vec![];
|
||||||
|
|
|
@ -9,14 +9,14 @@ pub enum ParameterLocation {
|
||||||
Path,
|
Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum OpenApiParameterDefault<'a> {
|
pub enum OpenApiParameterDefault<'a> {
|
||||||
Int(i32),
|
Int(i32),
|
||||||
Str(&'a str),
|
Str(&'a str),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||||
pub struct OpenApiParameterSchema<'a> {
|
pub struct OpenApiParameterSchema<'a> {
|
||||||
#[serde(rename = "$ref")]
|
#[serde(rename = "$ref")]
|
||||||
pub ref_path: Option<&'a str>,
|
pub ref_path: Option<&'a str>,
|
||||||
|
@ -29,7 +29,7 @@ pub struct OpenApiParameterSchema<'a> {
|
||||||
pub items: Option<Box<OpenApiParameterSchema<'a>>>,
|
pub items: Option<Box<OpenApiParameterSchema<'a>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||||
pub struct OpenApiParameter<'a> {
|
pub struct OpenApiParameter<'a> {
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
pub description: Option<Cow<'a, str>>,
|
pub description: Option<Cow<'a, str>>,
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
|
|
||||||
use super::parameter::OpenApiParameter;
|
use super::parameter::OpenApiParameter;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum OpenApiPathParameter<'a> {
|
pub enum OpenApiPathParameter<'a> {
|
||||||
Link {
|
Link {
|
||||||
|
@ -14,13 +14,13 @@ pub enum OpenApiPathParameter<'a> {
|
||||||
Inline(OpenApiParameter<'a>),
|
Inline(OpenApiParameter<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||||
pub struct SchemaLink<'a> {
|
pub struct SchemaLink<'a> {
|
||||||
#[serde(rename = "$ref")]
|
#[serde(rename = "$ref")]
|
||||||
pub ref_path: &'a str,
|
pub ref_path: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum OpenApiResponseBody<'a> {
|
pub enum OpenApiResponseBody<'a> {
|
||||||
Schema(SchemaLink<'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>
|
fn deserialize_response_body<'de, D>(deserializer: D) -> Result<OpenApiResponseBody<'de>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
|
@ -60,7 +63,8 @@ where
|
||||||
Ok(responses.ok.content.json.schema)
|
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 struct OpenApiPathBody<'a> {
|
||||||
pub summary: Option<Cow<'a, str>>,
|
pub summary: Option<Cow<'a, str>>,
|
||||||
pub description: Option<Cow<'a, str>>,
|
pub description: Option<Cow<'a, str>>,
|
||||||
|
@ -72,6 +76,7 @@ pub struct OpenApiPathBody<'a> {
|
||||||
deserialize_with = "deserialize_response_body"
|
deserialize_with = "deserialize_response_body"
|
||||||
)]
|
)]
|
||||||
pub response_content: OpenApiResponseBody<'a>,
|
pub response_content: OpenApiResponseBody<'a>,
|
||||||
|
pub operation_id: Option<OperationId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
|
|
@ -19,20 +19,12 @@ pub struct OpenApiSchema<'a> {
|
||||||
pub components: Components<'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)]
|
#[cfg(test)]
|
||||||
mod test {
|
pub(crate) mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
pub(crate) fn get_schema() -> OpenApiSchema<'static> {
|
||||||
fn read() {
|
let s = include_str!("../../../torn-api/openapi.json");
|
||||||
OpenApiSchema::read().unwrap();
|
serde_json::from_str(s).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,3 +41,4 @@ torn-api-codegen = { path = "../torn-api-codegen", version = "0.3.0" }
|
||||||
syn = { workspace = true, features = ["parsing"] }
|
syn = { workspace = true, features = ["parsing"] }
|
||||||
proc-macro2 = { workspace = true }
|
proc-macro2 = { workspace = true }
|
||||||
prettyplease = "0.2"
|
prettyplease = "0.2"
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
|
|
@ -15,7 +15,8 @@ fn main() {
|
||||||
let requests_dest = Path::new(&out_dir).join("requests.rs");
|
let requests_dest = Path::new(&out_dir).join("requests.rs");
|
||||||
let scopes_dest = Path::new(&out_dir).join("scopes.rs");
|
let scopes_dest = Path::new(&out_dir).join("scopes.rs");
|
||||||
|
|
||||||
let schema = OpenApiSchema::read().unwrap();
|
let s = include_str!("./openapi.json");
|
||||||
|
let schema: OpenApiSchema = serde_json::from_str(s).unwrap();
|
||||||
|
|
||||||
let mut models_code = TokenStream::new();
|
let mut models_code = TokenStream::new();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue