diff --git a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache index 43c8d17fadcb..7532ccd8f316 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -8,6 +8,7 @@ edition = "2018" serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" +serde_repr = "^0.1" url = "^2.2" {{#hyper}} hyper = "~0.11" diff --git a/modules/openapi-generator/src/main/resources/rust/lib.mustache b/modules/openapi-generator/src/main/resources/rust/lib.mustache index cdc5287aae73..fb68f4b1a497 100644 --- a/modules/openapi-generator/src/main/resources/rust/lib.mustache +++ b/modules/openapi-generator/src/main/resources/rust/lib.mustache @@ -1,5 +1,7 @@ #[macro_use] extern crate serde_derive; +#[macro_use] +extern crate serde_repr; extern crate serde; extern crate serde_json; diff --git a/modules/openapi-generator/src/main/resources/rust/model.mustache b/modules/openapi-generator/src/main/resources/rust/model.mustache index 974bc54bd100..d47c9178b716 100644 --- a/modules/openapi-generator/src/main/resources/rust/model.mustache +++ b/modules/openapi-generator/src/main/resources/rust/model.mustache @@ -5,8 +5,35 @@ /// {{{classname}}} : {{{description}}} {{/description}} +{{!-- for repr(int) enum schemas --}} +{{#isEnum}} +{{#isInteger}} +/// {{{description}}} +#[repr(i64)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize_repr, Deserialize_repr)] +pub enum {{{classname}}} { +{{#allowableValues}} +{{#enumVars}} + {{{name}}} = {{{value}}}, +{{/enumVars}}{{/allowableValues}} +} + +impl ToString for {{{classname}}} { + fn to_string(&self) -> String { + match self { + {{#allowableValues}} + {{#enumVars}} + Self::{{{name}}} => String::from("{{{value}}}"), + {{/enumVars}} + {{/allowableValues}} + } + } +} +{{/isInteger}} +{{/isEnum}} {{!-- for enum schemas --}} {{#isEnum}} +{{^isInteger}} /// {{{description}}} #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum {{{classname}}} { @@ -28,6 +55,7 @@ impl ToString for {{{classname}}} { } } } +{{/isInteger}} {{/isEnum}} {{!-- for schemas that have a discriminator --}} diff --git a/samples/client/petstore/rust/hyper/petstore/Cargo.toml b/samples/client/petstore/rust/hyper/petstore/Cargo.toml index 4bed4953a557..61f1f142aaf2 100644 --- a/samples/client/petstore/rust/hyper/petstore/Cargo.toml +++ b/samples/client/petstore/rust/hyper/petstore/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" +serde_repr = "^0.1" url = "^2.2" hyper = "~0.11" serde_yaml = "0.7" diff --git a/samples/client/petstore/rust/hyper/petstore/src/lib.rs b/samples/client/petstore/rust/hyper/petstore/src/lib.rs index a76d822525da..40bbd4a53d93 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/lib.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/lib.rs @@ -1,5 +1,7 @@ #[macro_use] extern crate serde_derive; +#[macro_use] +extern crate serde_repr; extern crate serde; extern crate serde_json; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml index a0c16dfdb530..289fb2ba4f32 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" +serde_repr = "^0.1" url = "^2.2" [dependencies.reqwest] version = "^0.11" diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/lib.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/lib.rs index c1dd666f7957..53156b6a4211 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/lib.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/lib.rs @@ -1,5 +1,7 @@ #[macro_use] extern crate serde_derive; +#[macro_use] +extern crate serde_repr; extern crate serde; extern crate serde_json; diff --git a/samples/client/petstore/rust/reqwest/petstore/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore/Cargo.toml index 4e6f624c352b..fcf8d32959d5 100644 --- a/samples/client/petstore/rust/reqwest/petstore/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" +serde_repr = "^0.1" url = "^2.2" reqwest = "~0.9" diff --git a/samples/client/petstore/rust/reqwest/petstore/src/lib.rs b/samples/client/petstore/rust/reqwest/petstore/src/lib.rs index c1dd666f7957..53156b6a4211 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/lib.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/lib.rs @@ -1,5 +1,7 @@ #[macro_use] extern crate serde_derive; +#[macro_use] +extern crate serde_repr; extern crate serde; extern crate serde_json;