mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 10:35:25 +00:00
[rust-server] add support for multiple samples (#658)
* Add support for multiple rust-server samples Though we only have the one as yet. This will make it easier to move rust-server back on to the main test spec, whilst preserving the ability to have rust-specific test specs. * Rust samples need unique names * Move samples to a dedicated directory So that there is nothing else in the folder where they live so that the workspace definition in the root Cargo.toml can be simple.
This commit is contained in:
parent
01dbb8b693
commit
cb9a734ebb
@ -25,8 +25,10 @@ then
|
||||
mvn -B clean package
|
||||
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/openapi-generator/src/main/resources/rust-server -i modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml -g rust-server -o samples/server/petstore/rust-server -DpackageName=petstore_api --additional-properties hideGenerationTimestamp=true $@"
|
||||
for spec_path in modules/openapi-generator/src/test/resources/2_0/rust-server/* ; do
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
spec=$(basename "$spec_path" | sed 's/.yaml//')
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/rust-server -i $spec_path -g rust-server -o samples/server/petstore/rust-server/output/$spec -DpackageName=$spec --additional-properties hideGenerationTimestamp=true $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
done
|
||||
|
@ -1,48 +1,2 @@
|
||||
[package]
|
||||
name = "petstore_api"
|
||||
version = "1.0.0"
|
||||
authors = []
|
||||
description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
|
||||
license = "Unlicense"
|
||||
|
||||
[features]
|
||||
default = ["client", "server"]
|
||||
client = ["serde_json", "serde_urlencoded", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "url", "uuid"]
|
||||
server = ["serde_json", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "tokio-proto", "tokio-tls", "regex", "percent-encoding", "url", "uuid"]
|
||||
|
||||
[dependencies]
|
||||
# Required by example server.
|
||||
#
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
futures = "0.1"
|
||||
hyper = {version = "0.11", optional = true}
|
||||
hyper-tls = {version = "0.1.2", optional = true}
|
||||
swagger = "1.0.1"
|
||||
|
||||
# Not required by example server.
|
||||
#
|
||||
lazy_static = "0.2"
|
||||
log = "0.3.0"
|
||||
mime = "0.3.3"
|
||||
multipart = {version = "0.13.3", optional = true}
|
||||
native-tls = {version = "0.1.4", optional = true}
|
||||
openssl = {version = "0.9.14", optional = true}
|
||||
percent-encoding = {version = "1.0.0", optional = true}
|
||||
regex = {version = "0.2", optional = true}
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_ignored = {version = "0.0.4", optional = true}
|
||||
serde_json = {version = "1.0", optional = true}
|
||||
serde_urlencoded = {version = "0.5.1", optional = true}
|
||||
tokio-core = {version = "0.1.6", optional = true}
|
||||
tokio-proto = {version = "0.1.1", optional = true}
|
||||
tokio-tls = {version = "0.1.3", optional = true, features = ["tokio-proto"]}
|
||||
url = {version = "1.5", optional = true}
|
||||
uuid = {version = "0.5", optional = true, features = ["serde", "v4"]}
|
||||
# ToDo: this should be updated to point at the official crate once
|
||||
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
serde-xml-rs = {git = "git://github.com/Metaswitch/serde-xml-rs.git" , branch = "master", optional = true}
|
||||
|
||||
[dev-dependencies]
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
||||
[workspace]
|
||||
members = ["output/*"]
|
||||
|
@ -0,0 +1,2 @@
|
||||
target
|
||||
Cargo.lock
|
@ -0,0 +1,48 @@
|
||||
[package]
|
||||
name = "petstore-with-fake-endpoints-models-for-testing"
|
||||
version = "1.0.0"
|
||||
authors = []
|
||||
description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
|
||||
license = "Unlicense"
|
||||
|
||||
[features]
|
||||
default = ["client", "server"]
|
||||
client = ["serde_json", "serde_urlencoded", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "url", "uuid"]
|
||||
server = ["serde_json", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "tokio-proto", "tokio-tls", "regex", "percent-encoding", "url", "uuid"]
|
||||
|
||||
[dependencies]
|
||||
# Required by example server.
|
||||
#
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
futures = "0.1"
|
||||
hyper = {version = "0.11", optional = true}
|
||||
hyper-tls = {version = "0.1.2", optional = true}
|
||||
swagger = "1.0.1"
|
||||
|
||||
# Not required by example server.
|
||||
#
|
||||
lazy_static = "0.2"
|
||||
log = "0.3.0"
|
||||
mime = "0.3.3"
|
||||
multipart = {version = "0.13.3", optional = true}
|
||||
native-tls = {version = "0.1.4", optional = true}
|
||||
openssl = {version = "0.9.14", optional = true}
|
||||
percent-encoding = {version = "1.0.0", optional = true}
|
||||
regex = {version = "0.2", optional = true}
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_ignored = {version = "0.0.4", optional = true}
|
||||
serde_json = {version = "1.0", optional = true}
|
||||
serde_urlencoded = {version = "0.5.1", optional = true}
|
||||
tokio-core = {version = "0.1.6", optional = true}
|
||||
tokio-proto = {version = "0.1.1", optional = true}
|
||||
tokio-tls = {version = "0.1.3", optional = true, features = ["tokio-proto"]}
|
||||
url = {version = "1.5", optional = true}
|
||||
uuid = {version = "0.5", optional = true, features = ["serde", "v4"]}
|
||||
# ToDo: this should be updated to point at the official crate once
|
||||
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
serde-xml-rs = {git = "git://github.com/Metaswitch/serde-xml-rs.git" , branch = "master", optional = true}
|
||||
|
||||
[dev-dependencies]
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
@ -1,4 +1,4 @@
|
||||
# Rust API for petstore_api
|
||||
# Rust API for petstore-with-fake-endpoints-models-for-testing
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
@ -14,17 +14,17 @@ To see how to make this your own, look here:
|
||||
|
||||
- API version: 1.0.0
|
||||
|
||||
This autogenerated project defines an API crate `petstore_api` which contains:
|
||||
This autogenerated project defines an API crate `petstore-with-fake-endpoints-models-for-testing` which contains:
|
||||
* An `Api` trait defining the API in Rust.
|
||||
* Data types representing the underlying data model.
|
||||
* A `Client` type which implements `Api` and issues HTTP requests for each operation.
|
||||
* A router which accepts HTTP requests and invokes the appropriate `Api` method for each operation.
|
||||
|
||||
It also contains an example server and client which make use of `petstore_api`:
|
||||
* The example server starts up a web server using the `petstore_api` router,
|
||||
It also contains an example server and client which make use of `petstore-with-fake-endpoints-models-for-testing`:
|
||||
* The example server starts up a web server using the `petstore-with-fake-endpoints-models-for-testing` router,
|
||||
and supplies a trivial implementation of `Api` which returns failure for every operation.
|
||||
* The example client provides a CLI which lets you invoke any single operation on the
|
||||
`petstore_api` client by passing appropriate arguments on the command line.
|
||||
`petstore-with-fake-endpoints-models-for-testing` client by passing appropriate arguments on the command line.
|
||||
|
||||
You can use the example server and client as a basis for your own code.
|
||||
See below for [more detail on implementing a server](#writing-a-server).
|
||||
@ -105,17 +105,17 @@ This will use the keys/certificates from the examples directory. Note that the s
|
||||
The server example is designed to form the basis for implementing your own server. Simply follow these steps.
|
||||
|
||||
* Set up a new Rust project, e.g., with `cargo init --bin`.
|
||||
* Insert `petstore_api` into the `members` array under [workspace] in the root `Cargo.toml`, e.g., `members = [ "petstore_api" ]`.
|
||||
* Add `petstore_api = {version = "1.0.0", path = "petstore_api"}` under `[dependencies]` in the root `Cargo.toml`.
|
||||
* Copy the `[dependencies]` and `[dev-dependencies]` from `petstore_api/Cargo.toml` into the root `Cargo.toml`'s `[dependencies]` section.
|
||||
* Insert `petstore-with-fake-endpoints-models-for-testing` into the `members` array under [workspace] in the root `Cargo.toml`, e.g., `members = [ "petstore-with-fake-endpoints-models-for-testing" ]`.
|
||||
* Add `petstore-with-fake-endpoints-models-for-testing = {version = "1.0.0", path = "petstore-with-fake-endpoints-models-for-testing"}` under `[dependencies]` in the root `Cargo.toml`.
|
||||
* Copy the `[dependencies]` and `[dev-dependencies]` from `petstore-with-fake-endpoints-models-for-testing/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.
|
||||
|
||||
Each autogenerated API will contain an implementation stub and main entry point, which should be copied into your project the first time:
|
||||
```
|
||||
cp petstore_api/examples/server.rs src/main.rs
|
||||
cp petstore_api/examples/server_lib/mod.rs src/lib.rs
|
||||
cp petstore_api/examples/server_lib/server.rs src/server.rs
|
||||
cp petstore-with-fake-endpoints-models-for-testing/examples/server.rs src/main.rs
|
||||
cp petstore-with-fake-endpoints-models-for-testing/examples/server_lib/mod.rs src/lib.rs
|
||||
cp petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs src/server.rs
|
||||
```
|
||||
|
||||
Now
|
@ -1,6 +1,6 @@
|
||||
#![allow(missing_docs, unused_variables, trivial_casts)]
|
||||
|
||||
extern crate petstore_api;
|
||||
extern crate petstore_with_fake_endpoints_models_for_testing;
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate futures;
|
||||
#[allow(unused_extern_crates)]
|
||||
@ -17,7 +17,7 @@ use swagger::{ContextBuilder, EmptyContext, XSpanIdString, Has, Push, AuthData};
|
||||
use futures::{Future, future, Stream, stream};
|
||||
use tokio_core::reactor;
|
||||
#[allow(unused_imports)]
|
||||
use petstore_api::{ApiNoContext, ContextWrapperExt,
|
||||
use petstore_with_fake_endpoints_models_for_testing::{ApiNoContext, ContextWrapperExt,
|
||||
ApiError,
|
||||
TestSpecialTagsResponse,
|
||||
FakeOuterBooleanSerializeResponse,
|
||||
@ -107,11 +107,11 @@ fn main() {
|
||||
matches.value_of("port").unwrap());
|
||||
let client = if matches.is_present("https") {
|
||||
// Using Simple HTTPS
|
||||
petstore_api::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem")
|
||||
petstore_with_fake_endpoints_models_for_testing::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem")
|
||||
.expect("Failed to create HTTPS client")
|
||||
} else {
|
||||
// Using HTTP
|
||||
petstore_api::Client::try_new_http(core.handle(), &base_url)
|
||||
petstore_with_fake_endpoints_models_for_testing::Client::try_new_http(core.handle(), &base_url)
|
||||
.expect("Failed to create HTTP client")
|
||||
};
|
||||
|
@ -1,10 +1,10 @@
|
||||
//! Main binary entry point for petstore_api implementation.
|
||||
//! Main binary entry point for petstore_with_fake_endpoints_models_for_testing implementation.
|
||||
|
||||
#![allow(missing_docs)]
|
||||
|
||||
// Imports required by this file.
|
||||
// extern crate <name of this crate>;
|
||||
extern crate petstore_api;
|
||||
extern crate petstore_with_fake_endpoints_models_for_testing;
|
||||
extern crate swagger;
|
||||
extern crate hyper;
|
||||
extern crate openssl;
|
||||
@ -14,7 +14,7 @@ extern crate tokio_tls;
|
||||
extern crate clap;
|
||||
|
||||
// Imports required by server library.
|
||||
// extern crate petstore_api;
|
||||
// extern crate petstore_with_fake_endpoints_models_for_testing;
|
||||
// extern crate swagger;
|
||||
extern crate futures;
|
||||
extern crate chrono;
|
||||
@ -55,7 +55,7 @@ fn main() {
|
||||
.get_matches();
|
||||
|
||||
let service_fn =
|
||||
petstore_api::server::context::NewAddContext::<_, EmptyContext>::new(
|
||||
petstore_with_fake_endpoints_models_for_testing::server::context::NewAddContext::<_, EmptyContext>::new(
|
||||
AllowAllAuthenticator::new(
|
||||
server_lib::NewService::new(),
|
||||
"cosmo"
|
@ -1,4 +1,4 @@
|
||||
//! Main library entry point for petstore_api implementation.
|
||||
//! Main library entry point for petstore_with_fake_endpoints_models_for_testing implementation.
|
||||
|
||||
mod server;
|
||||
|
||||
@ -11,7 +11,7 @@ use std::io;
|
||||
use std::clone::Clone;
|
||||
use std::marker::PhantomData;
|
||||
use hyper;
|
||||
use petstore_api;
|
||||
use petstore_with_fake_endpoints_models_for_testing;
|
||||
use swagger::{Has, XSpanIdString};
|
||||
use swagger::auth::Authorization;
|
||||
|
||||
@ -29,10 +29,10 @@ impl<C> hyper::server::NewService for NewService<C> where C: Has<XSpanIdString>
|
||||
type Request = (hyper::Request, C);
|
||||
type Response = hyper::Response;
|
||||
type Error = hyper::Error;
|
||||
type Instance = petstore_api::server::Service<server::Server<C>, C>;
|
||||
type Instance = petstore_with_fake_endpoints_models_for_testing::server::Service<server::Server<C>, C>;
|
||||
|
||||
/// Instantiate a new server.
|
||||
fn new_service(&self) -> io::Result<Self::Instance> {
|
||||
Ok(petstore_api::server::Service::new(server::Server::new()))
|
||||
Ok(petstore_with_fake_endpoints_models_for_testing::server::Service::new(server::Server::new()))
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
//! Server implementation of petstore_api.
|
||||
//! Server implementation of petstore_with_fake_endpoints_models_for_testing.
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
@ -10,7 +10,7 @@ use std::marker::PhantomData;
|
||||
use swagger;
|
||||
use swagger::{Has, XSpanIdString};
|
||||
|
||||
use petstore_api::{Api, ApiError,
|
||||
use petstore_with_fake_endpoints_models_for_testing::{Api, ApiError,
|
||||
TestSpecialTagsResponse,
|
||||
FakeOuterBooleanSerializeResponse,
|
||||
FakeOuterCompositeSerializeResponse,
|
||||
@ -44,7 +44,7 @@ use petstore_api::{Api, ApiError,
|
||||
LogoutUserResponse,
|
||||
UpdateUserResponse
|
||||
};
|
||||
use petstore_api::models;
|
||||
use petstore_with_fake_endpoints_models_for_testing::models;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Server<C> {
|
Loading…
Reference in New Issue
Block a user