From d215a933895b08bc91027b2020d952ea1f7da929 Mon Sep 17 00:00:00 2001 From: Martin Fidczuk <31689062+MF1-MS@users.noreply.github.com> Date: Mon, 5 Nov 2018 16:12:43 +0000 Subject: [PATCH] Allow package version to be passed on CLI (Rust fix) (#1286) This MR allows package version to be specified in Rust in the generate argument list, with the argument `-DpackageVersion=`. If this argument is present then the version in the resulting Cargo.toml file will be the passed value. If this argument is not present then the version in the OpenAPI definition file will be used, as per current behavior. --- .../openapitools/codegen/languages/RustServerCodegen.java | 5 +---- .../src/main/resources/rust-server/Cargo.mustache | 2 +- .../src/test/resources/2_0/rust-server/rust-server-test.yaml | 2 +- .../petstore/rust-server/output/rust-server-test/Cargo.toml | 2 +- .../petstore/rust-server/output/rust-server-test/README.md | 4 ++-- .../rust-server/output/rust-server-test/api/openapi.yaml | 2 +- .../petstore/rust-server/output/rust-server-test/src/lib.rs | 2 +- 7 files changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java index a1980ebb8714..85ea1893656c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java @@ -177,8 +177,7 @@ public RustServerCodegen() { "Rust crate name (convention: snake_case).") .defaultValue("openapi_client")); cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, - "Rust crate version.") - .defaultValue("1.0.0")); + "Rust crate version.")); /* * Additional Properties. These values can be passed to the templates and @@ -224,8 +223,6 @@ public void processOpts() { if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) { setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION)); - } else { - setPackageVersion("1.0.0"); } additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName); diff --git a/modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache index 462ee2aab0a2..70ef6c751f9f 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache @@ -1,6 +1,6 @@ [package] name = "{{{packageName}}}" -version = "{{{appVersion}}}" +version = {{#packageVersion}}"{{{packageVersion}}}"{{/packageVersion}}{{^packageVersion}}"{{{appVersion}}}"{{/packageVersion}}{{! Fill in with packageVersion if defined, which can be passed via a command line argument, Else use appVersion from the Open API spec, which defaults to 1.0.0 if not present.}} authors = [{{#infoEmail}}"{{{infoEmail}}}"{{/infoEmail}}] {{#appDescription}} description = "{{{appDescription}}}" diff --git a/modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml b/modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml index 1aff69d888ba..85f7981b68cf 100644 --- a/modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml @@ -1,7 +1,7 @@ swagger: '2.0' info: description: "This spec is for testing rust-server-specific things" - version: 1.0.0 + version: 2.0.0 title: rust-server-test schemes: - http diff --git a/samples/server/petstore/rust-server/output/rust-server-test/Cargo.toml b/samples/server/petstore/rust-server/output/rust-server-test/Cargo.toml index 1b40c9c33c6f..5cdbcb00d644 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/Cargo.toml +++ b/samples/server/petstore/rust-server/output/rust-server-test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust-server-test" -version = "1.0.0" +version = "2.0.0" authors = [] description = "This spec is for testing rust-server-specific things" license = "Unlicense" diff --git a/samples/server/petstore/rust-server/output/rust-server-test/README.md b/samples/server/petstore/rust-server/output/rust-server-test/README.md index 5be314fa09b7..efac790e2540 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/README.md +++ b/samples/server/petstore/rust-server/output/rust-server-test/README.md @@ -12,7 +12,7 @@ To see how to make this your own, look here: [README]((https://openapi-generator.tech)) -- API version: 1.0.0 +- API version: 2.0.0 This autogenerated project defines an API crate `rust-server-test` which contains: * An `Api` trait defining the API in Rust. @@ -75,7 +75,7 @@ The server example is designed to form the basis for implementing your own serve * Set up a new Rust project, e.g., with `cargo init --bin`. * Insert `rust-server-test` into the `members` array under [workspace] in the root `Cargo.toml`, e.g., `members = [ "rust-server-test" ]`. -* Add `rust-server-test = {version = "1.0.0", path = "rust-server-test"}` under `[dependencies]` in the root `Cargo.toml`. +* Add `rust-server-test = {version = "2.0.0", path = "rust-server-test"}` under `[dependencies]` in the root `Cargo.toml`. * Copy the `[dependencies]` and `[dev-dependencies]` from `rust-server-test/Cargo.toml` into the root `Cargo.toml`'s `[dependencies]` section. * Copy all of the `[dev-dependencies]`, but only the `[dependencies]` that are required by the example server. These should be clearly indicated by comments. * Remove `"optional = true"` from each of these lines if present. diff --git a/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml b/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml index 3ad35a166ff7..0a96a7ce761b 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml @@ -2,7 +2,7 @@ openapi: 3.0.1 info: description: This spec is for testing rust-server-specific things title: rust-server-test - version: 1.0.0 + version: 2.0.0 servers: - url: / paths: diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs index aceb8e42ccc5..8cb366a2ffba 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs @@ -36,7 +36,7 @@ mod mimetypes; pub use swagger::{ApiError, ContextWrapper}; pub const BASE_PATH: &'static str = ""; -pub const API_VERSION: &'static str = "1.0.0"; +pub const API_VERSION: &'static str = "2.0.0"; #[derive(Debug, PartialEq)]