forked from loafle/openapi-generator-original
[Rust Server] Test allOf objects including base properties (#5457)
* [Rust Server] Add operationIds for rust-server-test * [Rust Server] Add test for allOf * Update samples
This commit is contained in:
parent
b60fc900b2
commit
e4be8a107f
@ -9,10 +9,12 @@ paths:
|
|||||||
/dummy:
|
/dummy:
|
||||||
get:
|
get:
|
||||||
summary: A dummy endpoint to make the spec valid.
|
summary: A dummy endpoint to make the spec valid.
|
||||||
|
operationId: dummyGet
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Success
|
description: Success
|
||||||
put:
|
put:
|
||||||
|
operationId: dummyPut
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/parameters/nested_response'
|
- $ref: '#/parameters/nested_response'
|
||||||
responses:
|
responses:
|
||||||
@ -23,6 +25,7 @@ paths:
|
|||||||
summary: Test HTML handling
|
summary: Test HTML handling
|
||||||
consumes: [text/html]
|
consumes: [text/html]
|
||||||
produces: [text/html]
|
produces: [text/html]
|
||||||
|
operationId: htmlPost
|
||||||
parameters:
|
parameters:
|
||||||
- in: body
|
- in: body
|
||||||
name: body
|
name: body
|
||||||
@ -37,6 +40,7 @@ paths:
|
|||||||
/file_response:
|
/file_response:
|
||||||
get:
|
get:
|
||||||
summary: Get a file
|
summary: Get a file
|
||||||
|
operationId: file_responseGet
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
@ -47,6 +51,7 @@ paths:
|
|||||||
/raw_json:
|
/raw_json:
|
||||||
get:
|
get:
|
||||||
summary: Get an arbitrary JSON blob.
|
summary: Get an arbitrary JSON blob.
|
||||||
|
operationId: raw_jsonGet
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Success
|
description: Success
|
||||||
@ -55,6 +60,7 @@ paths:
|
|||||||
/solo-object:
|
/solo-object:
|
||||||
post:
|
post:
|
||||||
summary: Send an arbitrary JSON blob
|
summary: Send an arbitrary JSON blob
|
||||||
|
operationId: solo_objectPost
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
parameters:
|
parameters:
|
||||||
@ -93,6 +99,15 @@ paths:
|
|||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/get_yaml_response'
|
$ref: '#/definitions/get_yaml_response'
|
||||||
|
/allOf:
|
||||||
|
get:
|
||||||
|
description: Test getting an object which uses allOf
|
||||||
|
operationId: AllOf_Get
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/allOfObject'
|
||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
nested_response:
|
nested_response:
|
||||||
@ -115,6 +130,17 @@ definitions:
|
|||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: string
|
type: string
|
||||||
example: "foo"
|
example: "foo"
|
||||||
|
allOfObject:
|
||||||
|
properties:
|
||||||
|
sampleProperty:
|
||||||
|
type: string
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/baseAllOf'
|
||||||
|
baseAllOf:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
sampleBasePropery:
|
||||||
|
type: string
|
||||||
aNullableContainer:
|
aNullableContainer:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -61,6 +61,7 @@ cargo run --example server
|
|||||||
To run a client, follow one of the following simple steps:
|
To run a client, follow one of the following simple steps:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
cargo run --example client AllOfGet
|
||||||
cargo run --example client DummyGet
|
cargo run --example client DummyGet
|
||||||
cargo run --example client FileResponseGet
|
cargo run --example client FileResponseGet
|
||||||
cargo run --example client GetStructuredYaml
|
cargo run --example client GetStructuredYaml
|
||||||
@ -100,20 +101,23 @@ All URIs are relative to *http://localhost*
|
|||||||
|
|
||||||
Method | HTTP request | Description
|
Method | HTTP request | Description
|
||||||
------------- | ------------- | -------------
|
------------- | ------------- | -------------
|
||||||
[****](docs/default_api.md#) | **GET** /dummy | A dummy endpoint to make the spec valid.
|
[**AllOf_Get**](docs/default_api.md#AllOf_Get) | **GET** /allOf |
|
||||||
[****](docs/default_api.md#) | **PUT** /dummy |
|
[**dummyGet**](docs/default_api.md#dummyGet) | **GET** /dummy | A dummy endpoint to make the spec valid.
|
||||||
[****](docs/default_api.md#) | **GET** /file_response | Get a file
|
[**dummyPut**](docs/default_api.md#dummyPut) | **PUT** /dummy |
|
||||||
|
[**file_responseGet**](docs/default_api.md#file_responseGet) | **GET** /file_response | Get a file
|
||||||
[**getStructuredYaml**](docs/default_api.md#getStructuredYaml) | **GET** /get-structured-yaml |
|
[**getStructuredYaml**](docs/default_api.md#getStructuredYaml) | **GET** /get-structured-yaml |
|
||||||
[****](docs/default_api.md#) | **POST** /html | Test HTML handling
|
[**htmlPost**](docs/default_api.md#htmlPost) | **POST** /html | Test HTML handling
|
||||||
[**post_yaml**](docs/default_api.md#post_yaml) | **POST** /post-yaml |
|
[**post_yaml**](docs/default_api.md#post_yaml) | **POST** /post-yaml |
|
||||||
[****](docs/default_api.md#) | **GET** /raw_json | Get an arbitrary JSON blob.
|
[**raw_jsonGet**](docs/default_api.md#raw_jsonGet) | **GET** /raw_json | Get an arbitrary JSON blob.
|
||||||
[****](docs/default_api.md#) | **POST** /solo-object | Send an arbitrary JSON blob
|
[**solo_objectPost**](docs/default_api.md#solo_objectPost) | **POST** /solo-object | Send an arbitrary JSON blob
|
||||||
|
|
||||||
|
|
||||||
## Documentation For Models
|
## Documentation For Models
|
||||||
|
|
||||||
- [ANullableContainer](docs/ANullableContainer.md)
|
- [ANullableContainer](docs/ANullableContainer.md)
|
||||||
- [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md)
|
- [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md)
|
||||||
|
- [AllOfObject](docs/AllOfObject.md)
|
||||||
|
- [BaseAllOf](docs/BaseAllOf.md)
|
||||||
- [GetYamlResponse](docs/GetYamlResponse.md)
|
- [GetYamlResponse](docs/GetYamlResponse.md)
|
||||||
- [InlineObject](docs/InlineObject.md)
|
- [InlineObject](docs/InlineObject.md)
|
||||||
- [ObjectOfObjects](docs/ObjectOfObjects.md)
|
- [ObjectOfObjects](docs/ObjectOfObjects.md)
|
||||||
|
@ -8,12 +8,14 @@ servers:
|
|||||||
paths:
|
paths:
|
||||||
/dummy:
|
/dummy:
|
||||||
get:
|
get:
|
||||||
|
operationId: dummyGet
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
content: {}
|
content: {}
|
||||||
description: Success
|
description: Success
|
||||||
summary: A dummy endpoint to make the spec valid.
|
summary: A dummy endpoint to make the spec valid.
|
||||||
put:
|
put:
|
||||||
|
operationId: dummyPut
|
||||||
requestBody:
|
requestBody:
|
||||||
$ref: '#/components/requestBodies/inline_object'
|
$ref: '#/components/requestBodies/inline_object'
|
||||||
content:
|
content:
|
||||||
@ -35,6 +37,7 @@ paths:
|
|||||||
x-codegen-request-body-name: nested_response
|
x-codegen-request-body-name: nested_response
|
||||||
/html:
|
/html:
|
||||||
post:
|
post:
|
||||||
|
operationId: htmlPost
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
text/html:
|
text/html:
|
||||||
@ -52,6 +55,7 @@ paths:
|
|||||||
x-codegen-request-body-name: body
|
x-codegen-request-body-name: body
|
||||||
/file_response:
|
/file_response:
|
||||||
get:
|
get:
|
||||||
|
operationId: file_responseGet
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
content:
|
content:
|
||||||
@ -63,6 +67,7 @@ paths:
|
|||||||
summary: Get a file
|
summary: Get a file
|
||||||
/raw_json:
|
/raw_json:
|
||||||
get:
|
get:
|
||||||
|
operationId: raw_jsonGet
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
content:
|
content:
|
||||||
@ -73,6 +78,7 @@ paths:
|
|||||||
summary: Get an arbitrary JSON blob.
|
summary: Get an arbitrary JSON blob.
|
||||||
/solo-object:
|
/solo-object:
|
||||||
post:
|
post:
|
||||||
|
operationId: solo_objectPost
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
@ -112,6 +118,17 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/get_yaml_response'
|
$ref: '#/components/schemas/get_yaml_response'
|
||||||
description: OK
|
description: OK
|
||||||
|
/allOf:
|
||||||
|
get:
|
||||||
|
description: Test getting an object which uses allOf
|
||||||
|
operationId: AllOf_Get
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
content:
|
||||||
|
'*/*':
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/allOfObject'
|
||||||
|
description: OK
|
||||||
components:
|
components:
|
||||||
requestBodies:
|
requestBodies:
|
||||||
nested_response:
|
nested_response:
|
||||||
@ -140,6 +157,19 @@ components:
|
|||||||
description: An additionalPropertiesObject
|
description: An additionalPropertiesObject
|
||||||
example: foo
|
example: foo
|
||||||
type: object
|
type: object
|
||||||
|
allOfObject:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/baseAllOf'
|
||||||
|
example:
|
||||||
|
sampleProperty: sampleProperty
|
||||||
|
properties:
|
||||||
|
sampleProperty:
|
||||||
|
type: string
|
||||||
|
baseAllOf:
|
||||||
|
properties:
|
||||||
|
sampleBasePropery:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
aNullableContainer:
|
aNullableContainer:
|
||||||
properties:
|
properties:
|
||||||
NullableThing:
|
NullableThing:
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
# AllOfObject
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**sample_property** | **String** | | [optional] [default to None]
|
||||||
|
**sample_base_propery** | **String** | | [optional] [default to None]
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
# BaseAllOf
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**sample_base_propery** | **String** | | [optional] [default to None]
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -4,18 +4,43 @@ All URIs are relative to *http://localhost*
|
|||||||
|
|
||||||
Method | HTTP request | Description
|
Method | HTTP request | Description
|
||||||
------------- | ------------- | -------------
|
------------- | ------------- | -------------
|
||||||
****](default_api.md#) | **GET** /dummy | A dummy endpoint to make the spec valid.
|
**AllOf_Get**](default_api.md#AllOf_Get) | **GET** /allOf |
|
||||||
****](default_api.md#) | **PUT** /dummy |
|
**dummyGet**](default_api.md#dummyGet) | **GET** /dummy | A dummy endpoint to make the spec valid.
|
||||||
****](default_api.md#) | **GET** /file_response | Get a file
|
**dummyPut**](default_api.md#dummyPut) | **PUT** /dummy |
|
||||||
|
**file_responseGet**](default_api.md#file_responseGet) | **GET** /file_response | Get a file
|
||||||
**getStructuredYaml**](default_api.md#getStructuredYaml) | **GET** /get-structured-yaml |
|
**getStructuredYaml**](default_api.md#getStructuredYaml) | **GET** /get-structured-yaml |
|
||||||
****](default_api.md#) | **POST** /html | Test HTML handling
|
**htmlPost**](default_api.md#htmlPost) | **POST** /html | Test HTML handling
|
||||||
**post_yaml**](default_api.md#post_yaml) | **POST** /post-yaml |
|
**post_yaml**](default_api.md#post_yaml) | **POST** /post-yaml |
|
||||||
****](default_api.md#) | **GET** /raw_json | Get an arbitrary JSON blob.
|
**raw_jsonGet**](default_api.md#raw_jsonGet) | **GET** /raw_json | Get an arbitrary JSON blob.
|
||||||
****](default_api.md#) | **POST** /solo-object | Send an arbitrary JSON blob
|
**solo_objectPost**](default_api.md#solo_objectPost) | **POST** /solo-object | Send an arbitrary JSON blob
|
||||||
|
|
||||||
|
|
||||||
# ****
|
# **AllOf_Get**
|
||||||
> ()
|
> models::AllOfObject AllOf_Get()
|
||||||
|
|
||||||
|
|
||||||
|
Test getting an object which uses allOf
|
||||||
|
|
||||||
|
### Required Parameters
|
||||||
|
This endpoint does not need any parameter.
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
[**models::AllOfObject**](allOfObject.md)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: */*,
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **dummyGet**
|
||||||
|
> dummyGet()
|
||||||
A dummy endpoint to make the spec valid.
|
A dummy endpoint to make the spec valid.
|
||||||
|
|
||||||
### Required Parameters
|
### Required Parameters
|
||||||
@ -36,8 +61,8 @@ No authorization required
|
|||||||
|
|
||||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
# ****
|
# **dummyPut**
|
||||||
> (nested_response)
|
> dummyPut(nested_response)
|
||||||
|
|
||||||
|
|
||||||
### Required Parameters
|
### Required Parameters
|
||||||
@ -61,8 +86,8 @@ No authorization required
|
|||||||
|
|
||||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
# ****
|
# **file_responseGet**
|
||||||
> swagger::ByteArray ()
|
> swagger::ByteArray file_responseGet()
|
||||||
Get a file
|
Get a file
|
||||||
|
|
||||||
### Required Parameters
|
### Required Parameters
|
||||||
@ -107,8 +132,8 @@ No authorization required
|
|||||||
|
|
||||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
# ****
|
# **htmlPost**
|
||||||
> String (body)
|
> String htmlPost(body)
|
||||||
Test HTML handling
|
Test HTML handling
|
||||||
|
|
||||||
### Required Parameters
|
### Required Parameters
|
||||||
@ -159,8 +184,8 @@ No authorization required
|
|||||||
|
|
||||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
# ****
|
# **raw_jsonGet**
|
||||||
> serde_json::Value ()
|
> serde_json::Value raw_jsonGet()
|
||||||
Get an arbitrary JSON blob.
|
Get an arbitrary JSON blob.
|
||||||
|
|
||||||
### Required Parameters
|
### Required Parameters
|
||||||
@ -181,8 +206,8 @@ No authorization required
|
|||||||
|
|
||||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
# ****
|
# **solo_objectPost**
|
||||||
> (value)
|
> solo_objectPost(value)
|
||||||
Send an arbitrary JSON blob
|
Send an arbitrary JSON blob
|
||||||
|
|
||||||
### Required Parameters
|
### Required Parameters
|
||||||
|
@ -14,6 +14,7 @@ use futures::{Future, future, Stream, stream};
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use rust_server_test::{Api, ApiNoContext, Client, ContextWrapperExt,
|
use rust_server_test::{Api, ApiNoContext, Client, ContextWrapperExt,
|
||||||
ApiError,
|
ApiError,
|
||||||
|
AllOfGetResponse,
|
||||||
DummyGetResponse,
|
DummyGetResponse,
|
||||||
DummyPutResponse,
|
DummyPutResponse,
|
||||||
FileResponseGetResponse,
|
FileResponseGetResponse,
|
||||||
@ -33,6 +34,7 @@ fn main() {
|
|||||||
.arg(Arg::with_name("operation")
|
.arg(Arg::with_name("operation")
|
||||||
.help("Sets the operation to run")
|
.help("Sets the operation to run")
|
||||||
.possible_values(&[
|
.possible_values(&[
|
||||||
|
"AllOfGet",
|
||||||
"DummyGet",
|
"DummyGet",
|
||||||
"FileResponseGet",
|
"FileResponseGet",
|
||||||
"GetStructuredYaml",
|
"GetStructuredYaml",
|
||||||
@ -84,6 +86,11 @@ fn main() {
|
|||||||
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
|
|
||||||
match matches.value_of("operation") {
|
match matches.value_of("operation") {
|
||||||
|
Some("AllOfGet") => {
|
||||||
|
let result = rt.block_on(client.all_of_get(
|
||||||
|
));
|
||||||
|
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
|
||||||
|
},
|
||||||
Some("DummyGet") => {
|
Some("DummyGet") => {
|
||||||
let result = rt.block_on(client.dummy_get(
|
let result = rt.block_on(client.dummy_get(
|
||||||
));
|
));
|
||||||
|
@ -87,6 +87,7 @@ impl<C> Server<C> {
|
|||||||
use rust_server_test::{
|
use rust_server_test::{
|
||||||
Api,
|
Api,
|
||||||
ApiError,
|
ApiError,
|
||||||
|
AllOfGetResponse,
|
||||||
DummyGetResponse,
|
DummyGetResponse,
|
||||||
DummyPutResponse,
|
DummyPutResponse,
|
||||||
FileResponseGetResponse,
|
FileResponseGetResponse,
|
||||||
@ -99,6 +100,15 @@ use rust_server_test::{
|
|||||||
use rust_server_test::server::MakeService;
|
use rust_server_test::server::MakeService;
|
||||||
|
|
||||||
impl<C> Api<C> for Server<C> where C: Has<XSpanIdString>{
|
impl<C> Api<C> for Server<C> where C: Has<XSpanIdString>{
|
||||||
|
fn all_of_get(
|
||||||
|
&self,
|
||||||
|
context: &C) -> Box<Future<Item=AllOfGetResponse, Error=ApiError> + Send>
|
||||||
|
{
|
||||||
|
let context = context.clone();
|
||||||
|
info!("all_of_get() - X-Span-ID: {:?}", context.get().0.clone());
|
||||||
|
Box::new(future::err("Generic failure".into()))
|
||||||
|
}
|
||||||
|
|
||||||
/// A dummy endpoint to make the spec valid.
|
/// A dummy endpoint to make the spec valid.
|
||||||
fn dummy_get(
|
fn dummy_get(
|
||||||
&self,
|
&self,
|
||||||
|
@ -37,6 +37,7 @@ define_encode_set! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use {Api,
|
use {Api,
|
||||||
|
AllOfGetResponse,
|
||||||
DummyGetResponse,
|
DummyGetResponse,
|
||||||
DummyPutResponse,
|
DummyPutResponse,
|
||||||
FileResponseGetResponse,
|
FileResponseGetResponse,
|
||||||
@ -242,6 +243,89 @@ impl<C, F> Api<C> for Client<F> where
|
|||||||
C: Has<XSpanIdString> ,
|
C: Has<XSpanIdString> ,
|
||||||
F: Future<Item=Response<Body>, Error=hyper::Error> + Send + 'static
|
F: Future<Item=Response<Body>, Error=hyper::Error> + Send + 'static
|
||||||
{
|
{
|
||||||
|
fn all_of_get(
|
||||||
|
&self,
|
||||||
|
context: &C) -> Box<dyn Future<Item=AllOfGetResponse, Error=ApiError> + Send>
|
||||||
|
{
|
||||||
|
let mut uri = format!(
|
||||||
|
"{}/allOf",
|
||||||
|
self.base_path
|
||||||
|
);
|
||||||
|
|
||||||
|
// Query parameters
|
||||||
|
let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
|
||||||
|
let query_string_str = query_string.finish();
|
||||||
|
if !query_string_str.is_empty() {
|
||||||
|
uri += "?";
|
||||||
|
uri += &query_string_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
let uri = match Uri::from_str(&uri) {
|
||||||
|
Ok(uri) => uri,
|
||||||
|
Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut request = match hyper::Request::builder()
|
||||||
|
.method("GET")
|
||||||
|
.uri(uri)
|
||||||
|
.body(Body::empty()) {
|
||||||
|
Ok(req) => req,
|
||||||
|
Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
|
||||||
|
};
|
||||||
|
|
||||||
|
let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
|
||||||
|
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||||
|
Ok(h) => h,
|
||||||
|
Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
|
||||||
|
});
|
||||||
|
|
||||||
|
Box::new(self.client_service.request(request)
|
||||||
|
.map_err(|e| ApiError(format!("No response received: {}", e)))
|
||||||
|
.and_then(|mut response| {
|
||||||
|
match response.status().as_u16() {
|
||||||
|
200 => {
|
||||||
|
let body = response.into_body();
|
||||||
|
Box::new(
|
||||||
|
body
|
||||||
|
.concat2()
|
||||||
|
.map_err(|e| ApiError(format!("Failed to read response: {}", e)))
|
||||||
|
.and_then(|body|
|
||||||
|
str::from_utf8(&body)
|
||||||
|
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
|
||||||
|
.and_then(|body|
|
||||||
|
serde_json::from_str::<models::AllOfObject>(body)
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.map(move |body| {
|
||||||
|
AllOfGetResponse::OK
|
||||||
|
(body)
|
||||||
|
})
|
||||||
|
) as Box<dyn Future<Item=_, Error=_> + Send>
|
||||||
|
},
|
||||||
|
code => {
|
||||||
|
let headers = response.headers().clone();
|
||||||
|
Box::new(response.into_body()
|
||||||
|
.take(100)
|
||||||
|
.concat2()
|
||||||
|
.then(move |body|
|
||||||
|
future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
|
||||||
|
code,
|
||||||
|
headers,
|
||||||
|
match body {
|
||||||
|
Ok(ref body) => match str::from_utf8(body) {
|
||||||
|
Ok(body) => Cow::from(body),
|
||||||
|
Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
|
||||||
|
},
|
||||||
|
Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
|
||||||
|
})))
|
||||||
|
)
|
||||||
|
) as Box<dyn Future<Item=_, Error=_> + Send>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
fn dummy_get(
|
fn dummy_get(
|
||||||
&self,
|
&self,
|
||||||
context: &C) -> Box<dyn Future<Item=DummyGetResponse, Error=ApiError> + Send>
|
context: &C) -> Box<dyn Future<Item=DummyGetResponse, Error=ApiError> + Send>
|
||||||
|
@ -73,6 +73,13 @@ pub use futures::Future;
|
|||||||
pub const BASE_PATH: &'static str = "";
|
pub const BASE_PATH: &'static str = "";
|
||||||
pub const API_VERSION: &'static str = "2.3.4";
|
pub const API_VERSION: &'static str = "2.3.4";
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum AllOfGetResponse {
|
||||||
|
/// OK
|
||||||
|
OK
|
||||||
|
(models::AllOfObject)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum DummyGetResponse {
|
pub enum DummyGetResponse {
|
||||||
/// Success
|
/// Success
|
||||||
@ -127,6 +134,10 @@ pub enum SoloObjectPostResponse {
|
|||||||
|
|
||||||
/// API
|
/// API
|
||||||
pub trait Api<C> {
|
pub trait Api<C> {
|
||||||
|
fn all_of_get(
|
||||||
|
&self,
|
||||||
|
context: &C) -> Box<dyn Future<Item=AllOfGetResponse, Error=ApiError> + Send>;
|
||||||
|
|
||||||
/// A dummy endpoint to make the spec valid.
|
/// A dummy endpoint to make the spec valid.
|
||||||
fn dummy_get(
|
fn dummy_get(
|
||||||
&self,
|
&self,
|
||||||
@ -172,6 +183,10 @@ pub trait Api<C> {
|
|||||||
|
|
||||||
/// API without a `Context`
|
/// API without a `Context`
|
||||||
pub trait ApiNoContext {
|
pub trait ApiNoContext {
|
||||||
|
fn all_of_get(
|
||||||
|
&self,
|
||||||
|
) -> Box<dyn Future<Item=AllOfGetResponse, Error=ApiError> + Send>;
|
||||||
|
|
||||||
/// A dummy endpoint to make the spec valid.
|
/// A dummy endpoint to make the spec valid.
|
||||||
fn dummy_get(
|
fn dummy_get(
|
||||||
&self,
|
&self,
|
||||||
@ -228,6 +243,13 @@ impl<'a, T: Api<C> + Sized, C> ContextWrapperExt<'a, C> for T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> {
|
impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> {
|
||||||
|
fn all_of_get(
|
||||||
|
&self,
|
||||||
|
) -> Box<dyn Future<Item=AllOfGetResponse, Error=ApiError> + Send>
|
||||||
|
{
|
||||||
|
self.api().all_of_get(&self.context())
|
||||||
|
}
|
||||||
|
|
||||||
/// A dummy endpoint to make the spec valid.
|
/// A dummy endpoint to make the spec valid.
|
||||||
fn dummy_get(
|
fn dummy_get(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
/// mime types for requests and responses
|
/// mime types for requests and responses
|
||||||
|
|
||||||
pub mod responses {
|
pub mod responses {
|
||||||
|
/// Create &str objects for the response content types for AllOfGet
|
||||||
|
pub static ALL_OF_GET_OK: &str = "*/*";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Create &str objects for the response content types for FileResponseGet
|
/// Create &str objects for the response content types for FileResponseGet
|
||||||
@ -21,6 +24,7 @@ pub mod responses {
|
|||||||
|
|
||||||
pub mod requests {
|
pub mod requests {
|
||||||
|
|
||||||
|
|
||||||
/// Create &str objects for the request content types for DummyPut
|
/// Create &str objects for the request content types for DummyPut
|
||||||
pub static DUMMY_PUT: &str = "application/json";
|
pub static DUMMY_PUT: &str = "application/json";
|
||||||
|
|
||||||
|
@ -171,6 +171,206 @@ impl ::std::str::FromStr for AdditionalPropertiesObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Methods for converting between IntoHeaderValue<AllOfObject> and HeaderValue
|
||||||
|
|
||||||
|
impl From<IntoHeaderValue<AllOfObject>> for HeaderValue {
|
||||||
|
fn from(hdr_value: IntoHeaderValue<AllOfObject>) -> Self {
|
||||||
|
HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<HeaderValue> for IntoHeaderValue<AllOfObject> {
|
||||||
|
fn from(hdr_value: HeaderValue) -> Self {
|
||||||
|
IntoHeaderValue(AllOfObject::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
|
||||||
|
pub struct AllOfObject {
|
||||||
|
#[serde(rename = "sampleProperty")]
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub sample_property: Option<String>,
|
||||||
|
|
||||||
|
#[serde(rename = "sampleBasePropery")]
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub sample_base_propery: Option<String>,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AllOfObject {
|
||||||
|
pub fn new() -> AllOfObject {
|
||||||
|
AllOfObject {
|
||||||
|
sample_property: None,
|
||||||
|
sample_base_propery: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts the AllOfObject value to the Query Parameters representation (style=form, explode=false)
|
||||||
|
/// specified in https://swagger.io/docs/specification/serialization/
|
||||||
|
/// Should be implemented in a serde serializer
|
||||||
|
impl ::std::string::ToString for AllOfObject {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
let mut params: Vec<String> = vec![];
|
||||||
|
|
||||||
|
if let Some(ref sample_property) = self.sample_property {
|
||||||
|
params.push("sampleProperty".to_string());
|
||||||
|
params.push(sample_property.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if let Some(ref sample_base_propery) = self.sample_base_propery {
|
||||||
|
params.push("sampleBasePropery".to_string());
|
||||||
|
params.push(sample_base_propery.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
params.join(",").to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts Query Parameters representation (style=form, explode=false) to a AllOfObject value
|
||||||
|
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||||
|
/// Should be implemented in a serde deserializer
|
||||||
|
impl ::std::str::FromStr for AllOfObject {
|
||||||
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
#[derive(Default)]
|
||||||
|
// An intermediate representation of the struct to use for parsing.
|
||||||
|
struct IntermediateRep {
|
||||||
|
pub sample_property: Vec<String>,
|
||||||
|
pub sample_base_propery: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut intermediate_rep = IntermediateRep::default();
|
||||||
|
|
||||||
|
// Parse into intermediate representation
|
||||||
|
let mut string_iter = s.split(',').into_iter();
|
||||||
|
let mut key_result = string_iter.next();
|
||||||
|
|
||||||
|
while key_result.is_some() {
|
||||||
|
let val = match string_iter.next() {
|
||||||
|
Some(x) => x,
|
||||||
|
None => return Err(())
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(key) = key_result {
|
||||||
|
match key {
|
||||||
|
"sampleProperty" => intermediate_rep.sample_property.push(String::from_str(val).map_err(|x| ())?),
|
||||||
|
"sampleBasePropery" => intermediate_rep.sample_base_propery.push(String::from_str(val).map_err(|x| ())?),
|
||||||
|
_ => return Err(()) // Parse error - unexpected key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the next key
|
||||||
|
key_result = string_iter.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the intermediate representation to return the struct
|
||||||
|
Ok(AllOfObject {
|
||||||
|
sample_property: intermediate_rep.sample_property.into_iter().next(),
|
||||||
|
sample_base_propery: intermediate_rep.sample_base_propery.into_iter().next(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Methods for converting between IntoHeaderValue<BaseAllOf> and HeaderValue
|
||||||
|
|
||||||
|
impl From<IntoHeaderValue<BaseAllOf>> for HeaderValue {
|
||||||
|
fn from(hdr_value: IntoHeaderValue<BaseAllOf>) -> Self {
|
||||||
|
HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<HeaderValue> for IntoHeaderValue<BaseAllOf> {
|
||||||
|
fn from(hdr_value: HeaderValue) -> Self {
|
||||||
|
IntoHeaderValue(BaseAllOf::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
|
||||||
|
pub struct BaseAllOf {
|
||||||
|
#[serde(rename = "sampleBasePropery")]
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub sample_base_propery: Option<String>,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BaseAllOf {
|
||||||
|
pub fn new() -> BaseAllOf {
|
||||||
|
BaseAllOf {
|
||||||
|
sample_base_propery: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts the BaseAllOf value to the Query Parameters representation (style=form, explode=false)
|
||||||
|
/// specified in https://swagger.io/docs/specification/serialization/
|
||||||
|
/// Should be implemented in a serde serializer
|
||||||
|
impl ::std::string::ToString for BaseAllOf {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
let mut params: Vec<String> = vec![];
|
||||||
|
|
||||||
|
if let Some(ref sample_base_propery) = self.sample_base_propery {
|
||||||
|
params.push("sampleBasePropery".to_string());
|
||||||
|
params.push(sample_base_propery.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
params.join(",").to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts Query Parameters representation (style=form, explode=false) to a BaseAllOf value
|
||||||
|
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||||
|
/// Should be implemented in a serde deserializer
|
||||||
|
impl ::std::str::FromStr for BaseAllOf {
|
||||||
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
#[derive(Default)]
|
||||||
|
// An intermediate representation of the struct to use for parsing.
|
||||||
|
struct IntermediateRep {
|
||||||
|
pub sample_base_propery: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut intermediate_rep = IntermediateRep::default();
|
||||||
|
|
||||||
|
// Parse into intermediate representation
|
||||||
|
let mut string_iter = s.split(',').into_iter();
|
||||||
|
let mut key_result = string_iter.next();
|
||||||
|
|
||||||
|
while key_result.is_some() {
|
||||||
|
let val = match string_iter.next() {
|
||||||
|
Some(x) => x,
|
||||||
|
None => return Err(())
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(key) = key_result {
|
||||||
|
match key {
|
||||||
|
"sampleBasePropery" => intermediate_rep.sample_base_propery.push(String::from_str(val).map_err(|x| ())?),
|
||||||
|
_ => return Err(()) // Parse error - unexpected key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the next key
|
||||||
|
key_result = string_iter.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the intermediate representation to return the struct
|
||||||
|
Ok(BaseAllOf {
|
||||||
|
sample_base_propery: intermediate_rep.sample_base_propery.into_iter().next(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// structured response
|
/// structured response
|
||||||
// Methods for converting between IntoHeaderValue<GetYamlResponse> and HeaderValue
|
// Methods for converting between IntoHeaderValue<GetYamlResponse> and HeaderValue
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ use header;
|
|||||||
pub use crate::context;
|
pub use crate::context;
|
||||||
|
|
||||||
use {Api,
|
use {Api,
|
||||||
|
AllOfGetResponse,
|
||||||
DummyGetResponse,
|
DummyGetResponse,
|
||||||
DummyPutResponse,
|
DummyPutResponse,
|
||||||
FileResponseGetResponse,
|
FileResponseGetResponse,
|
||||||
@ -38,6 +39,7 @@ mod paths {
|
|||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(vec![
|
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(vec![
|
||||||
|
r"^/allOf$",
|
||||||
r"^/dummy$",
|
r"^/dummy$",
|
||||||
r"^/file_response$",
|
r"^/file_response$",
|
||||||
r"^/get-structured-yaml$",
|
r"^/get-structured-yaml$",
|
||||||
@ -48,13 +50,14 @@ mod paths {
|
|||||||
])
|
])
|
||||||
.expect("Unable to create global regex set");
|
.expect("Unable to create global regex set");
|
||||||
}
|
}
|
||||||
pub static ID_DUMMY: usize = 0;
|
pub static ID_ALLOF: usize = 0;
|
||||||
pub static ID_FILE_RESPONSE: usize = 1;
|
pub static ID_DUMMY: usize = 1;
|
||||||
pub static ID_GET_STRUCTURED_YAML: usize = 2;
|
pub static ID_FILE_RESPONSE: usize = 2;
|
||||||
pub static ID_HTML: usize = 3;
|
pub static ID_GET_STRUCTURED_YAML: usize = 3;
|
||||||
pub static ID_POST_YAML: usize = 4;
|
pub static ID_HTML: usize = 4;
|
||||||
pub static ID_RAW_JSON: usize = 5;
|
pub static ID_POST_YAML: usize = 5;
|
||||||
pub static ID_SOLO_OBJECT: usize = 6;
|
pub static ID_RAW_JSON: usize = 6;
|
||||||
|
pub static ID_SOLO_OBJECT: usize = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MakeService<T, RC> {
|
pub struct MakeService<T, RC> {
|
||||||
@ -131,6 +134,49 @@ where
|
|||||||
|
|
||||||
match &method {
|
match &method {
|
||||||
|
|
||||||
|
// AllOfGet - GET /allOf
|
||||||
|
&hyper::Method::GET if path.matched(paths::ID_ALLOF) => {
|
||||||
|
Box::new({
|
||||||
|
{{
|
||||||
|
Box::new(
|
||||||
|
api_impl.all_of_get(
|
||||||
|
&context
|
||||||
|
).then(move |result| {
|
||||||
|
let mut response = Response::new(Body::empty());
|
||||||
|
response.headers_mut().insert(
|
||||||
|
HeaderName::from_static("x-span-id"),
|
||||||
|
HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str())
|
||||||
|
.expect("Unable to create X-Span-ID header value"));
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(rsp) => match rsp {
|
||||||
|
AllOfGetResponse::OK
|
||||||
|
(body)
|
||||||
|
=> {
|
||||||
|
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||||
|
response.headers_mut().insert(
|
||||||
|
CONTENT_TYPE,
|
||||||
|
HeaderValue::from_str(mimetypes::responses::ALL_OF_GET_OK)
|
||||||
|
.expect("Unable to create Content-Type header for ALL_OF_GET_OK"));
|
||||||
|
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||||
|
*response.body_mut() = Body::from(body);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
// Application code returned an error. This should not happen, as the implementation should
|
||||||
|
// return a valid response.
|
||||||
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
*response.body_mut() = Body::from("An internal error occurred");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
future::ok(response)
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}}
|
||||||
|
}) as Self::Future
|
||||||
|
},
|
||||||
|
|
||||||
// DummyGet - GET /dummy
|
// DummyGet - GET /dummy
|
||||||
&hyper::Method::GET if path.matched(paths::ID_DUMMY) => {
|
&hyper::Method::GET if path.matched(paths::ID_DUMMY) => {
|
||||||
Box::new({
|
Box::new({
|
||||||
@ -620,6 +666,8 @@ impl<T> RequestParser<T> for ApiRequestParser {
|
|||||||
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
|
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
|
||||||
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
|
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
|
||||||
match request.method() {
|
match request.method() {
|
||||||
|
// AllOfGet - GET /allOf
|
||||||
|
&hyper::Method::GET if path.matched(paths::ID_ALLOF) => Ok("AllOfGet"),
|
||||||
// DummyGet - GET /dummy
|
// DummyGet - GET /dummy
|
||||||
&hyper::Method::GET if path.matched(paths::ID_DUMMY) => Ok("DummyGet"),
|
&hyper::Method::GET if path.matched(paths::ID_DUMMY) => Ok("DummyGet"),
|
||||||
// DummyPut - PUT /dummy
|
// DummyPut - PUT /dummy
|
||||||
|
Loading…
x
Reference in New Issue
Block a user