[rust-server] API version constant and composite version support (#7969)

* Add constant with API version

* Use semver::Version for ApiVersion

* Go back to API version as a string

* Rust composite services

* Actually use the version from the swagger file
This commit is contained in:
Benjamin Gill 2018-04-06 06:27:13 +01:00 committed by William Cheng
parent 386b9f432a
commit 37faaf9266
7 changed files with 22 additions and 5 deletions

View File

@ -19,7 +19,7 @@ chrono = { version = "0.4", features = ["serde"] }
futures = "0.1" futures = "0.1"
hyper = {version = "0.11", optional = true} hyper = {version = "0.11", optional = true}
hyper-tls = {version = "0.1.2", optional = true} hyper-tls = {version = "0.1.2", optional = true}
swagger = "0.9" swagger = "0.10.0"
# Not required by example server. # Not required by example server.
# #

View File

@ -33,6 +33,7 @@ mod mimetypes;
pub use swagger::{ApiError, Context, ContextWrapper}; pub use swagger::{ApiError, Context, ContextWrapper};
pub const BASE_PATH: &'static str = "{{basePathWithoutHost}}"; pub const BASE_PATH: &'static str = "{{basePathWithoutHost}}";
pub const API_VERSION: &'static str = "{{appVersion}}";
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}} {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
{{^isResponseFile}} {{^isResponseFile}}

View File

@ -17,7 +17,7 @@ chrono = { version = "0.4", features = ["serde"] }
futures = "0.1" futures = "0.1"
hyper = {version = "0.11", optional = true} hyper = {version = "0.11", optional = true}
hyper-tls = {version = "0.1.2", optional = true} hyper-tls = {version = "0.1.2", optional = true}
swagger = "0.9" swagger = "0.10.0"
# Not required by example server. # Not required by example server.
# #

View File

@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)
- API version: 1.0.0 - API version: 1.0.0
- Build date: 2018-02-06T14:00:33.084Z - Build date: 2018-04-03T12:24:00.479+01:00
This autogenerated project defines an API crate `petstore_api` which contains: This autogenerated project defines an API crate `petstore_api` which contains:
* An `Api` trait defining the API in Rust. * An `Api` trait defining the API in Rust.
@ -57,6 +57,7 @@ To run a client, follow one of the following simple steps:
``` ```
cargo run --example client TestSpecialTags cargo run --example client TestSpecialTags
cargo run --example client TestBodyWithQueryParams
cargo run --example client FakeOuterBooleanSerialize cargo run --example client FakeOuterBooleanSerialize
cargo run --example client FakeOuterCompositeSerialize cargo run --example client FakeOuterCompositeSerialize
cargo run --example client FakeOuterNumberSerialize cargo run --example client FakeOuterNumberSerialize

View File

@ -784,7 +784,7 @@ paths:
parameters: parameters:
- name: "username" - name: "username"
in: "path" in: "path"
description: "The name that needs to be fetched. Use user1 for testing. " description: "The name that needs to be fetched. Use user1 for testing."
required: true required: true
type: "string" type: "string"
formatString: "\\\"{}\\\"" formatString: "\\\"{}\\\""
@ -902,6 +902,7 @@ paths:
tags: tags:
- "fake_classname_tags 123#$%^" - "fake_classname_tags 123#$%^"
summary: "To test class name in snake case" summary: "To test class name in snake case"
description: "To test class name in snake case"
operationId: "testClassname" operationId: "testClassname"
consumes: consumes:
- "application/json" - "application/json"
@ -1900,6 +1901,8 @@ definitions:
upperCaseName: "ENUMCLASS" upperCaseName: "ENUMCLASS"
Enum_Test: Enum_Test:
type: "object" type: "object"
required:
- "enum_string_required"
properties: properties:
enum_string: enum_string:
type: "string" type: "string"
@ -1907,6 +1910,12 @@ definitions:
- "UPPER" - "UPPER"
- "lower" - "lower"
- "" - ""
enum_string_required:
type: "string"
enum:
- "UPPER"
- "lower"
- ""
enum_integer: enum_integer:
type: "integer" type: "integer"
format: "int32" format: "int32"

View File

@ -33,6 +33,7 @@ mod mimetypes;
pub use swagger::{ApiError, Context, ContextWrapper}; pub use swagger::{ApiError, Context, ContextWrapper};
pub const BASE_PATH: &'static str = "/v2"; pub const BASE_PATH: &'static str = "/v2";
pub const API_VERSION: &'static str = "1.0.0";
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View File

@ -361,6 +361,10 @@ pub struct EnumTest {
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub enum_string: Option<String>, pub enum_string: Option<String>,
// Note: inline enums are not fully supported by swagger-codegen
#[serde(rename = "enum_string_required")]
pub enum_string_required: String,
// Note: inline enums are not fully supported by swagger-codegen // Note: inline enums are not fully supported by swagger-codegen
#[serde(rename = "enum_integer")] #[serde(rename = "enum_integer")]
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
@ -378,9 +382,10 @@ pub struct EnumTest {
} }
impl EnumTest { impl EnumTest {
pub fn new() -> EnumTest { pub fn new(enum_string_required: String, ) -> EnumTest {
EnumTest { EnumTest {
enum_string: None, enum_string: None,
enum_string_required: enum_string_required,
enum_integer: None, enum_integer: None,
enum_number: None, enum_number: None,
outer_enum: None, outer_enum: None,