-
Notifications
You must be signed in to change notification settings - Fork 57
Adds default, and various properties related to minimum and maximum #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
9f9930b
7f7a270
8cbb469
48be538
23c61f4
7271248
6efec71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<String>, | ||
|
|
@@ -165,6 +165,59 @@ pub struct Operation { | |
| pub parameters: Option<Vec<ParameterOrRef>>, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] | ||
| #[serde(untagged)] | ||
| pub enum PropertyDefault { | ||
| Integer(i32), | ||
| Boolean(bool), | ||
| String(String), | ||
| } | ||
|
|
||
| impl From<i32> for PropertyDefault { | ||
| fn from(item: i32) -> Self { | ||
| PropertyDefault::Integer(item) | ||
| } | ||
| } | ||
|
|
||
| impl From<bool> for PropertyDefault { | ||
| fn from(item: bool) -> Self { | ||
| PropertyDefault::Boolean(item) | ||
| } | ||
| } | ||
|
|
||
| impl From<String> for PropertyDefault { | ||
| fn from(item: String) -> Self { | ||
| PropertyDefault::String(item) | ||
| } | ||
| } | ||
|
|
||
| impl From<PropertyDefault> for i32 { | ||
| fn from(item: PropertyDefault) -> Self { | ||
| match item { | ||
| PropertyDefault::Integer(item) => item, | ||
| _ => 1, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<PropertyDefault> for bool { | ||
| fn from(item: PropertyDefault) -> Self { | ||
| match item { | ||
| PropertyDefault::Boolean(item) => item, | ||
| _ => true, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about using rusts defaults for these i.e. returning
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I'm using Default::default() now. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<PropertyDefault> 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,36 @@ pub struct Parameter { | |
| pub format: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub description: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| //#[serde(deserialize_with = "deserialize_default_param")] | ||
| pub default: Option<PropertyDefault>, | ||
| /// The minimum valid value for this parameter. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub minimum: Option<i32>, | ||
| /// 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<bool>, | ||
| /// The maximum valid value for this parameter. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub maximum: Option<i32>, | ||
| /// 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<bool>, | ||
| /// The maximum number of characters of a String | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub max_length: Option<i32>, | ||
| /// The minimum number of characters of a String | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub min_length: Option<i32>, | ||
| /// The maximum number of items of an array | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub max_items: Option<i32>, | ||
| /// The minimmum number of items of an array | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub min_items: Option<i32>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[serde(rename = "enum")] | ||
| pub enum_values: Option<Vec<String>>, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] | ||
|
|
@@ -196,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)] | ||
|
|
@@ -223,17 +307,40 @@ pub enum ParameterOrRef { | |
| /// of use. GitHub Flavored Markdown is allowed. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| description: Option<String>, | ||
| /// 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<PropertyDefault>, | ||
| /// The minimum valid value for this parameter. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| minimum: Option<i32>, | ||
| /// 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<bool>, | ||
| /// The maximum valid value for this parameter. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| maximum: Option<i32>, | ||
| /// 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<bool>, | ||
| /// The maximum number of characters of a String | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| max_length: Option<i32>, | ||
| /// The minimum number of characters of a String | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| min_length: Option<i32>, | ||
| /// The maximum number of items of an array | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| max_items: Option<i32>, | ||
| /// The minimmum number of items of an array | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| min_items: Option<i32>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[serde(rename = "enum")] | ||
| enum_values: Option<Vec<String>>, | ||
| // collectionFormat: ??? | ||
| // default: ??? | ||
| // maximum ? | ||
| // exclusiveMaximum ?? | ||
| // minimum ?? | ||
| // exclusiveMinimum ?? | ||
| // maxLength ?? | ||
| // minLength ?? | ||
| // pattern ?? | ||
| // maxItems ?? | ||
| // minItems ?? | ||
| // enum ?? | ||
| // multipleOf ?? | ||
| // allowEmptyValue ( for query / body params ) | ||
|
|
@@ -243,6 +350,7 @@ pub enum ParameterOrRef { | |
| ref_path: String, | ||
| }, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] | ||
| #[serde(tag = "type")] | ||
| pub enum Security { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason for these two. Newer is better I'd hope