Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor Author

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

error-chain = "0.12"
semver = "0.9.0"
url = "1.6.0"
url_serde = "0.2.0"
140 changes: 99 additions & 41 deletions src/v2/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -165,10 +165,66 @@ 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,
_ => Default::default(),
}
}
}

impl From<PropertyDefault> for bool {
fn from(item: PropertyDefault) -> Self {
match item {
PropertyDefault::Boolean(item) => item,
_ => Default::default(),
}
}
}

impl From<PropertyDefault> 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")]
Expand All @@ -177,13 +233,52 @@ pub struct Parameter {
pub schema: Option<Schema>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unique_items: Option<bool>,
/// string, number, boolean, integer, array, file ( only for formData )
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "type")]
pub param_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<String>,
/// 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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
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")]
// Enum of possible values for this parameter
#[serde(rename = "enum")]
pub enum_values: Option<Vec<String>>,
// Pattern for the string of this parameter
#[serde(skip_serializing_if = "Option::is_none")]
pub pattern: Option<String>,
// collectionFormat: ???
// multipleOf ??
// allowEmptyValue ( for query / body params )
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
Expand All @@ -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<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
schema: Option<Schema>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "uniqueItems")]
unique_items: Option<bool>,
/// string, number, boolean, integer, array, file ( only for formData )
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "type")]
param_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
format: Option<String>,
/// 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<String>,
// 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 {
Expand Down