mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-13 05:00:50 +00:00
fix(rust): wrong path to model used as parameter of api (#17968)
* fix(rust): wrong path to mode used as parameter of api Closes #16974 * fix: re-build samples
This commit is contained in:
parent
340a3eba54
commit
6f01a7ad82
9
bin/configs/rust-hyper-api-with-ref-param.yaml
Normal file
9
bin/configs/rust-hyper-api-with-ref-param.yaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
generatorName: rust
|
||||||
|
outputDir: samples/client/others/rust/hyper/api-with-ref-param
|
||||||
|
library: hyper
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/api-with-ref-param.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/rust
|
||||||
|
additionalProperties:
|
||||||
|
supportAsync: true
|
||||||
|
packageName: api-ref-param-hyper
|
||||||
|
|
9
bin/configs/rust-reqwest-api-with-ref-param.yaml
Normal file
9
bin/configs/rust-reqwest-api-with-ref-param.yaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
generatorName: rust
|
||||||
|
outputDir: samples/client/others/rust/reqwest/api-with-ref-param
|
||||||
|
library: reqwest
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/api-with-ref-param.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/rust
|
||||||
|
additionalProperties:
|
||||||
|
supportAsync: true
|
||||||
|
packageName: api-ref-param-reqwest
|
||||||
|
|
@ -17,7 +17,7 @@ pub struct {{{operationIdCamelCase}}}Params {
|
|||||||
{{#description}}
|
{{#description}}
|
||||||
/// {{{.}}}
|
/// {{{.}}}
|
||||||
{{/description}}
|
{{/description}}
|
||||||
pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^isUuid}}{{#isString}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isString}}{{/isUuid}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}{{#isBodyParam}}models::{{/isBodyParam}}{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}},{{/-last}}
|
pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^isUuid}}{{#isString}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isString}}{{/isUuid}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}},{{/-last}}
|
||||||
{{#-last}}
|
{{#-last}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
|
|||||||
|
|
||||||
{{/vendorExtensions.x-group-parameters}}
|
{{/vendorExtensions.x-group-parameters}}
|
||||||
{{^vendorExtensions.x-group-parameters}}
|
{{^vendorExtensions.x-group-parameters}}
|
||||||
pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}{{#isBodyParam}}models::{{/isBodyParam}}{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> {
|
pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> {
|
||||||
let local_var_configuration = configuration;
|
let local_var_configuration = configuration;
|
||||||
{{/vendorExtensions.x-group-parameters}}
|
{{/vendorExtensions.x-group-parameters}}
|
||||||
|
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
openapi: 3.0.3
|
||||||
|
info:
|
||||||
|
title: Demo
|
||||||
|
version: 0.0.0
|
||||||
|
paths:
|
||||||
|
/demo/{color}:
|
||||||
|
get:
|
||||||
|
parameters:
|
||||||
|
- name: color
|
||||||
|
required: true
|
||||||
|
in: path
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Color"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: OK
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Color:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- RED
|
||||||
|
- GREEN
|
||||||
|
- BLUE
|
28
samples/client/others/rust/Cargo.lock
generated
28
samples/client/others/rust/Cargo.lock
generated
@ -17,6 +17,34 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "api-ref-param-hyper"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"base64 0.7.0",
|
||||||
|
"futures",
|
||||||
|
"http",
|
||||||
|
"hyper",
|
||||||
|
"hyper-tls",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"url",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "api-ref-param-reqwest"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"url",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
3
samples/client/others/rust/hyper/api-with-ref-param/.gitignore
vendored
Normal file
3
samples/client/others/rust/hyper/api-with-ref-param/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
@ -0,0 +1,15 @@
|
|||||||
|
.gitignore
|
||||||
|
.travis.yml
|
||||||
|
Cargo.toml
|
||||||
|
README.md
|
||||||
|
docs/Color.md
|
||||||
|
docs/DefaultApi.md
|
||||||
|
git_push.sh
|
||||||
|
src/apis/client.rs
|
||||||
|
src/apis/configuration.rs
|
||||||
|
src/apis/default_api.rs
|
||||||
|
src/apis/mod.rs
|
||||||
|
src/apis/request.rs
|
||||||
|
src/lib.rs
|
||||||
|
src/models/color.rs
|
||||||
|
src/models/mod.rs
|
@ -0,0 +1 @@
|
|||||||
|
7.4.0-SNAPSHOT
|
@ -0,0 +1 @@
|
|||||||
|
language: rust
|
@ -0,0 +1,20 @@
|
|||||||
|
[package]
|
||||||
|
name = "api-ref-param-hyper"
|
||||||
|
version = "0.0.0"
|
||||||
|
authors = ["OpenAPI Generator team and contributors"]
|
||||||
|
description = "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)"
|
||||||
|
# Override this license by providing a License Object in the OpenAPI.
|
||||||
|
license = "Unlicense"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = "^1.0"
|
||||||
|
serde_derive = "^1.0"
|
||||||
|
serde_json = "^1.0"
|
||||||
|
url = "^2.2"
|
||||||
|
uuid = { version = "^1.0", features = ["serde", "v4"] }
|
||||||
|
hyper = { version = "~0.14", features = ["full"] }
|
||||||
|
hyper-tls = "~0.5"
|
||||||
|
http = "~0.2"
|
||||||
|
base64 = "~0.7.0"
|
||||||
|
futures = "^0.3"
|
@ -0,0 +1,45 @@
|
|||||||
|
# Rust API client for api-ref-param-hyper
|
||||||
|
|
||||||
|
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.
|
||||||
|
|
||||||
|
- API version: 0.0.0
|
||||||
|
- Package version: 0.0.0
|
||||||
|
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Put the package under your project folder in a directory named `api-ref-param-hyper` and add the following to `Cargo.toml` under `[dependencies]`:
|
||||||
|
|
||||||
|
```
|
||||||
|
api-ref-param-hyper = { path = "./api-ref-param-hyper" }
|
||||||
|
```
|
||||||
|
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
*DefaultApi* | [**demo_color_get**](docs/DefaultApi.md#demo_color_get) | **Get** /demo/{color} |
|
||||||
|
|
||||||
|
|
||||||
|
## Documentation For Models
|
||||||
|
|
||||||
|
- [Color](docs/Color.md)
|
||||||
|
|
||||||
|
|
||||||
|
To get access to the crate's generated documentation, use:
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo doc --open
|
||||||
|
```
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
# Color
|
||||||
|
|
||||||
|
## Enum Variants
|
||||||
|
|
||||||
|
| Name | Value |
|
||||||
|
|---- | -----|
|
||||||
|
| Red | RED |
|
||||||
|
| Green | GREEN |
|
||||||
|
| Blue | BLUE |
|
||||||
|
|
||||||
|
|
||||||
|
[[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,37 @@
|
|||||||
|
# \DefaultApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**demo_color_get**](DefaultApi.md#demo_color_get) | **Get** /demo/{color} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## demo_color_get
|
||||||
|
|
||||||
|
> demo_color_get(color)
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
|
||||||
|
Name | Type | Description | Required | Notes
|
||||||
|
------------- | ------------- | ------------- | ------------- | -------------
|
||||||
|
**color** | [**Color**](.md) | | [required] |
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
(empty response body)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: Not defined
|
||||||
|
|
||||||
|
[[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)
|
||||||
|
|
@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||||
|
#
|
||||||
|
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
|
||||||
|
|
||||||
|
git_user_id=$1
|
||||||
|
git_repo_id=$2
|
||||||
|
release_note=$3
|
||||||
|
git_host=$4
|
||||||
|
|
||||||
|
if [ "$git_host" = "" ]; then
|
||||||
|
git_host="github.com"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$git_user_id" = "" ]; then
|
||||||
|
git_user_id="GIT_USER_ID"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$git_repo_id" = "" ]; then
|
||||||
|
git_repo_id="GIT_REPO_ID"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$release_note" = "" ]; then
|
||||||
|
release_note="Minor update"
|
||||||
|
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize the local directory as a Git repository
|
||||||
|
git init
|
||||||
|
|
||||||
|
# Adds the files in the local repository and stages them for commit.
|
||||||
|
git add .
|
||||||
|
|
||||||
|
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||||
|
git commit -m "$release_note"
|
||||||
|
|
||||||
|
# Sets the new remote
|
||||||
|
git_remote=$(git remote)
|
||||||
|
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||||
|
|
||||||
|
if [ "$GIT_TOKEN" = "" ]; then
|
||||||
|
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
|
||||||
|
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
|
||||||
|
else
|
||||||
|
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
git pull origin master
|
||||||
|
|
||||||
|
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||||
|
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||||
|
git push origin master 2>&1 | grep -v 'To https'
|
@ -0,0 +1,24 @@
|
|||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use hyper;
|
||||||
|
use super::configuration::Configuration;
|
||||||
|
|
||||||
|
pub struct APIClient {
|
||||||
|
default_api: Box<dyn crate::apis::DefaultApi>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl APIClient {
|
||||||
|
pub fn new<C: hyper::client::connect::Connect>(configuration: Configuration<C>) -> APIClient
|
||||||
|
where C: Clone + std::marker::Send + Sync + 'static {
|
||||||
|
let rc = Rc::new(configuration);
|
||||||
|
|
||||||
|
APIClient {
|
||||||
|
default_api: Box::new(crate::apis::DefaultApiClient::new(rc.clone())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn default_api(&self) -> &dyn crate::apis::DefaultApi{
|
||||||
|
self.default_api.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Demo
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
use hyper;
|
||||||
|
|
||||||
|
pub struct Configuration<C: hyper::client::connect::Connect>
|
||||||
|
where C: Clone + std::marker::Send + Sync + 'static {
|
||||||
|
pub base_path: String,
|
||||||
|
pub user_agent: Option<String>,
|
||||||
|
pub client: hyper::client::Client<C>,
|
||||||
|
pub basic_auth: Option<BasicAuth>,
|
||||||
|
pub oauth_access_token: Option<String>,
|
||||||
|
pub api_key: Option<ApiKey>,
|
||||||
|
// TODO: take an oauth2 token source, similar to the go one
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type BasicAuth = (String, Option<String>);
|
||||||
|
|
||||||
|
pub struct ApiKey {
|
||||||
|
pub prefix: Option<String>,
|
||||||
|
pub key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<C: hyper::client::connect::Connect> Configuration<C>
|
||||||
|
where C: Clone + std::marker::Send + Sync {
|
||||||
|
pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
|
||||||
|
Configuration {
|
||||||
|
base_path: "http://localhost".to_owned(),
|
||||||
|
user_agent: Some("OpenAPI-Generator/0.0.0/rust".to_owned()),
|
||||||
|
client,
|
||||||
|
basic_auth: None,
|
||||||
|
oauth_access_token: None,
|
||||||
|
api_key: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Demo
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
use std::pin::Pin;
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use std::option::Option;
|
||||||
|
|
||||||
|
use hyper;
|
||||||
|
use futures::Future;
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
use super::{Error, configuration};
|
||||||
|
use super::request as __internal_request;
|
||||||
|
|
||||||
|
pub struct DefaultApiClient<C: hyper::client::connect::Connect>
|
||||||
|
where C: Clone + std::marker::Send + Sync + 'static {
|
||||||
|
configuration: Rc<configuration::Configuration<C>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<C: hyper::client::connect::Connect> DefaultApiClient<C>
|
||||||
|
where C: Clone + std::marker::Send + Sync {
|
||||||
|
pub fn new(configuration: Rc<configuration::Configuration<C>>) -> DefaultApiClient<C> {
|
||||||
|
DefaultApiClient {
|
||||||
|
configuration,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait DefaultApi {
|
||||||
|
fn demo_color_get(&self, color: models::Color) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<C: hyper::client::connect::Connect>DefaultApi for DefaultApiClient<C>
|
||||||
|
where C: Clone + std::marker::Send + Sync {
|
||||||
|
#[allow(unused_mut)]
|
||||||
|
fn demo_color_get(&self, color: models::Color) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> {
|
||||||
|
let mut req = __internal_request::Request::new(hyper::Method::GET, "/demo/{color}".to_string())
|
||||||
|
;
|
||||||
|
req = req.with_path_param("color".to_string(), color.to_string());
|
||||||
|
req = req.returns_nothing();
|
||||||
|
|
||||||
|
req.execute(self.configuration.borrow())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
use http;
|
||||||
|
use hyper;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
Api(ApiError),
|
||||||
|
Header(hyper::http::header::InvalidHeaderValue),
|
||||||
|
Http(http::Error),
|
||||||
|
Hyper(hyper::Error),
|
||||||
|
Serde(serde_json::Error),
|
||||||
|
UriError(http::uri::InvalidUri),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ApiError {
|
||||||
|
pub code: hyper::StatusCode,
|
||||||
|
pub body: hyper::body::Body,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(hyper::StatusCode, hyper::body::Body)> for Error {
|
||||||
|
fn from(e: (hyper::StatusCode, hyper::body::Body)) -> Self {
|
||||||
|
Error::Api(ApiError {
|
||||||
|
code: e.0,
|
||||||
|
body: e.1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<http::Error> for Error {
|
||||||
|
fn from(e: http::Error) -> Self {
|
||||||
|
return Error::Http(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<hyper::Error> for Error {
|
||||||
|
fn from(e: hyper::Error) -> Self {
|
||||||
|
return Error::Hyper(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<serde_json::Error> for Error {
|
||||||
|
fn from(e: serde_json::Error) -> Self {
|
||||||
|
return Error::Serde(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod request;
|
||||||
|
|
||||||
|
mod default_api;
|
||||||
|
pub use self::default_api::{ DefaultApi, DefaultApiClient };
|
||||||
|
|
||||||
|
pub mod configuration;
|
||||||
|
pub mod client;
|
@ -0,0 +1,242 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::pin::Pin;
|
||||||
|
|
||||||
|
use futures;
|
||||||
|
use futures::Future;
|
||||||
|
use futures::future::*;
|
||||||
|
use hyper;
|
||||||
|
use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, HeaderValue, USER_AGENT};
|
||||||
|
use serde;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
|
use super::{configuration, Error};
|
||||||
|
|
||||||
|
pub(crate) struct ApiKey {
|
||||||
|
pub in_header: bool,
|
||||||
|
pub in_query: bool,
|
||||||
|
pub param_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApiKey {
|
||||||
|
fn key(&self, prefix: &Option<String>, key: &str) -> String {
|
||||||
|
match prefix {
|
||||||
|
None => key.to_owned(),
|
||||||
|
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub(crate) enum Auth {
|
||||||
|
None,
|
||||||
|
ApiKey(ApiKey),
|
||||||
|
Basic,
|
||||||
|
Oauth,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If the authorization type is unspecified then it will be automatically detected based
|
||||||
|
/// on the configuration. This functionality is useful when the OpenAPI definition does not
|
||||||
|
/// include an authorization scheme.
|
||||||
|
pub(crate) struct Request {
|
||||||
|
auth: Option<Auth>,
|
||||||
|
method: hyper::Method,
|
||||||
|
path: String,
|
||||||
|
query_params: HashMap<String, String>,
|
||||||
|
no_return_type: bool,
|
||||||
|
path_params: HashMap<String, String>,
|
||||||
|
form_params: HashMap<String, String>,
|
||||||
|
header_params: HashMap<String, String>,
|
||||||
|
// TODO: multiple body params are possible technically, but not supported here.
|
||||||
|
serialized_body: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
impl Request {
|
||||||
|
pub fn new(method: hyper::Method, path: String) -> Self {
|
||||||
|
Request {
|
||||||
|
auth: None,
|
||||||
|
method,
|
||||||
|
path,
|
||||||
|
query_params: HashMap::new(),
|
||||||
|
path_params: HashMap::new(),
|
||||||
|
form_params: HashMap::new(),
|
||||||
|
header_params: HashMap::new(),
|
||||||
|
serialized_body: None,
|
||||||
|
no_return_type: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_body_param<T: serde::Serialize>(mut self, param: T) -> Self {
|
||||||
|
self.serialized_body = Some(serde_json::to_string(¶m).unwrap());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_header_param(mut self, basename: String, param: String) -> Self {
|
||||||
|
self.header_params.insert(basename, param);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn with_query_param(mut self, basename: String, param: String) -> Self {
|
||||||
|
self.query_params.insert(basename, param);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn with_path_param(mut self, basename: String, param: String) -> Self {
|
||||||
|
self.path_params.insert(basename, param);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn with_form_param(mut self, basename: String, param: String) -> Self {
|
||||||
|
self.form_params.insert(basename, param);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn returns_nothing(mut self) -> Self {
|
||||||
|
self.no_return_type = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_auth(mut self, auth: Auth) -> Self {
|
||||||
|
self.auth = Some(auth);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute<'a, C, U>(
|
||||||
|
self,
|
||||||
|
conf: &configuration::Configuration<C>,
|
||||||
|
) -> Pin<Box<dyn Future<Output=Result<U, Error>> + 'a>>
|
||||||
|
where
|
||||||
|
C: hyper::client::connect::Connect + Clone + std::marker::Send + Sync,
|
||||||
|
U: Sized + std::marker::Send + 'a,
|
||||||
|
for<'de> U: serde::Deserialize<'de>,
|
||||||
|
{
|
||||||
|
let mut query_string = ::url::form_urlencoded::Serializer::new("".to_owned());
|
||||||
|
|
||||||
|
let mut path = self.path;
|
||||||
|
for (k, v) in self.path_params {
|
||||||
|
// replace {id} with the value of the id path param
|
||||||
|
path = path.replace(&format!("{{{}}}", k), &v);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (key, val) in self.query_params {
|
||||||
|
query_string.append_pair(&key, &val);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut uri_str = format!("{}{}", conf.base_path, path);
|
||||||
|
|
||||||
|
let query_string_str = query_string.finish();
|
||||||
|
if !query_string_str.is_empty() {
|
||||||
|
uri_str += "?";
|
||||||
|
uri_str += &query_string_str;
|
||||||
|
}
|
||||||
|
let uri: hyper::Uri = match uri_str.parse() {
|
||||||
|
Err(e) => return Box::pin(futures::future::err(Error::UriError(e))),
|
||||||
|
Ok(u) => u,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut req_builder = hyper::Request::builder()
|
||||||
|
.uri(uri)
|
||||||
|
.method(self.method);
|
||||||
|
|
||||||
|
// Detect the authorization type if it hasn't been set.
|
||||||
|
let auth = self.auth.unwrap_or_else(||
|
||||||
|
if conf.api_key.is_some() {
|
||||||
|
panic!("Cannot automatically set the API key from the configuration, it must be specified in the OpenAPI definition")
|
||||||
|
} else if conf.oauth_access_token.is_some() {
|
||||||
|
Auth::Oauth
|
||||||
|
} else if conf.basic_auth.is_some() {
|
||||||
|
Auth::Basic
|
||||||
|
} else {
|
||||||
|
Auth::None
|
||||||
|
}
|
||||||
|
);
|
||||||
|
match auth {
|
||||||
|
Auth::ApiKey(apikey) => {
|
||||||
|
if let Some(ref key) = conf.api_key {
|
||||||
|
let val = apikey.key(&key.prefix, &key.key);
|
||||||
|
if apikey.in_query {
|
||||||
|
query_string.append_pair(&apikey.param_name, &val);
|
||||||
|
}
|
||||||
|
if apikey.in_header {
|
||||||
|
req_builder = req_builder.header(&apikey.param_name, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Auth::Basic => {
|
||||||
|
if let Some(ref auth_conf) = conf.basic_auth {
|
||||||
|
let mut text = auth_conf.0.clone();
|
||||||
|
text.push(':');
|
||||||
|
if let Some(ref pass) = auth_conf.1 {
|
||||||
|
text.push_str(&pass[..]);
|
||||||
|
}
|
||||||
|
let encoded = base64::encode(&text);
|
||||||
|
req_builder = req_builder.header(AUTHORIZATION, encoded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Auth::Oauth => {
|
||||||
|
if let Some(ref token) = conf.oauth_access_token {
|
||||||
|
let text = "Bearer ".to_owned() + token;
|
||||||
|
req_builder = req_builder.header(AUTHORIZATION, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Auth::None => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ref user_agent) = conf.user_agent {
|
||||||
|
req_builder = req_builder.header(USER_AGENT, match HeaderValue::from_str(user_agent) {
|
||||||
|
Ok(header_value) => header_value,
|
||||||
|
Err(e) => return Box::pin(futures::future::err(super::Error::Header(e)))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k, v) in self.header_params {
|
||||||
|
req_builder = req_builder.header(&k, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
let req_headers = req_builder.headers_mut().unwrap();
|
||||||
|
let request_result = if self.form_params.len() > 0 {
|
||||||
|
req_headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/x-www-form-urlencoded"));
|
||||||
|
let mut enc = ::url::form_urlencoded::Serializer::new("".to_owned());
|
||||||
|
for (k, v) in self.form_params {
|
||||||
|
enc.append_pair(&k, &v);
|
||||||
|
}
|
||||||
|
req_builder.body(hyper::Body::from(enc.finish()))
|
||||||
|
} else if let Some(body) = self.serialized_body {
|
||||||
|
req_headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
|
||||||
|
req_headers.insert(CONTENT_LENGTH, body.len().into());
|
||||||
|
req_builder.body(hyper::Body::from(body))
|
||||||
|
} else {
|
||||||
|
req_builder.body(hyper::Body::default())
|
||||||
|
};
|
||||||
|
let request = match request_result {
|
||||||
|
Ok(request) => request,
|
||||||
|
Err(e) => return Box::pin(futures::future::err(Error::from(e)))
|
||||||
|
};
|
||||||
|
|
||||||
|
let no_return_type = self.no_return_type;
|
||||||
|
Box::pin(conf.client
|
||||||
|
.request(request)
|
||||||
|
.map_err(|e| Error::from(e))
|
||||||
|
.and_then(move |response| {
|
||||||
|
let status = response.status();
|
||||||
|
if !status.is_success() {
|
||||||
|
futures::future::err::<U, Error>(Error::from((status, response.into_body()))).boxed()
|
||||||
|
} else if no_return_type {
|
||||||
|
// This is a hack; if there's no_ret_type, U is (), but serde_json gives an
|
||||||
|
// error when deserializing "" into (), so deserialize 'null' into it
|
||||||
|
// instead.
|
||||||
|
// An alternate option would be to require U: Default, and then return
|
||||||
|
// U::default() here instead since () implements that, but then we'd
|
||||||
|
// need to impl default for all models.
|
||||||
|
futures::future::ok::<U, Error>(serde_json::from_str("null").expect("serde null value")).boxed()
|
||||||
|
} else {
|
||||||
|
hyper::body::to_bytes(response.into_body())
|
||||||
|
.map(|bytes| serde_json::from_slice(&bytes.unwrap()))
|
||||||
|
.map_err(|e| Error::from(e)).boxed()
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
extern crate serde;
|
||||||
|
extern crate serde_json;
|
||||||
|
extern crate url;
|
||||||
|
extern crate hyper;
|
||||||
|
extern crate futures;
|
||||||
|
|
||||||
|
pub mod apis;
|
||||||
|
pub mod models;
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Demo
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
|
||||||
|
///
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||||
|
pub enum Color {
|
||||||
|
#[serde(rename = "RED")]
|
||||||
|
Red,
|
||||||
|
#[serde(rename = "GREEN")]
|
||||||
|
Green,
|
||||||
|
#[serde(rename = "BLUE")]
|
||||||
|
Blue,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for Color {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Red => String::from("RED"),
|
||||||
|
Self::Green => String::from("GREEN"),
|
||||||
|
Self::Blue => String::from("BLUE"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Color {
|
||||||
|
fn default() -> Color {
|
||||||
|
Self::Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
pub mod color;
|
||||||
|
pub use self::color::Color;
|
3
samples/client/others/rust/reqwest/api-with-ref-param/.gitignore
vendored
Normal file
3
samples/client/others/rust/reqwest/api-with-ref-param/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
@ -0,0 +1,13 @@
|
|||||||
|
.gitignore
|
||||||
|
.travis.yml
|
||||||
|
Cargo.toml
|
||||||
|
README.md
|
||||||
|
docs/Color.md
|
||||||
|
docs/DefaultApi.md
|
||||||
|
git_push.sh
|
||||||
|
src/apis/configuration.rs
|
||||||
|
src/apis/default_api.rs
|
||||||
|
src/apis/mod.rs
|
||||||
|
src/lib.rs
|
||||||
|
src/models/color.rs
|
||||||
|
src/models/mod.rs
|
@ -0,0 +1 @@
|
|||||||
|
7.4.0-SNAPSHOT
|
@ -0,0 +1 @@
|
|||||||
|
language: rust
|
@ -0,0 +1,18 @@
|
|||||||
|
[package]
|
||||||
|
name = "api-ref-param-reqwest"
|
||||||
|
version = "0.0.0"
|
||||||
|
authors = ["OpenAPI Generator team and contributors"]
|
||||||
|
description = "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)"
|
||||||
|
# Override this license by providing a License Object in the OpenAPI.
|
||||||
|
license = "Unlicense"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = "^1.0"
|
||||||
|
serde_derive = "^1.0"
|
||||||
|
serde_json = "^1.0"
|
||||||
|
url = "^2.2"
|
||||||
|
uuid = { version = "^1.0", features = ["serde", "v4"] }
|
||||||
|
[dependencies.reqwest]
|
||||||
|
version = "^0.11"
|
||||||
|
features = ["json", "multipart"]
|
@ -0,0 +1,45 @@
|
|||||||
|
# Rust API client for api-ref-param-reqwest
|
||||||
|
|
||||||
|
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.
|
||||||
|
|
||||||
|
- API version: 0.0.0
|
||||||
|
- Package version: 0.0.0
|
||||||
|
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Put the package under your project folder in a directory named `api-ref-param-reqwest` and add the following to `Cargo.toml` under `[dependencies]`:
|
||||||
|
|
||||||
|
```
|
||||||
|
api-ref-param-reqwest = { path = "./api-ref-param-reqwest" }
|
||||||
|
```
|
||||||
|
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
*DefaultApi* | [**demo_color_get**](docs/DefaultApi.md#demo_color_get) | **GET** /demo/{color} |
|
||||||
|
|
||||||
|
|
||||||
|
## Documentation For Models
|
||||||
|
|
||||||
|
- [Color](docs/Color.md)
|
||||||
|
|
||||||
|
|
||||||
|
To get access to the crate's generated documentation, use:
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo doc --open
|
||||||
|
```
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
# Color
|
||||||
|
|
||||||
|
## Enum Variants
|
||||||
|
|
||||||
|
| Name | Value |
|
||||||
|
|---- | -----|
|
||||||
|
| Red | RED |
|
||||||
|
| Green | GREEN |
|
||||||
|
| Blue | BLUE |
|
||||||
|
|
||||||
|
|
||||||
|
[[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,37 @@
|
|||||||
|
# \DefaultApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**demo_color_get**](DefaultApi.md#demo_color_get) | **GET** /demo/{color} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## demo_color_get
|
||||||
|
|
||||||
|
> demo_color_get(color)
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
|
||||||
|
Name | Type | Description | Required | Notes
|
||||||
|
------------- | ------------- | ------------- | ------------- | -------------
|
||||||
|
**color** | [**Color**](.md) | | [required] |
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
(empty response body)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: Not defined
|
||||||
|
|
||||||
|
[[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)
|
||||||
|
|
@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||||
|
#
|
||||||
|
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
|
||||||
|
|
||||||
|
git_user_id=$1
|
||||||
|
git_repo_id=$2
|
||||||
|
release_note=$3
|
||||||
|
git_host=$4
|
||||||
|
|
||||||
|
if [ "$git_host" = "" ]; then
|
||||||
|
git_host="github.com"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$git_user_id" = "" ]; then
|
||||||
|
git_user_id="GIT_USER_ID"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$git_repo_id" = "" ]; then
|
||||||
|
git_repo_id="GIT_REPO_ID"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$release_note" = "" ]; then
|
||||||
|
release_note="Minor update"
|
||||||
|
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize the local directory as a Git repository
|
||||||
|
git init
|
||||||
|
|
||||||
|
# Adds the files in the local repository and stages them for commit.
|
||||||
|
git add .
|
||||||
|
|
||||||
|
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||||
|
git commit -m "$release_note"
|
||||||
|
|
||||||
|
# Sets the new remote
|
||||||
|
git_remote=$(git remote)
|
||||||
|
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||||
|
|
||||||
|
if [ "$GIT_TOKEN" = "" ]; then
|
||||||
|
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
|
||||||
|
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
|
||||||
|
else
|
||||||
|
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
git pull origin master
|
||||||
|
|
||||||
|
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||||
|
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||||
|
git push origin master 2>&1 | grep -v 'To https'
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Demo
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Configuration {
|
||||||
|
pub base_path: String,
|
||||||
|
pub user_agent: Option<String>,
|
||||||
|
pub client: reqwest::Client,
|
||||||
|
pub basic_auth: Option<BasicAuth>,
|
||||||
|
pub oauth_access_token: Option<String>,
|
||||||
|
pub bearer_access_token: Option<String>,
|
||||||
|
pub api_key: Option<ApiKey>,
|
||||||
|
// TODO: take an oauth2 token source, similar to the go one
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type BasicAuth = (String, Option<String>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ApiKey {
|
||||||
|
pub prefix: Option<String>,
|
||||||
|
pub key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Configuration {
|
||||||
|
pub fn new() -> Configuration {
|
||||||
|
Configuration::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Configuration {
|
||||||
|
fn default() -> Self {
|
||||||
|
Configuration {
|
||||||
|
base_path: "http://localhost".to_owned(),
|
||||||
|
user_agent: Some("OpenAPI-Generator/0.0.0/rust".to_owned()),
|
||||||
|
client: reqwest::Client::new(),
|
||||||
|
basic_auth: None,
|
||||||
|
oauth_access_token: None,
|
||||||
|
bearer_access_token: None,
|
||||||
|
api_key: None,
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Demo
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
use reqwest;
|
||||||
|
|
||||||
|
use crate::{apis::ResponseContent, models};
|
||||||
|
use super::{Error, configuration};
|
||||||
|
|
||||||
|
|
||||||
|
/// struct for typed errors of method [`demo_color_get`]
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum DemoColorGetError {
|
||||||
|
UnknownValue(serde_json::Value),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn demo_color_get(configuration: &configuration::Configuration, color: models::Color) -> Result<(), Error<DemoColorGetError>> {
|
||||||
|
let local_var_configuration = configuration;
|
||||||
|
|
||||||
|
let local_var_client = &local_var_configuration.client;
|
||||||
|
|
||||||
|
let local_var_uri_str = format!("{}/demo/{color}", local_var_configuration.base_path, color=color.to_string());
|
||||||
|
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
|
||||||
|
|
||||||
|
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
|
||||||
|
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
let local_var_req = local_var_req_builder.build()?;
|
||||||
|
let local_var_resp = local_var_client.execute(local_var_req).await?;
|
||||||
|
|
||||||
|
let local_var_status = local_var_resp.status();
|
||||||
|
let local_var_content = local_var_resp.text().await?;
|
||||||
|
|
||||||
|
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
let local_var_entity: Option<DemoColorGetError> = serde_json::from_str(&local_var_content).ok();
|
||||||
|
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
|
||||||
|
Err(Error::ResponseError(local_var_error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,95 @@
|
|||||||
|
use std::error;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ResponseContent<T> {
|
||||||
|
pub status: reqwest::StatusCode,
|
||||||
|
pub content: String,
|
||||||
|
pub entity: Option<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error<T> {
|
||||||
|
Reqwest(reqwest::Error),
|
||||||
|
Serde(serde_json::Error),
|
||||||
|
Io(std::io::Error),
|
||||||
|
ResponseError(ResponseContent<T>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl <T> fmt::Display for Error<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let (module, e) = match self {
|
||||||
|
Error::Reqwest(e) => ("reqwest", e.to_string()),
|
||||||
|
Error::Serde(e) => ("serde", e.to_string()),
|
||||||
|
Error::Io(e) => ("IO", e.to_string()),
|
||||||
|
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
|
||||||
|
};
|
||||||
|
write!(f, "error in {}: {}", module, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl <T: fmt::Debug> error::Error for Error<T> {
|
||||||
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||||
|
Some(match self {
|
||||||
|
Error::Reqwest(e) => e,
|
||||||
|
Error::Serde(e) => e,
|
||||||
|
Error::Io(e) => e,
|
||||||
|
Error::ResponseError(_) => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl <T> From<reqwest::Error> for Error<T> {
|
||||||
|
fn from(e: reqwest::Error) -> Self {
|
||||||
|
Error::Reqwest(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl <T> From<serde_json::Error> for Error<T> {
|
||||||
|
fn from(e: serde_json::Error) -> Self {
|
||||||
|
Error::Serde(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl <T> From<std::io::Error> for Error<T> {
|
||||||
|
fn from(e: std::io::Error) -> Self {
|
||||||
|
Error::Io(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn urlencode<T: AsRef<str>>(s: T) -> String {
|
||||||
|
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
|
||||||
|
if let serde_json::Value::Object(object) = value {
|
||||||
|
let mut params = vec![];
|
||||||
|
|
||||||
|
for (key, value) in object {
|
||||||
|
match value {
|
||||||
|
serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
|
||||||
|
&format!("{}[{}]", prefix, key),
|
||||||
|
value,
|
||||||
|
)),
|
||||||
|
serde_json::Value::Array(array) => {
|
||||||
|
for (i, value) in array.iter().enumerate() {
|
||||||
|
params.append(&mut parse_deep_object(
|
||||||
|
&format!("{}[{}][{}]", prefix, key, i),
|
||||||
|
value,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
|
||||||
|
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
unimplemented!("Only objects are supported with style=deepObject")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod default_api;
|
||||||
|
|
||||||
|
pub mod configuration;
|
@ -0,0 +1,12 @@
|
|||||||
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
extern crate serde;
|
||||||
|
extern crate serde_json;
|
||||||
|
extern crate url;
|
||||||
|
extern crate reqwest;
|
||||||
|
|
||||||
|
pub mod apis;
|
||||||
|
pub mod models;
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Demo
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
|
||||||
|
///
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||||
|
pub enum Color {
|
||||||
|
#[serde(rename = "RED")]
|
||||||
|
Red,
|
||||||
|
#[serde(rename = "GREEN")]
|
||||||
|
Green,
|
||||||
|
#[serde(rename = "BLUE")]
|
||||||
|
Blue,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for Color {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Red => String::from("RED"),
|
||||||
|
Self::Green => String::from("GREEN"),
|
||||||
|
Self::Blue => String::from("BLUE"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Color {
|
||||||
|
fn default() -> Color {
|
||||||
|
Self::Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
pub mod color;
|
||||||
|
pub use self::color::Color;
|
Loading…
x
Reference in New Issue
Block a user