diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fd33e6..187ab80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Derives Default for all structs * Derives Clone for all structs * Changes the order of the output to be more similar to OpenAPI examples +* Adds lots of properties related to minimum and maximum values # 0.1.5 diff --git a/Cargo.toml b/Cargo.toml index 8cc541c..d8b1711 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,8 @@ license = "MIT" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" -serde_yaml = "0.7" -error-chain = "0.10" +serde_yaml = "0.8" +error-chain = "0.12" semver = "0.9.0" url = "1.6.0" url_serde = "0.2.0" diff --git a/src/v2/schema.rs b/src/v2/schema.rs index d03aa12..12ec681 100644 --- a/src/v2/schema.rs +++ b/src/v2/schema.rs @@ -144,7 +144,7 @@ pub struct PathItem { } #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] -#[serde(rename_all = "lowercase")] +#[serde(rename_all = "camelCase")] pub struct Operation { #[serde(skip_serializing_if = "Option::is_none")] pub summary: Option, @@ -165,10 +165,66 @@ pub struct Operation { pub parameters: Option>, } +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +#[serde(untagged)] +pub enum PropertyDefault { + Integer(i32), + Boolean(bool), + String(String), +} + +impl From for PropertyDefault { + fn from(item: i32) -> Self { + PropertyDefault::Integer(item) + } +} + +impl From for PropertyDefault { + fn from(item: bool) -> Self { + PropertyDefault::Boolean(item) + } +} + +impl From for PropertyDefault { + fn from(item: String) -> Self { + PropertyDefault::String(item) + } +} + +impl From for i32 { + fn from(item: PropertyDefault) -> Self { + match item { + PropertyDefault::Integer(item) => item, + _ => Default::default(), + } + } +} + +impl From for bool { + fn from(item: PropertyDefault) -> Self { + match item { + PropertyDefault::Boolean(item) => item, + _ => Default::default(), + } + } +} + +impl From for String { + fn from(item: PropertyDefault) -> Self { + match item { + PropertyDefault::String(item) => item, + _ => Default::default(), + } + } +} + #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] #[serde(rename_all = "camelCase")] pub struct Parameter { + /// The name of the parameter. pub name: String, + /// values depend on parameter type + /// may be `header`, `query`, 'path`, `formData` #[serde(rename = "in")] pub location: String, #[serde(skip_serializing_if = "Option::is_none")] @@ -177,13 +233,52 @@ pub struct Parameter { pub schema: Option, #[serde(skip_serializing_if = "Option::is_none")] pub unique_items: Option, + /// string, number, boolean, integer, array, file ( only for formData ) #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "type")] pub param_type: Option, #[serde(skip_serializing_if = "Option::is_none")] pub format: Option, + /// A brief description of the parameter. This could contain examples + /// of use. GitHub Flavored Markdown is allowed. #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub default: Option, + /// The minimum valid value for this parameter. + #[serde(skip_serializing_if = "Option::is_none")] + pub minimum: Option, + /// When set to true the value of the minimum property is not part of the range + #[serde(skip_serializing_if = "Option::is_none")] + pub exclusive_minimum: Option, + /// The maximum valid value for this parameter. + #[serde(skip_serializing_if = "Option::is_none")] + pub maximum: Option, + /// When set to true the value of the maximum property is not part of the range + #[serde(skip_serializing_if = "Option::is_none")] + pub exclusive_maximum: Option, + /// The maximum number of characters of a String + #[serde(skip_serializing_if = "Option::is_none")] + pub max_length: Option, + /// The minimum number of characters of a String + #[serde(skip_serializing_if = "Option::is_none")] + pub min_length: Option, + /// The maximum number of items of an array + #[serde(skip_serializing_if = "Option::is_none")] + pub max_items: Option, + /// The minimmum number of items of an array + #[serde(skip_serializing_if = "Option::is_none")] + pub min_items: Option, + #[serde(skip_serializing_if = "Option::is_none")] + // Enum of possible values for this parameter + #[serde(rename = "enum")] + pub enum_values: Option>, + // Pattern for the string of this parameter + #[serde(skip_serializing_if = "Option::is_none")] + pub pattern: Option, + // collectionFormat: ??? + // multipleOf ?? + // allowEmptyValue ( for query / body params ) } #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] @@ -196,53 +291,16 @@ pub struct Response { // todo: support x-* fields #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(untagged)] +#[serde(rename_all = "camelCase")] pub enum ParameterOrRef { /// both bodyParameter and nonBodyParameter in one for now - #[derive(Default)] - Parameter { - /// The name of the parameter. - name: String, - /// values depend on parameter type - /// may be `header`, `query`, 'path`, `formData` - #[serde(rename = "in")] - location: String, - #[serde(skip_serializing_if = "Option::is_none")] - required: Option, - #[serde(skip_serializing_if = "Option::is_none")] - schema: Option, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(rename = "uniqueItems")] - unique_items: Option, - /// string, number, boolean, integer, array, file ( only for formData ) - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(rename = "type")] - param_type: Option, - #[serde(skip_serializing_if = "Option::is_none")] - format: Option, - /// A brief description of the parameter. This could contain examples - /// of use. GitHub Flavored Markdown is allowed. - #[serde(skip_serializing_if = "Option::is_none")] - description: Option, - // collectionFormat: ??? - // default: ??? - // maximum ? - // exclusiveMaximum ?? - // minimum ?? - // exclusiveMinimum ?? - // maxLength ?? - // minLength ?? - // pattern ?? - // maxItems ?? - // minItems ?? - // enum ?? - // multipleOf ?? - // allowEmptyValue ( for query / body params ) - }, + Parameter(Parameter), Ref { #[serde(rename = "$ref")] ref_path: String, }, } + #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(tag = "type")] pub enum Security {