Skip to content

Commit

Permalink
Allow package version to be passed on CLI (Rust fix) (OpenAPITools#1286)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MF1-MS authored and bjgill committed Nov 5, 2018
1 parent 9720623 commit d215a93
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}}"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit d215a93

Please sign in to comment.