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=<package_version>`. 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.
This commit is contained in:
Martin Fidczuk
2018-11-05 16:12:43 +00:00
committed by Benjamin Gill
parent c95b1f4545
commit 303b469fae
7 changed files with 8 additions and 11 deletions

View File

@@ -177,8 +177,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
"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 class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
} else {
setPackageVersion("1.0.0");
}
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);

View File

@@ -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}}}"

View File

@@ -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

View File

@@ -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"

View File

@@ -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.

View File

@@ -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:

View File

@@ -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)]