From 9f9930bb716d95ca83b8fc34f5fc6be0a04e7c24 Mon Sep 17 00:00:00 2001 From: Jordi Polo Date: Thu, 8 Mar 2018 15:05:10 -0800 Subject: [PATCH 1/7] Adds default min and max to param --- src/v2/schema.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/src/v2/schema.rs b/src/v2/schema.rs index d03aa12..95715dc 100644 --- a/src/v2/schema.rs +++ b/src/v2/schema.rs @@ -165,6 +165,59 @@ 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, + _ => 1, + } + } +} + +impl From for bool { + fn from(item: PropertyDefault) -> Self { + match item { + PropertyDefault::Boolean(item) => item, + _ => true, + } + } +} + +impl From for String { + fn from(item: PropertyDefault) -> Self { + match item { + PropertyDefault::String(item) => item, + _ => "".to_string(), + } + } +} + #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] #[serde(rename_all = "camelCase")] pub struct Parameter { @@ -184,6 +237,13 @@ pub struct Parameter { pub format: Option, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] + //#[serde(deserialize_with = "deserialize_default_param")] + pub default: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub minimum: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub maximum: Option, } #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] @@ -223,11 +283,19 @@ pub enum ParameterOrRef { /// of use. GitHub Flavored Markdown is allowed. #[serde(skip_serializing_if = "Option::is_none")] description: Option, + /// The default value of this parameter. + /// Deser from String because it can be any type. + #[serde(skip_serializing_if = "Option::is_none")] + //#[serde(deserialize_with = "deserialize_default_param")] + default: Option, + /// The minimum valid value for this parameter. + #[serde(skip_serializing_if = "Option::is_none")] + minimum: Option, + /// The maximum valid value for this parameter. + #[serde(skip_serializing_if = "Option::is_none")] + maximum: Option, // collectionFormat: ??? - // default: ??? - // maximum ? // exclusiveMaximum ?? - // minimum ?? // exclusiveMinimum ?? // maxLength ?? // minLength ?? @@ -243,6 +311,7 @@ pub enum ParameterOrRef { ref_path: String, }, } + #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(tag = "type")] pub enum Security { From 7f7a270161c79e2f51cfcc2b5f684a0a785f4b26 Mon Sep 17 00:00:00 2001 From: Jordi Polo Date: Sun, 11 Mar 2018 07:08:12 -0700 Subject: [PATCH 2/7] Adds enum values to parameters --- src/v2/schema.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/v2/schema.rs b/src/v2/schema.rs index 95715dc..5b08b3b 100644 --- a/src/v2/schema.rs +++ b/src/v2/schema.rs @@ -244,6 +244,9 @@ pub struct Parameter { pub minimum: Option, #[serde(skip_serializing_if = "Option::is_none")] pub maximum: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(rename = "enum")] + pub enum_values: Option>, } #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] @@ -294,6 +297,9 @@ pub enum ParameterOrRef { /// The maximum valid value for this parameter. #[serde(skip_serializing_if = "Option::is_none")] maximum: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(rename = "enum")] + enum_values: Option>, // collectionFormat: ??? // exclusiveMaximum ?? // exclusiveMinimum ?? From 8cbb469febfbeb4c8574aa96d7d7959375c65c4d Mon Sep 17 00:00:00 2001 From: Jordi Polo Date: Mon, 16 Apr 2018 09:49:47 -0700 Subject: [PATCH 3/7] add operationid rename --- src/v2/schema.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/v2/schema.rs b/src/v2/schema.rs index 5b08b3b..9460f2d 100644 --- a/src/v2/schema.rs +++ b/src/v2/schema.rs @@ -158,6 +158,7 @@ pub struct Operation { pub schemes: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, + #[serde(rename = "operationId")] #[serde(skip_serializing_if = "Option::is_none")] pub operation_id: Option, pub responses: BTreeMap, From 48be538c8795d889766bd7a594759819e72d728e Mon Sep 17 00:00:00 2001 From: jcarres-mdsol Date: Sat, 3 Nov 2018 22:23:54 -0700 Subject: [PATCH 4/7] Adds maxLength, maxItems, ExclusiveMaximum and their minimum variants to the schema --- Cargo.toml | 4 ++-- src/v2/schema.rs | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) 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 9460f2d..c7d6dd4 100644 --- a/src/v2/schema.rs +++ b/src/v2/schema.rs @@ -295,20 +295,32 @@ pub enum ParameterOrRef { /// The minimum valid value for this parameter. #[serde(skip_serializing_if = "Option::is_none")] 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")] + exclusiveMinimum: Option, /// The maximum valid value for this parameter. #[serde(skip_serializing_if = "Option::is_none")] 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")] + exclusiveMaximum: Option, + /// The maximum number of characters of a String + #[serde(skip_serializing_if = "Option::is_none")] + maxLength: Option, + /// The minimum number of characters of a String + #[serde(skip_serializing_if = "Option::is_none")] + minLength: Option, + /// The maximum number of items of an array + #[serde(skip_serializing_if = "Option::is_none")] + maxItems: Option, + /// The minimmum number of items of an array + #[serde(skip_serializing_if = "Option::is_none")] + minItems: Option, #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "enum")] enum_values: Option>, // collectionFormat: ??? - // exclusiveMaximum ?? - // exclusiveMinimum ?? - // maxLength ?? - // minLength ?? // pattern ?? - // maxItems ?? - // minItems ?? // enum ?? // multipleOf ?? // allowEmptyValue ( for query / body params ) From 23c61f46deb70bb7ad3318e7a13a52d0e9e4d90c Mon Sep 17 00:00:00 2001 From: jcarres-mdsol Date: Sat, 3 Nov 2018 22:25:43 -0700 Subject: [PATCH 5/7] Adds changes to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 727124863a0dbe10858a5a8d6caa76f8ae16eda4 Mon Sep 17 00:00:00 2001 From: jcarres-mdsol Date: Sat, 3 Nov 2018 23:01:48 -0700 Subject: [PATCH 6/7] Changes field names to snake cases and serde to rename everything as camelCase --- src/v2/schema.rs | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/v2/schema.rs b/src/v2/schema.rs index c7d6dd4..ee8156c 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, @@ -158,7 +158,6 @@ pub struct Operation { pub schemes: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, - #[serde(rename = "operationId")] #[serde(skip_serializing_if = "Option::is_none")] pub operation_id: Option, pub responses: BTreeMap, @@ -241,10 +240,30 @@ pub struct Parameter { #[serde(skip_serializing_if = "Option::is_none")] //#[serde(deserialize_with = "deserialize_default_param")] 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")] #[serde(rename = "enum")] pub enum_values: Option>, @@ -260,6 +279,7 @@ 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)] @@ -297,25 +317,25 @@ pub enum ParameterOrRef { 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")] - exclusiveMinimum: Option, + exclusive_minimum: Option, /// The maximum valid value for this parameter. #[serde(skip_serializing_if = "Option::is_none")] 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")] - exclusiveMaximum: Option, + exclusive_maximum: Option, /// The maximum number of characters of a String #[serde(skip_serializing_if = "Option::is_none")] - maxLength: Option, + max_length: Option, /// The minimum number of characters of a String #[serde(skip_serializing_if = "Option::is_none")] - minLength: Option, + min_length: Option, /// The maximum number of items of an array #[serde(skip_serializing_if = "Option::is_none")] - maxItems: Option, + max_items: Option, /// The minimmum number of items of an array #[serde(skip_serializing_if = "Option::is_none")] - minItems: Option, + min_items: Option, #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "enum")] enum_values: Option>, From 6efec718feb4b53f5372fed0d4704fe62d4e09ce Mon Sep 17 00:00:00 2001 From: jcarres-mdsol Date: Mon, 12 Nov 2018 17:40:43 -0800 Subject: [PATCH 7/7] Uses Default::default() for default property and makes Parameter a variant of ParameterOrRef instead of copying the structure --- src/v2/schema.rs | 84 ++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 67 deletions(-) diff --git a/src/v2/schema.rs b/src/v2/schema.rs index ee8156c..12ec681 100644 --- a/src/v2/schema.rs +++ b/src/v2/schema.rs @@ -195,7 +195,7 @@ impl From for i32 { fn from(item: PropertyDefault) -> Self { match item { PropertyDefault::Integer(item) => item, - _ => 1, + _ => Default::default(), } } } @@ -204,7 +204,7 @@ impl From for bool { fn from(item: PropertyDefault) -> Self { match item { PropertyDefault::Boolean(item) => item, - _ => true, + _ => Default::default(), } } } @@ -213,7 +213,7 @@ impl From for String { fn from(item: PropertyDefault) -> Self { match item { PropertyDefault::String(item) => item, - _ => "".to_string(), + _ => Default::default(), } } } @@ -221,7 +221,10 @@ impl From for String { #[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")] @@ -230,15 +233,17 @@ 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")] - //#[serde(deserialize_with = "deserialize_default_param")] pub default: Option, /// The minimum valid value for this parameter. #[serde(skip_serializing_if = "Option::is_none")] @@ -265,8 +270,15 @@ pub struct Parameter { #[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)] @@ -282,69 +294,7 @@ pub struct Response { #[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, - /// The default value of this parameter. - /// Deser from String because it can be any type. - #[serde(skip_serializing_if = "Option::is_none")] - //#[serde(deserialize_with = "deserialize_default_param")] - default: Option, - /// The minimum valid value for this parameter. - #[serde(skip_serializing_if = "Option::is_none")] - 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")] - exclusive_minimum: Option, - /// The maximum valid value for this parameter. - #[serde(skip_serializing_if = "Option::is_none")] - 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")] - exclusive_maximum: Option, - /// The maximum number of characters of a String - #[serde(skip_serializing_if = "Option::is_none")] - max_length: Option, - /// The minimum number of characters of a String - #[serde(skip_serializing_if = "Option::is_none")] - min_length: Option, - /// The maximum number of items of an array - #[serde(skip_serializing_if = "Option::is_none")] - max_items: Option, - /// The minimmum number of items of an array - #[serde(skip_serializing_if = "Option::is_none")] - min_items: Option, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(rename = "enum")] - enum_values: Option>, - // collectionFormat: ??? - // pattern ?? - // enum ?? - // multipleOf ?? - // allowEmptyValue ( for query / body params ) - }, + Parameter(Parameter), Ref { #[serde(rename = "$ref")] ref_path: String,