use std::collections::BTreeMap; use url::Url; #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct OpenApiV2 { pub swagger: String, pub info: SpecInfo, pub host: Option, pub base_path: Option, pub schemes: Option>, pub consumes: Option>, pub produces: Option>, pub paths: BTreeMap, pub definitions: Option>, pub parameters: Option>, pub responses: Option>, pub security_definitions: Option>, pub security: Option>>>, pub tags: Option>, pub external_docs: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct SpecInfo { pub title: String, pub description: Option, pub terms_of_service: Option, pub contact: Option, pub license: Option, pub version: String, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Contact { pub name: Option, pub url: Option, pub email: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct License { pub name: String, pub url: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct PathItem { #[serde(rename = "$ref")] pub _ref: Option, pub get: Option, pub put: Option, pub post: Option, pub delete: Option, pub options: Option, pub head: Option, pub patch: Option, pub parameters: Option>>, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Operation { pub tags: Option>, pub summary: Option, pub description: Option, pub external_docs: Option, pub operation_id: Option, pub consumes: Option>, pub produces: Option>, pub parameters: Option>>, pub responses: Responses, pub schemes: Option>, pub deprecated: Option, pub security: Option>>>, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct ExternalDocs { pub description: Option, pub url: Url, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Parameter { pub name: String, #[serde(rename = "in")] pub _in: ParameterIn, pub description: Option, pub required: Option, pub schema: Option>, #[serde(rename = "type")] pub _type: Option, pub format: Option, pub allow_empty_value: Option, pub items: Option, pub collection_format: Option, pub default: Option, pub maximum: Option, pub exclusive_maximum: Option, pub minimum: Option, pub exclusive_minimum: Option, pub max_length: Option, pub min_length: Option, pub pattern: Option, // should be regex pub max_items: Option, pub min_items: Option, pub unique_items: Option, #[serde(rename = "enum")] pub _enum: Option>, pub multiple_of: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub enum ParameterIn { Path, Query, Header, Body, FormData, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub enum ParameterType { String, Number, Integer, Boolean, Array, File, } #[derive(serde::Deserialize, Debug, PartialEq, Clone, Copy)] #[serde(rename_all(deserialize = "camelCase"))] pub enum CollectionFormat { Csv, Ssv, Tsv, Pipes, Multi, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Items { #[serde(rename = "type")] pub _type: ParameterType, pub format: Option, pub items: Option>, pub collection_format: Option, pub default: Option, pub maximum: Option, pub exclusive_maximum: Option, pub minimum: Option, pub exclusive_minimum: Option, pub max_length: Option, pub min_length: Option, pub pattern: Option, // should be regex pub max_items: Option, pub min_items: Option, pub unique_items: Option, #[serde(rename = "enum")] pub _enum: Option>, pub multiple_of: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Responses { pub default: Option>, #[serde(flatten)] pub http_codes: BTreeMap>, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Response { pub description: String, pub schema: Option>, pub headers: Option>, pub examples: Option>, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Header { pub description: Option, #[serde(rename = "type")] pub _type: ParameterType, pub format: Option, pub items: Option, pub collection_format: Option, pub default: Option, pub maximum: Option, pub exclusive_maximum: Option, pub minimum: Option, pub exclusive_minimum: Option, pub max_length: Option, pub min_length: Option, pub pattern: Option, // should be regex pub max_items: Option, pub min_items: Option, pub unique_items: Option, #[serde(rename = "enum")] pub _enum: Option>, pub multiple_of: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Tag { pub name: String, pub description: Option, pub external_docs: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Schema { pub format: Option, pub title: Option, pub description: Option, pub default: Option, pub multiple_of: Option, pub maximum: Option, pub exclusive_maximum: Option, pub minimum: Option, pub exclusive_minimum: Option, pub max_length: Option, pub min_length: Option, pub pattern: Option, // should be regex pub max_items: Option, pub min_items: Option, pub unique_items: Option, pub max_properties: Option, pub min_properties: Option, pub required: Option>, #[serde(rename = "enum")] pub _enum: Option>, #[serde(rename = "type")] pub _type: Option, pub properties: Option>>, pub additional_properties: Option>>, pub items: Option>>, pub discriminator: Option, pub read_only: Option, pub xml: Option, pub external_docs: Option, pub example: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(untagged)] pub enum SchemaType { One(Primitive), List(Vec), } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub enum Primitive { Array, Boolean, Integer, Number, Null, Object, String, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct Xml { pub name: Option, pub namespace: Option, pub prefix: Option, pub attribute: Option, pub wrapped: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub struct SecurityScheme { #[serde(flatten)] pub _type: SecurityType, pub description: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"), tag = "type")] pub enum SecurityType { Basic, ApiKey { name: String, #[serde(rename = "in")] _in: KeyIn, }, OAuth2 { #[serde(flatten)] flow: OAuth2Flow, scopes: BTreeMap, }, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"))] pub enum KeyIn { Query, Header, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(rename_all(deserialize = "camelCase"), tag = "flow")] pub enum OAuth2Flow { Implicit { authorization_url: Url, }, Password { token_url: Url, }, Application { token_url: Url, }, AccessCode { authorization_url: Url, token_url: Url, }, } #[derive(serde::Deserialize, Debug, PartialEq)] #[serde(untagged)] pub enum MaybeRef { Ref { #[serde(rename = "$ref")] _ref: String, }, Value { #[serde(flatten)] value: T, }, }