From 80a86686ce1e8ca56fb24a9229cc7c91e39c0a4f Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 19 Oct 2017 17:48:32 +0800 Subject: [PATCH 1/2] rename rust2 to rust-server --- README.md | 2 +- ...t2-petstore.sh => rust-server-petstore.sh} | 2 +- bin/windows/rust-server-petstore.bat | 10 ++ ...st2Codegen.java => RustServerCodegen.java} | 16 +-- .../services/io.swagger.codegen.CodegenConfig | 2 +- .../{rust2 => rust-server}/Cargo.mustache | 0 .../{rust2 => rust-server}/README.mustache | 0 .../{rust2 => rust-server}/cargo-config | 0 .../{rust2 => rust-server}/client.mustache | 0 .../{rust2 => rust-server}/example-ca.pem | 0 .../example-client.mustache | 0 .../example-server-chain.pem | 0 .../example-server-key.pem | 0 .../example-server.mustache | 0 .../example-server_lib.mustache | 0 .../{rust2 => rust-server}/gitignore | 0 .../{rust2 => rust-server}/lib.mustache | 0 .../{rust2 => rust-server}/mimetypes.mustache | 0 .../{rust2 => rust-server}/models.mustache | 0 .../{rust2 => rust-server}/server.mustache | 0 .../{rust2 => rust-server}/swagger.mustache | 0 .../petstore/rust-server}/.cargo/config | 0 .../petstore/rust-server}/.gitignore | 0 .../rust-server}/.swagger-codegen-ignore | 0 .../rust-server}/.swagger-codegen/VERSION | 0 .../petstore/rust-server}/Cargo.toml | 0 .../petstore/rust-server}/README.md | 3 +- .../petstore/rust-server}/api/swagger.yaml | 111 ++++++++++-------- .../petstore/rust-server}/examples/ca.pem | 0 .../petstore/rust-server}/examples/client.rs | 7 ++ .../rust-server}/examples/server-chain.pem | 0 .../rust-server}/examples/server-key.pem | 0 .../petstore/rust-server}/examples/server.rs | 0 .../rust-server}/examples/server_lib/mod.rs | 8 ++ .../petstore/rust-server}/src/client.rs | 56 ++++++++- .../petstore/rust-server}/src/lib.rs | 16 +++ .../petstore/rust-server}/src/mimetypes.rs | 4 + .../petstore/rust-server}/src/models.rs | 99 ---------------- .../petstore/rust-server}/src/server.rs | 73 +++++++++++- 39 files changed, 237 insertions(+), 172 deletions(-) rename bin/{rust2-petstore.sh => rust-server-petstore.sh} (78%) create mode 100755 bin/windows/rust-server-petstore.bat rename modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/{Rust2Codegen.java => RustServerCodegen.java} (98%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/Cargo.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/README.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/cargo-config (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/client.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/example-ca.pem (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/example-client.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/example-server-chain.pem (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/example-server-key.pem (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/example-server.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/example-server_lib.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/gitignore (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/lib.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/mimetypes.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/models.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/server.mustache (100%) rename modules/swagger-codegen/src/main/resources/{rust2 => rust-server}/swagger.mustache (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/.cargo/config (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/.gitignore (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/.swagger-codegen-ignore (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/.swagger-codegen/VERSION (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/Cargo.toml (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/README.md (96%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/api/swagger.yaml (97%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/examples/ca.pem (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/examples/client.rs (97%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/examples/server-chain.pem (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/examples/server-key.pem (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/examples/server.rs (100%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/examples/server_lib/mod.rs (96%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/src/client.rs (97%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/src/lib.rs (97%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/src/mimetypes.rs (96%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/src/models.rs (91%) rename samples/{client/petstore/rust2 => server/petstore/rust-server}/src/server.rs (97%) diff --git a/README.md b/README.md index ed4a2870fb7..8181f2eecde 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This is the swagger codegen project, which allows generation of API client libraries (SDK generation), server stubs and documentation automatically given an [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification). Currently, the following languages/frameworks are supported: - **API clients**: **ActionScript**, **Ada**, **Apex**, **Bash**, **C#** (.net 2.0, 4.0 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart**, **Elixir**, **Eiffel**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust**, **Scala** (akka, http4s, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (Angular1.x, Angular2.x, Fetch, jQuery, Node) -- **Server stubs**: **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go**, **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework), **PHP** (Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Scala** ([Finch](https://github.com/finagle/finch), Scalatra) +- **Server stubs**: **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go**, **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework), **PHP** (Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust**, **Scala** ([Finch](https://github.com/finagle/finch), Scalatra) - **API documentation generators**: **HTML**, **Confluence Wiki** - **Configuration files**: [**Apache2**](https://httpd.apache.org/) - **Others**: **JMeter** diff --git a/bin/rust2-petstore.sh b/bin/rust-server-petstore.sh similarity index 78% rename from bin/rust2-petstore.sh rename to bin/rust-server-petstore.sh index 8428f974cdd..e7e655d4812 100755 --- a/bin/rust2-petstore.sh +++ b/bin/rust-server-petstore.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="$@ generate -t modules/swagger-codegen/src/main/resources/rust2 -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l rust2 -o samples/client/petstore/rust2 -DpackageName=petstore_api" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/rust-server -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l rust-server -o samples/server/petstore/rust-server -DpackageName=petstore_api" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/windows/rust-server-petstore.bat b/bin/windows/rust-server-petstore.bat new file mode 100755 index 00000000000..2ab761e971f --- /dev/null +++ b/bin/windows/rust-server-petstore.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties +set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l rust-server -o samples\server\petstore\rust-server + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Rust2Codegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustServerCodegen.java similarity index 98% rename from modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Rust2Codegen.java rename to modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustServerCodegen.java index 76f218aa50f..301e6532038 100755 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Rust2Codegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustServerCodegen.java @@ -27,25 +27,25 @@ import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; -public class Rust2Codegen extends DefaultCodegen implements CodegenConfig { +public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { - private static final Logger LOGGER = LoggerFactory.getLogger(Rust2Codegen.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RustServerCodegen.class); private HashMap modelXmlNames = new HashMap(); protected String apiVersion = "1.0.0"; protected int serverPort = 8080; protected String projectName = "swagger-server"; - protected String apiPath = "rust2"; + protected String apiPath = "rust-server"; protected String packageName; protected String packageVersion; protected String externCrateName; - public Rust2Codegen() { + public RustServerCodegen() { super(); // set the output folder here - outputFolder = "generated-code/rust2"; + outputFolder = "generated-code/rust-server"; /* * Models. You can write model files using the modelTemplateFiles map. @@ -66,7 +66,7 @@ public Rust2Codegen() { * Template Location. This is the location which templates will be read from. The generator * will use the resource stream to attempt to read the templates. */ - embeddedTemplateDir = templateDir = "rust2"; + embeddedTemplateDir = templateDir = "rust-server"; /* * Reserved words. Override this with reserved words specific to your language @@ -232,7 +232,7 @@ public CodegenType getTag() { */ @Override public String getName() { - return "rust2"; + return "rust-server"; } /** @@ -243,7 +243,7 @@ public String getName() { */ @Override public String getHelp() { - return "Generates a Rust client/server library using the swagger-codegen project."; + return "Generates a Rust client/server library (beta) using the swagger-codegen project."; } @Override diff --git a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig index c1cd7c72641..54e82bf7350 100644 --- a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig +++ b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig @@ -55,8 +55,8 @@ io.swagger.codegen.languages.RClientCodegen io.swagger.codegen.languages.Rails5ServerCodegen io.swagger.codegen.languages.RestbedCodegen io.swagger.codegen.languages.RubyClientCodegen -io.swagger.codegen.languages.Rust2Codegen io.swagger.codegen.languages.RustClientCodegen +io.swagger.codegen.languages.RustServerCodegen io.swagger.codegen.languages.ScalaClientCodegen io.swagger.codegen.languages.ScalatraServerCodegen io.swagger.codegen.languages.ScalazClientCodegen diff --git a/modules/swagger-codegen/src/main/resources/rust2/Cargo.mustache b/modules/swagger-codegen/src/main/resources/rust-server/Cargo.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/Cargo.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/Cargo.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/README.mustache b/modules/swagger-codegen/src/main/resources/rust-server/README.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/README.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/README.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/cargo-config b/modules/swagger-codegen/src/main/resources/rust-server/cargo-config similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/cargo-config rename to modules/swagger-codegen/src/main/resources/rust-server/cargo-config diff --git a/modules/swagger-codegen/src/main/resources/rust2/client.mustache b/modules/swagger-codegen/src/main/resources/rust-server/client.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/client.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/client.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/example-ca.pem b/modules/swagger-codegen/src/main/resources/rust-server/example-ca.pem similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/example-ca.pem rename to modules/swagger-codegen/src/main/resources/rust-server/example-ca.pem diff --git a/modules/swagger-codegen/src/main/resources/rust2/example-client.mustache b/modules/swagger-codegen/src/main/resources/rust-server/example-client.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/example-client.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/example-client.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/example-server-chain.pem b/modules/swagger-codegen/src/main/resources/rust-server/example-server-chain.pem similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/example-server-chain.pem rename to modules/swagger-codegen/src/main/resources/rust-server/example-server-chain.pem diff --git a/modules/swagger-codegen/src/main/resources/rust2/example-server-key.pem b/modules/swagger-codegen/src/main/resources/rust-server/example-server-key.pem similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/example-server-key.pem rename to modules/swagger-codegen/src/main/resources/rust-server/example-server-key.pem diff --git a/modules/swagger-codegen/src/main/resources/rust2/example-server.mustache b/modules/swagger-codegen/src/main/resources/rust-server/example-server.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/example-server.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/example-server.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/example-server_lib.mustache b/modules/swagger-codegen/src/main/resources/rust-server/example-server_lib.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/example-server_lib.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/example-server_lib.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/gitignore b/modules/swagger-codegen/src/main/resources/rust-server/gitignore similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/gitignore rename to modules/swagger-codegen/src/main/resources/rust-server/gitignore diff --git a/modules/swagger-codegen/src/main/resources/rust2/lib.mustache b/modules/swagger-codegen/src/main/resources/rust-server/lib.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/lib.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/lib.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/mimetypes.mustache b/modules/swagger-codegen/src/main/resources/rust-server/mimetypes.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/mimetypes.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/mimetypes.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/models.mustache b/modules/swagger-codegen/src/main/resources/rust-server/models.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/models.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/models.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/server.mustache b/modules/swagger-codegen/src/main/resources/rust-server/server.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/server.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/server.mustache diff --git a/modules/swagger-codegen/src/main/resources/rust2/swagger.mustache b/modules/swagger-codegen/src/main/resources/rust-server/swagger.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/rust2/swagger.mustache rename to modules/swagger-codegen/src/main/resources/rust-server/swagger.mustache diff --git a/samples/client/petstore/rust2/.cargo/config b/samples/server/petstore/rust-server/.cargo/config similarity index 100% rename from samples/client/petstore/rust2/.cargo/config rename to samples/server/petstore/rust-server/.cargo/config diff --git a/samples/client/petstore/rust2/.gitignore b/samples/server/petstore/rust-server/.gitignore similarity index 100% rename from samples/client/petstore/rust2/.gitignore rename to samples/server/petstore/rust-server/.gitignore diff --git a/samples/client/petstore/rust2/.swagger-codegen-ignore b/samples/server/petstore/rust-server/.swagger-codegen-ignore similarity index 100% rename from samples/client/petstore/rust2/.swagger-codegen-ignore rename to samples/server/petstore/rust-server/.swagger-codegen-ignore diff --git a/samples/client/petstore/rust2/.swagger-codegen/VERSION b/samples/server/petstore/rust-server/.swagger-codegen/VERSION similarity index 100% rename from samples/client/petstore/rust2/.swagger-codegen/VERSION rename to samples/server/petstore/rust-server/.swagger-codegen/VERSION diff --git a/samples/client/petstore/rust2/Cargo.toml b/samples/server/petstore/rust-server/Cargo.toml similarity index 100% rename from samples/client/petstore/rust2/Cargo.toml rename to samples/server/petstore/rust-server/Cargo.toml diff --git a/samples/client/petstore/rust2/README.md b/samples/server/petstore/rust-server/README.md similarity index 96% rename from samples/client/petstore/rust2/README.md rename to samples/server/petstore/rust-server/README.md index 1e98c25281c..987a3df7c98 100644 --- a/samples/client/petstore/rust2/README.md +++ b/samples/server/petstore/rust-server/README.md @@ -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) - API version: 1.0.0 -- Build date: 2017-09-26T16:36:55.563+01:00 +- Build date: 2017-10-19T17:45:37.995+08:00 ## Examples @@ -50,6 +50,7 @@ cargo run --example client FakeOuterStringSerialize cargo run --example client TestClientModel cargo run --example client TestEndpointParameters cargo run --example client TestEnumParameters +cargo run --example client TestInlineAdditionalProperties cargo run --example client TestJsonFormData cargo run --example client TestClassname cargo run --example client AddPet diff --git a/samples/client/petstore/rust2/api/swagger.yaml b/samples/server/petstore/rust-server/api/swagger.yaml similarity index 97% rename from samples/client/petstore/rust2/api/swagger.yaml rename to samples/server/petstore/rust-server/api/swagger.yaml index 1dc845be640..3d1431f92e2 100644 --- a/samples/client/petstore/rust2/api/swagger.yaml +++ b/samples/server/petstore/rust-server/api/swagger.yaml @@ -10,7 +10,7 @@ info: contact: email: "apiteam@swagger.io" license: - name: "Apache 2.0" + name: "Apache-2.0" url: "http://www.apache.org/licenses/LICENSE-2.0.html" host: "petstore.swagger.io:80" basePath: "/v2" @@ -54,7 +54,7 @@ paths: refName: "Pet" formatString: "{:?}" example: "???" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "ADD_PET" consumesXml: true responses: @@ -95,7 +95,7 @@ paths: refName: "Pet" formatString: "{:?}" example: "???" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "UPDATE_PET" consumesXml: true responses: @@ -450,7 +450,7 @@ paths: refName: "Order" formatString: "{:?}" example: "???" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "PLACE_ORDER" responses: 200: @@ -568,7 +568,7 @@ paths: refName: "User" formatString: "{:?}" example: "???" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "CREATE_USER" responses: default: @@ -602,7 +602,7 @@ paths: $ref: "#/definitions/User" formatString: "{:?}" example: "&Vec::new()" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "CREATE_USERS_WITH_ARRAY_INPUT" responses: default: @@ -635,7 +635,7 @@ paths: $ref: "#/definitions/User" formatString: "{:?}" example: "&Vec::new()" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "CREATE_USERS_WITH_LIST_INPUT" responses: default: @@ -787,7 +787,7 @@ paths: refName: "User" formatString: "{:?}" example: "???" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "UPDATE_USER" responses: 400: @@ -856,7 +856,7 @@ paths: refName: "Client" formatString: "{:?}" example: "???" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "TEST_CLASSNAME" responses: 200: @@ -1169,7 +1169,7 @@ paths: refName: "Client" formatString: "{:?}" example: "???" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "TEST_CLIENT_MODEL" responses: 200: @@ -1202,7 +1202,7 @@ paths: refName: "OuterNumber" formatString: "{:?}" example: "None" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "FAKE_OUTER_NUMBER_SERIALIZE" responses: 200: @@ -1234,7 +1234,7 @@ paths: refName: "OuterString" formatString: "{:?}" example: "None" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "FAKE_OUTER_STRING_SERIALIZE" responses: 200: @@ -1266,7 +1266,7 @@ paths: refName: "OuterBoolean" formatString: "{:?}" example: "None" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "FAKE_OUTER_BOOLEAN_SERIALIZE" responses: 200: @@ -1298,7 +1298,7 @@ paths: refName: "OuterComposite" formatString: "{:?}" example: "None" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "FAKE_OUTER_COMPOSITE_SERIALIZE" responses: 200: @@ -1365,7 +1365,6 @@ paths: uppercase_message: "SUCCESS" uppercase_data_type: "XMLOBJECT" producesXml: true - has_namespace: "true" operation_id: "get_xml_features" uppercase_operation_id: "GET_XML_FEATURES" path: "/fake/xmlFeatures" @@ -1388,8 +1387,7 @@ paths: refName: "xmlObject" formatString: "{:?}" example: "???" - has_namespace: "true" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "POST_XML_FEATURES" consumesXml: true responses: @@ -1403,6 +1401,41 @@ paths: HttpMethod: "Post" httpmethod: "post" noClientExample: true + /fake/inline-additionalProperties: + post: + tags: + - "fake" + summary: "test inline additionalProperties" + description: "" + operationId: "testInlineAdditionalProperties" + consumes: + - "application/json" + parameters: + - in: "body" + name: "param" + description: "request body" + required: true + schema: + type: "object" + additionalProperties: + type: "string" + upperCaseName: "PARAM" + refName: null + formatString: "{:?}" + example: "???" + model_key: "OuterBoolean" + uppercase_operation_id: "TEST_INLINE_ADDITIONAL_PROPERTIES" + responses: + 200: + description: "successful operation" + uppercase_operation_id: "TEST_INLINE_ADDITIONAL_PROPERTIES" + uppercase_message: "SUCCESSFUL_OPERATION" + operation_id: "test_inline_additional_properties" + uppercase_operation_id: "TEST_INLINE_ADDITIONAL_PROPERTIES" + path: "/fake/inline-additionalProperties" + HttpMethod: "Post" + httpmethod: "post" + noClientExample: true /another-fake/dummy: patch: tags: @@ -1425,7 +1458,7 @@ paths: refName: "Client" formatString: "{:?}" example: "???" - model_key: "itemList" + model_key: "OuterBoolean" uppercase_operation_id: "TEST_SPECIAL_TAGS" responses: 200: @@ -1968,15 +2001,6 @@ definitions: - "approved" - "delivered" upperCaseName: "OUTERENUM" - OuterNumber: - type: "number" - upperCaseName: "OUTERNUMBER" - OuterString: - type: "string" - upperCaseName: "OUTERSTRING" - OuterBoolean: - type: "boolean" - upperCaseName: "OUTERBOOLEAN" OuterComposite: type: "object" properties: @@ -1991,30 +2015,15 @@ definitions: my_number: {} my_boolean: {} upperCaseName: "OUTERCOMPOSITE" - xmlObject: - required: - - "itemList" - - "name" - properties: - name: - type: "string" - example: "myXmlObject" - itemList: - $ref: "#/definitions/itemList" - itemXmlName: "item" - xml: - name: "group" - namespace: "http://example.com/schema.xsd" - upperCaseName: "XMLOBJECT" - itemList: - type: "array" - items: - type: "string" - example: "my item" - xml: - name: "item" - upperCaseName: "ITEMLIST" - itemXmlName: "item" + OuterNumber: + type: "number" + upperCaseName: "OUTERNUMBER" + OuterString: + type: "string" + upperCaseName: "OUTERSTRING" + OuterBoolean: + type: "boolean" + upperCaseName: "OUTERBOOLEAN" externalDocs: description: "Find out more about Swagger" url: "http://swagger.io" diff --git a/samples/client/petstore/rust2/examples/ca.pem b/samples/server/petstore/rust-server/examples/ca.pem similarity index 100% rename from samples/client/petstore/rust2/examples/ca.pem rename to samples/server/petstore/rust-server/examples/ca.pem diff --git a/samples/client/petstore/rust2/examples/client.rs b/samples/server/petstore/rust-server/examples/client.rs similarity index 97% rename from samples/client/petstore/rust2/examples/client.rs rename to samples/server/petstore/rust-server/examples/client.rs index 6fd88afc5b6..28ec7fa7268 100644 --- a/samples/client/petstore/rust2/examples/client.rs +++ b/samples/server/petstore/rust-server/examples/client.rs @@ -24,6 +24,7 @@ use petstore_api::{ApiNoContext, ContextWrapperExt, TestClientModelResponse, TestEndpointParametersResponse, TestEnumParametersResponse, + TestInlineAdditionalPropertiesResponse, TestJsonFormDataResponse, TestClassnameResponse, AddPetResponse, @@ -151,6 +152,12 @@ fn main() { println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); }, + // Disabled because there's no example. + // Some("TestInlineAdditionalProperties") => { + // let result = client.test_inline_additional_properties(???).wait(); + // println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); + // }, + Some("TestJsonFormData") => { let result = client.test_json_form_data("param_example".to_string(), "param2_example".to_string()).wait(); println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); diff --git a/samples/client/petstore/rust2/examples/server-chain.pem b/samples/server/petstore/rust-server/examples/server-chain.pem similarity index 100% rename from samples/client/petstore/rust2/examples/server-chain.pem rename to samples/server/petstore/rust-server/examples/server-chain.pem diff --git a/samples/client/petstore/rust2/examples/server-key.pem b/samples/server/petstore/rust-server/examples/server-key.pem similarity index 100% rename from samples/client/petstore/rust2/examples/server-key.pem rename to samples/server/petstore/rust-server/examples/server-key.pem diff --git a/samples/client/petstore/rust2/examples/server.rs b/samples/server/petstore/rust-server/examples/server.rs similarity index 100% rename from samples/client/petstore/rust2/examples/server.rs rename to samples/server/petstore/rust-server/examples/server.rs diff --git a/samples/client/petstore/rust2/examples/server_lib/mod.rs b/samples/server/petstore/rust-server/examples/server_lib/mod.rs similarity index 96% rename from samples/client/petstore/rust2/examples/server_lib/mod.rs rename to samples/server/petstore/rust-server/examples/server_lib/mod.rs index 598d4a0e946..ad6fed845a9 100644 --- a/samples/client/petstore/rust2/examples/server_lib/mod.rs +++ b/samples/server/petstore/rust-server/examples/server_lib/mod.rs @@ -20,6 +20,7 @@ use petstore_api::{Api, ApiError, Context, TestClientModelResponse, TestEndpointParametersResponse, TestEnumParametersResponse, + TestInlineAdditionalPropertiesResponse, TestJsonFormDataResponse, TestClassnameResponse, AddPetResponse, @@ -121,6 +122,13 @@ impl Api for Server { Box::new(futures::failed("Generic failure".into())) } + /// test inline additionalProperties + fn test_inline_additional_properties(&self, param: object, context: &Context) -> Box + Send> { + let context = context.clone(); + println!("test_inline_additional_properties({:?}) - X-Span-ID: {:?}", param, context.x_span_id.unwrap_or(String::from("")).clone()); + Box::new(futures::failed("Generic failure".into())) + } + /// test json serialization of form data fn test_json_form_data(&self, param: String, param2: String, context: &Context) -> Box + Send> { let context = context.clone(); diff --git a/samples/client/petstore/rust2/src/client.rs b/samples/server/petstore/rust-server/src/client.rs similarity index 97% rename from samples/client/petstore/rust2/src/client.rs rename to samples/server/petstore/rust-server/src/client.rs index b5a5e27bf6b..d98fe03ca2c 100644 --- a/samples/client/petstore/rust2/src/client.rs +++ b/samples/server/petstore/rust-server/src/client.rs @@ -45,6 +45,7 @@ use {Api, TestClientModelResponse, TestEndpointParametersResponse, TestEnumParametersResponse, + TestInlineAdditionalPropertiesResponse, TestJsonFormDataResponse, TestClassnameResponse, AddPetResponse, @@ -307,11 +308,7 @@ impl Api for Client { let url = format!("{}/v2/fake/xmlFeatures?", self.base_path); - - let mut namespaces = BTreeMap::new(); - // An empty string is used to indicate a global namespace in xmltree. - namespaces.insert("".to_string(), models::namespaces::XMLOBJECT.clone()); - let body = serde_xml_rs::to_string_with_namespaces(¶m_xml_object, namespaces).expect("impossible to fail to serialize"); + let body = serde_xml_rs::to_string(¶m_xml_object).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -744,6 +741,55 @@ impl Api for Client { Box::new(futures::done(result)) } + fn test_inline_additional_properties(&self, param_param: object, context: &Context) -> Box + Send> { + + + let url = format!("{}/v2/fake/inline-additionalProperties?", self.base_path); + + + let body = serde_json::to_string(¶m_param).expect("impossible to fail to serialize"); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Post, &url); + let mut custom_headers = hyper::header::Headers::new(); + + let request = request.body(&body); + + custom_headers.set(ContentType(mimetypes::requests::TEST_INLINE_ADDITIONAL_PROPERTIES.clone())); + context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); + + + let request = request.headers(custom_headers); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn parse_response(mut response: hyper::client::response::Response) -> Result { + match response.status.to_u16() { + 200 => { + + + Ok(TestInlineAdditionalPropertiesResponse::SuccessfulOperation) + }, + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", + code, + response.headers, + debug_body))) + } + } + } + + let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + Box::new(futures::done(result)) + } + fn test_json_form_data(&self, param_param: String, param_param2: String, context: &Context) -> Box + Send> { diff --git a/samples/client/petstore/rust2/src/lib.rs b/samples/server/petstore/rust-server/src/lib.rs similarity index 97% rename from samples/client/petstore/rust2/src/lib.rs rename to samples/server/petstore/rust-server/src/lib.rs index a923266374c..f5a047e710b 100644 --- a/samples/client/petstore/rust2/src/lib.rs +++ b/samples/server/petstore/rust-server/src/lib.rs @@ -85,6 +85,11 @@ pub enum TestEnumParametersResponse { NotFound , } +#[derive(Debug, PartialEq)] +pub enum TestInlineAdditionalPropertiesResponse { + SuccessfulOperation , +} + #[derive(Debug, PartialEq)] pub enum TestJsonFormDataResponse { SuccessfulOperation , @@ -244,6 +249,9 @@ pub trait Api { /// To test enum parameters fn test_enum_parameters(&self, enum_form_string_array: Option<&Vec>, enum_form_string: Option, enum_header_string_array: Option<&Vec>, enum_header_string: Option, enum_query_string_array: Option<&Vec>, enum_query_string: Option, enum_query_integer: Option, enum_query_double: Option, context: &Context) -> Box + Send>; + /// test inline additionalProperties + fn test_inline_additional_properties(&self, param: object, context: &Context) -> Box + Send>; + /// test json serialization of form data fn test_json_form_data(&self, param: String, param2: String, context: &Context) -> Box + Send>; @@ -345,6 +353,9 @@ pub trait ApiNoContext { /// To test enum parameters fn test_enum_parameters(&self, enum_form_string_array: Option<&Vec>, enum_form_string: Option, enum_header_string_array: Option<&Vec>, enum_header_string: Option, enum_query_string_array: Option<&Vec>, enum_query_string: Option, enum_query_integer: Option, enum_query_double: Option) -> Box + Send>; + /// test inline additionalProperties + fn test_inline_additional_properties(&self, param: object) -> Box + Send>; + /// test json serialization of form data fn test_json_form_data(&self, param: String, param2: String) -> Box + Send>; @@ -477,6 +488,11 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().test_enum_parameters(enum_form_string_array, enum_form_string, enum_header_string_array, enum_header_string, enum_query_string_array, enum_query_string, enum_query_integer, enum_query_double, &self.context()) } + /// test inline additionalProperties + fn test_inline_additional_properties(&self, param: object) -> Box + Send> { + self.api().test_inline_additional_properties(param, &self.context()) + } + /// test json serialization of form data fn test_json_form_data(&self, param: String, param2: String) -> Box + Send> { self.api().test_json_form_data(param, param2, &self.context()) diff --git a/samples/client/petstore/rust2/src/mimetypes.rs b/samples/server/petstore/rust-server/src/mimetypes.rs similarity index 96% rename from samples/client/petstore/rust2/src/mimetypes.rs rename to samples/server/petstore/rust-server/src/mimetypes.rs index 1f9be4ef9c5..11bcff7abd1 100644 --- a/samples/client/petstore/rust2/src/mimetypes.rs +++ b/samples/server/petstore/rust-server/src/mimetypes.rs @@ -89,6 +89,10 @@ pub mod requests { lazy_static! { pub static ref TEST_CLIENT_MODEL: Mime = mime!(Application/Json); } + /// Create Mime objects for the request content types for TestInlineAdditionalProperties + lazy_static! { + pub static ref TEST_INLINE_ADDITIONAL_PROPERTIES: Mime = mime!(Application/Json); + } /// Create Mime objects for the request content types for TestClassname lazy_static! { pub static ref TEST_CLASSNAME: Mime = mime!(Application/Json); diff --git a/samples/client/petstore/rust2/src/models.rs b/samples/server/petstore/rust-server/src/models.rs similarity index 91% rename from samples/client/petstore/rust2/src/models.rs rename to samples/server/petstore/rust-server/src/models.rs index 8b5a3251c8b..e956aae2bb9 100644 --- a/samples/client/petstore/rust2/src/models.rs +++ b/samples/server/petstore/rust-server/src/models.rs @@ -481,76 +481,6 @@ impl HasOnlyReadOnly { } } -// Utility function for wrapping list elements when serializing xml -fn wrap_in_item(item: &Vec, serializer: S) -> Result -where - S: Serializer, -{ - serde_xml_rs::wrap_primitives(item, serializer, "item") -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct ItemList(Vec); - -impl ::std::convert::From> for ItemList { - fn from(x: Vec) -> Self { - ItemList(x) - } -} - -impl ::std::convert::From for Vec { - fn from(x: ItemList) -> Self { - x.0 - } -} - -impl ::std::iter::FromIterator for ItemList { - fn from_iter>(u: U) -> Self { - ItemList(Vec::::from_iter(u)) - } -} - -impl ::std::iter::IntoIterator for ItemList { - type Item = String; - type IntoIter = ::std::vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl<'a> ::std::iter::IntoIterator for &'a ItemList { - type Item = &'a String; - type IntoIter = ::std::slice::Iter<'a, String>; - - fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() - } -} - -impl<'a> ::std::iter::IntoIterator for &'a mut ItemList { - type Item = &'a mut String; - type IntoIter = ::std::slice::IterMut<'a, String>; - - fn into_iter(self) -> Self::IntoIter { - (&mut self.0).into_iter() - } -} - -impl ::std::ops::Deref for ItemList { - type Target = Vec; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl ::std::ops::DerefMut for ItemList { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct List { #[serde(rename = "123-list")] @@ -1056,27 +986,6 @@ impl User { } } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(rename = "group")] -pub struct XmlObject { - #[serde(rename = "name")] - pub name: String, - - #[serde(rename = "itemList")] - #[serde(serialize_with = "wrap_in_item")] - pub item_list: models::ItemList, - -} - -impl XmlObject { - pub fn new(name: String, item_list: models::ItemList, ) -> XmlObject { - XmlObject { - name: name, - item_list: item_list, - } - } -} - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Cat { #[serde(rename = "className")] @@ -1126,11 +1035,3 @@ impl Dog { } } } - -//XML namespaces -pub mod namespaces { - lazy_static!{ - pub static ref XMLOBJECT: String = "http://example.com/schema.xsd".to_string(); - - } -} diff --git a/samples/client/petstore/rust2/src/server.rs b/samples/server/petstore/rust-server/src/server.rs similarity index 97% rename from samples/client/petstore/rust2/src/server.rs rename to samples/server/petstore/rust-server/src/server.rs index a8d32981940..22e52fe4706 100644 --- a/samples/client/petstore/rust2/src/server.rs +++ b/samples/server/petstore/rust-server/src/server.rs @@ -47,6 +47,7 @@ use {Api, TestClientModelResponse, TestEndpointParametersResponse, TestEnumParametersResponse, + TestInlineAdditionalPropertiesResponse, TestJsonFormDataResponse, TestClassnameResponse, AddPetResponse, @@ -200,11 +201,7 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone Ok(rsp) => match rsp { GetXmlFeaturesResponse::Success(body) => { - - let mut namespaces = BTreeMap::new(); - // An empty string is used to indicate a global namespace in xmltree. - namespaces.insert("".to_string(), models::namespaces::XMLOBJECT.clone()); - let body_string = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); + let body_string = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(200), body_string)); response.headers.set(ContentType(mimetypes::responses::GET_XML_FEATURES_SUCCESS.clone())); @@ -781,6 +778,72 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone }, "TestEnumParameters"); + let api_clone = api.clone(); + router.post( + "/v2/fake/inline-additionalProperties", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { + + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + + + + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_param_raw = req.get::().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter param - not valid UTF-8: {}", e))))?; + let mut unused_elements = Vec::new(); + + let param_param = if let Some(param_param_raw) = param_param_raw { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_param_raw); + + let param_param: Option = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter param - doesn't match schema: {}", e))))?; + + param_param + } else { + None + }; + let param_param = param_param.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter param".to_string())))?; + + + match api.test_inline_additional_properties(param_param, context).wait() { + Ok(rsp) => match rsp { + TestInlineAdditionalPropertiesResponse::SuccessfulOperation => { + + + let mut response = Response::with((status::Status::from_u16(200))); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } + Ok(response) + }, + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + } + } + } + + handle_request(req, &api_clone, &mut context).or_else(|mut response| { + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + Ok(response) + }) + }, + "TestInlineAdditionalProperties"); + let api_clone = api.clone(); router.get( "/v2/fake/jsonFormData", From 737210f9993cb720173dd9fc78e423f064af2f1f Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 19 Oct 2017 18:14:47 +0800 Subject: [PATCH 2/2] update rust-server batch file to use petstore test spec --- bin/windows/rust-server-petstore.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/windows/rust-server-petstore.bat b/bin/windows/rust-server-petstore.bat index 2ab761e971f..ff565aa1e04 100755 --- a/bin/windows/rust-server-petstore.bat +++ b/bin/windows/rust-server-petstore.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties -set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l rust-server -o samples\server\petstore\rust-server +set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l rust-server -o samples\server\petstore\rust-server java %JAVA_OPTS% -jar %executable% %ags%