forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 3.2.x
This commit is contained in:
commit
70cdd27e75
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
- [ ] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
|
||||
- [ ] Ran the shell script under `./bin/` to update Petstore sample so that CIs can verify the change. (For instance, only need to run `./bin/{LANG}-petstore.sh` and `./bin/security/{LANG}-petstore.sh` if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in `.\bin\windows\`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `3.1.x`, `4.0.x`. Default: `master`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `3.2.x`, `4.0.x`. Default: `master`.
|
||||
- [ ] Copied the [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) to review the pull request if your PR is targeting a particular programming language.
|
||||
|
||||
### Description of the PR
|
||||
|
45
README.md
45
README.md
@ -167,6 +167,49 @@ export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
|
||||
export PATH=${JAVA_HOME}/bin:$PATH
|
||||
```
|
||||
|
||||
### Launcher Script
|
||||
|
||||
One downside to manual jar downloads is that you don't keep up-to-date with the latest released version. We have a Bash launcher script at [bin/utils/openapi-generator.cli.sh](./bin/utils/openapi-generator.cli.sh) which resolves this issue.
|
||||
|
||||
To install the launcher script, copy the contents of the script to a location on your path and make the script executable.
|
||||
|
||||
An example of setting this up (NOTE: Always evaluate scripts curled from external systems before executing them).
|
||||
|
||||
```
|
||||
mkdir -p ~/bin/openapitools
|
||||
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator.cli.sh > ~/bin/openapitools/openapi-generator-cli
|
||||
chmod u+x ~/bin/openapitools/openapi-generator-cli
|
||||
export PATH=$PATH:~/bin/openapitools/
|
||||
```
|
||||
|
||||
Now, `openapi-generator-cli` is "installed". On invocation, it will query the GitHub repository for the most recently released version. If this matches the last downloaded jar,
|
||||
it will execute as normal. If a newer version is found, the script will download the latest release and execute it.
|
||||
|
||||
If you need to invoke an older version of the generator, you can define the variable `OPENAPI_GENERATOR_VERSION` either ad hoc or globally. You can export this variable if you'd like to persist a specific release version.
|
||||
|
||||
Examples:
|
||||
|
||||
```
|
||||
# Execute latest released openapi-generator-cli
|
||||
openapi-generator-cli version
|
||||
|
||||
# Execute version 3.1.0 for the current invocation, regardless of the latest released version
|
||||
OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli version
|
||||
|
||||
# Execute version 3.1.0-SNAPSHOT for the current invocation
|
||||
OPENAPI_GENERATOR_VERSION=3.1.0-SNAPSHOT openapi-generator-cli version
|
||||
|
||||
# Execute version 3.0.2 for every invocation in the current shell session
|
||||
export OPENAPI_GENERATOR_VERSION=3.0.2
|
||||
openapi-generator-cli version # is 3.0.2
|
||||
openapi-generator-cli version # is also 3.0.2
|
||||
|
||||
# To "install" a specific version, set the variable in .bashrc/.bash_profile
|
||||
echo "export OPENAPI_GENERATOR_VERSION=3.0.2" >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
openapi-generator-cli version # is always 3.0.2, unless any of the above overrides are done ad hoc
|
||||
```
|
||||
|
||||
### [1.4 - Build Projects](#table-of-contents)
|
||||
|
||||
To build from source, you need the following installed and available in your `$PATH:`
|
||||
@ -419,11 +462,11 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- [Bithost GmbH](https://www.bithost.ch)
|
||||
- [GMO Pepabo](https://pepabo.com/en/)
|
||||
- [Raiffeisen Schweiz Genossenschaft](https://www.raiffeisen.ch)
|
||||
- [RepreZen API Studio](https://www.reprezen.com/swagger-openapi-code-generation-api-first-microservices-enterprise-development)
|
||||
- [REST United](https://restunited.com)
|
||||
- [Telstra](https://dev.telstra.com)
|
||||
- [unblu inc.](https://www.unblu.com/)
|
||||
|
||||
|
||||
## [5 - Presentations/Videos/Tutorials/Books](#table-of-contents)
|
||||
|
||||
- 2018/05/12 - [OpenAPI Generator - community drivenで成長するコードジェネレータ](https://ackintosh.github.io/blog/2018/05/12/openapi-generator/) by [中野暁人](https://github.com/ackintosh)
|
||||
|
60
bin/utils/openapi-generator-cli.sh
Normal file
60
bin/utils/openapi-generator-cli.sh
Normal file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
####
|
||||
# Save as openapi-generator-cli on your PATH. chmod u+x. Enjoy.
|
||||
#
|
||||
# This script will query github on every invocation to pull the latest released version
|
||||
# of openapi-generator.
|
||||
#
|
||||
# If you want repeatable executions, you can explicitly set a version via
|
||||
# OPENAPI_GENERATOR_VERSION
|
||||
# e.g. (in Bash)
|
||||
# export OPENAPI_GENERATOR_VERSION=3.1.0
|
||||
# openapi-generator-cli.sh
|
||||
# or
|
||||
# OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli.sh
|
||||
#
|
||||
# This is also helpful, for example, if you want want to evaluate a SNAPSHOT version.
|
||||
#
|
||||
# NOTE: Jars are downloaded on demand from maven into the same directory as this script
|
||||
# for every 'latest' version pulled from github. Consider putting this under its own directory.
|
||||
####
|
||||
set -o pipefail
|
||||
|
||||
for cmd in {mvn,python,curl}; do
|
||||
if ! command -v ${cmd} > /dev/null; then
|
||||
>&2 echo "This script requires '${cmd}' to be installed."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
function latest.tag {
|
||||
local uri="https://api.github.com/repos/${1}/tags"
|
||||
curl -s ${uri} | python -c "import sys, json; print json.load(sys.stdin)[0]['name'][1:]"
|
||||
}
|
||||
|
||||
ghrepo=openapitools/openapi-generator
|
||||
groupid=org.openapitools
|
||||
artifactid=openapi-generator-cli
|
||||
ver=${OPENAPI_GENERATOR_VERSION:-$(latest.tag $ghrepo)}
|
||||
|
||||
jar=${artifactid}-${ver}.jar
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
if [ ! -f ${DIR}/${jar} ]; then
|
||||
repo="central::default::https://repo1.maven.apache.org/maven2"
|
||||
if [[ ${ver} =~ ^.*-SNAPSHOT$ ]]; then
|
||||
repo="central::default::https://oss.sonatype.org/content/repositories/snapshots"
|
||||
fi
|
||||
mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:get \
|
||||
-DremoteRepositories=${repo} \
|
||||
-Dartifact=${groupid}:${artifactid}:${ver} \
|
||||
-Dtransitive=false \
|
||||
-Ddest=${DIR}/${jar}
|
||||
fi
|
||||
|
||||
java -ea \
|
||||
${JAVA_OPTS} \
|
||||
-Xms512M \
|
||||
-Xmx1024M \
|
||||
-server \
|
||||
-jar ${DIR}/${jar} "$@"
|
@ -768,6 +768,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
public String toVarName(String name) {
|
||||
if (reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
} else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains( "" + ((char) character)))) {
|
||||
return escapeSpecialCharacters(name, null, null);
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
@ -784,6 +786,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
name = removeNonNameElementToCamelCase(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
} else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains( "" + ((char) character)))) {
|
||||
return escapeSpecialCharacters(name, null, null);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@ -822,6 +826,32 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException("reserved word " + name + " not allowed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name with escaped characters.
|
||||
*
|
||||
* @param name the name to be escaped
|
||||
* @param charactersToAllow characters that are not escaped
|
||||
* @param appdendixToReplacement String to append to replaced characters.
|
||||
* @return the escaped word
|
||||
* <p>
|
||||
* throws Runtime exception as word is not escaped properly.
|
||||
*/
|
||||
public String escapeSpecialCharacters(String name, List<String> charactersToAllow, String appdendixToReplacement) {
|
||||
String result = (String) ((CharSequence) name).chars().mapToObj(c -> {
|
||||
String character = "" + (char) c;
|
||||
if (charactersToAllow != null && charactersToAllow.contains(character)) {
|
||||
return character;
|
||||
} else if (specialCharReplacements.containsKey(character)) {
|
||||
return specialCharReplacements.get(character) + (appdendixToReplacement != null ? appdendixToReplacement: "");
|
||||
} else {
|
||||
return character;
|
||||
}
|
||||
}).reduce( (c1, c2) -> "" + c1 + c2).orElse(null);
|
||||
|
||||
if (result != null) return result;
|
||||
throw new RuntimeException("Word '" + name + "' could not be escaped.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fully-qualified "Model" name for import
|
||||
*
|
||||
|
@ -896,8 +896,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
if (path.getParameters() != null) {
|
||||
for (Parameter parameter : path.getParameters()) {
|
||||
//skip propagation if a parameter with the same name is already defined at the operation level
|
||||
if (!operationParameters.contains(generateParameterId(parameter)) && operation.getParameters() != null) {
|
||||
operation.getParameters().add(parameter);
|
||||
if (!operationParameters.contains(generateParameterId(parameter))) {
|
||||
operation.addParametersItem(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -574,6 +574,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
name = name.substring(0, 2).toLowerCase() + name.substring(2);
|
||||
}
|
||||
|
||||
// If name contains special chars -> replace them.
|
||||
if ((((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains( "" + ((char) character))))) {
|
||||
List<String> allowedCharacters = new ArrayList<>();
|
||||
allowedCharacters.add("_");
|
||||
allowedCharacters.add("$");
|
||||
name = escapeSpecialCharacters(name, allowedCharacters, "_");
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
|
@ -49,6 +49,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
public static final String DECLSPEC = "declspec";
|
||||
public static final String DEFAULT_INCLUDE = "defaultInclude";
|
||||
public static final String GENERATE_GMOCKS_FOR_APIS = "generateGMocksForApis";
|
||||
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String declspec = "";
|
||||
@ -114,6 +115,9 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
addOption(DEFAULT_INCLUDE,
|
||||
"The default include statement that should be placed in all headers for including things like the declspec (convention: #include \"Commons.h\" ",
|
||||
this.defaultInclude);
|
||||
addOption(GENERATE_GMOCKS_FOR_APIS,
|
||||
"Generate Google Mock classes for APIs.",
|
||||
null);
|
||||
|
||||
supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h"));
|
||||
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp"));
|
||||
@ -177,6 +181,11 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
defaultInclude = additionalProperties.get(DEFAULT_INCLUDE).toString();
|
||||
}
|
||||
|
||||
if (convertPropertyToBoolean(GENERATE_GMOCKS_FOR_APIS)) {
|
||||
apiTemplateFiles.put("api-gmock.mustache", "GMock.h");
|
||||
additionalProperties.put("gmockApis", "true");
|
||||
}
|
||||
|
||||
additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
|
||||
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
|
||||
additionalProperties.put("modelHeaderGuardPrefix", modelPackage.replaceAll("\\.", "_").toUpperCase());
|
||||
|
@ -165,8 +165,9 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", apiFolder, "configuration.rs"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("client.mustache", apiFolder, "client.rs"));
|
||||
supportingFiles.add(new SupportingFile("api_mod.mustache", apiFolder, "mod.rs"));
|
||||
supportingFiles.add(new SupportingFile("client.mustache", apiFolder, "client.rs"));
|
||||
supportingFiles.add(new SupportingFile("request.rs", apiFolder, "request.rs"));
|
||||
supportingFiles.add(new SupportingFile("model_mod.mustache", modelFolder, "mod.rs"));
|
||||
supportingFiles.add(new SupportingFile("lib.rs", "src", "lib.rs"));
|
||||
supportingFiles.add(new SupportingFile("Cargo.mustache", "", "Cargo.toml"));
|
||||
|
@ -0,0 +1,41 @@
|
||||
{{>licenseInfo}}
|
||||
{{#operations}}
|
||||
#ifndef {{apiHeaderGuardPrefix}}_{{classname}}GMock_H_
|
||||
#define {{apiHeaderGuardPrefix}}_{{classname}}GMock_H_
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "{{classname}}.h"
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
|
||||
class {{declspec}} {{classname}}Mock : public I{{classname}}
|
||||
{
|
||||
public:
|
||||
using Base = I{{classname}};
|
||||
|
||||
{{classname}}Mock() = default;
|
||||
explicit {{classname}}Mock( std::shared_ptr<ApiClient> apiClient ) { };
|
||||
~{{classname}}Mock() override = default;
|
||||
|
||||
{{#operation}}
|
||||
MOCK_METHOD{{allParams.size}}( {{operationId}}, pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> (
|
||||
{{#allParams}}
|
||||
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/allParams}}
|
||||
) );
|
||||
{{/operation}}
|
||||
};
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
#endif /* {{apiHeaderGuardPrefix}}_{{classname}}GMock_H_ */
|
||||
|
||||
{{/operations}}
|
@ -22,11 +22,38 @@ namespace {{this}} {
|
||||
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
class {{declspec}} {{classname}}
|
||||
{{#gmockApis}}
|
||||
class {{declspec}} I{{classname}}
|
||||
{
|
||||
public:
|
||||
{{classname}}( std::shared_ptr<ApiClient> apiClient );
|
||||
virtual ~{{classname}}();
|
||||
I{{classname}}() = default;
|
||||
virtual ~I{{classname}}() = default;
|
||||
|
||||
{{#operation}}
|
||||
virtual pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{operationId}}(
|
||||
{{#allParams}}
|
||||
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/allParams}}
|
||||
) = 0;
|
||||
{{/operation}}
|
||||
};{{/gmockApis}}
|
||||
|
||||
class {{declspec}} {{classname}} {{#gmockApis}} : public I{{classname}} {{/gmockApis}}
|
||||
{
|
||||
public:
|
||||
{{#gmockApis}}
|
||||
using Base = I{{classname}};
|
||||
{{/gmockApis}}
|
||||
|
||||
explicit {{classname}}( std::shared_ptr<ApiClient> apiClient );
|
||||
|
||||
{{#gmockApis}}
|
||||
~{{classname}}() override;
|
||||
{{/gmockApis}}
|
||||
{{^gmockApis}}
|
||||
virtual ~{{classname}}() = default;
|
||||
{{/gmockApis}}
|
||||
|
||||
{{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
@ -41,7 +68,7 @@ public:
|
||||
{{#allParams}}
|
||||
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/allParams}}
|
||||
);
|
||||
){{#gmockApis}} override{{/gmockApis}};
|
||||
{{/operation}}
|
||||
|
||||
protected:
|
||||
|
@ -245,29 +245,35 @@ void {{classname}}::fromJson(web::json::value& val)
|
||||
{{#isString}}
|
||||
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
|
||||
{{/isString}}
|
||||
{{#isByteArray}}{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));{{/isByteArray}}
|
||||
{{#isByteArray}}
|
||||
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
|
||||
{{/isByteArray}}
|
||||
{{^isString}}
|
||||
{{#isDateTime}}
|
||||
{{setter}}(ModelBase::dateFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
|
||||
{{/isDateTime}}
|
||||
{{^isDateTime}}{{^isByteArray}}
|
||||
{{^isDateTime}}
|
||||
{{^isByteArray}}
|
||||
if(!val[utility::conversions::to_string_t("{{baseName}}")].is_null())
|
||||
{
|
||||
{{{dataType}}} newItem({{{defaultValue}}});
|
||||
newItem->fromJson(val[utility::conversions::to_string_t("{{baseName}}")]);
|
||||
{{setter}}( newItem );
|
||||
}
|
||||
{{/isByteArray}}{{/isDateTime}}
|
||||
{{/isByteArray}}
|
||||
{{/isDateTime}}
|
||||
{{/isString}}
|
||||
}
|
||||
{{/required}}
|
||||
{{#required}}
|
||||
{{#isString}}
|
||||
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
|
||||
{{/isString}}{{#isByteArray}}
|
||||
{{/isString}}
|
||||
{{#isByteArray}}
|
||||
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
|
||||
{{/isByteArray}}
|
||||
{{^isString}}{{^isByteArray}}
|
||||
{{^isString}}
|
||||
{{^isByteArray}}
|
||||
{{#isDateTime}}
|
||||
{{setter}}
|
||||
(ModelBase::dateFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
|
||||
@ -282,7 +288,8 @@ void {{classname}}::fromJson(web::json::value& val)
|
||||
{{setter}}( new{{name}} );
|
||||
{{/vendorExtensions.x-codegen-file}}
|
||||
{{/isDateTime}}
|
||||
{{/isByteArray}}{{/isString}}
|
||||
{{/isByteArray}}
|
||||
{{/isString}}
|
||||
{{/required}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isMapContainer}}
|
||||
@ -356,33 +363,47 @@ void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, co
|
||||
{{^required}}
|
||||
if(m_{{name}}IsSet)
|
||||
{
|
||||
{{#isString}}multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));{{/isString}}{{#isByteArray}}multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/isByteArray}}{{^isString}}{{#isDateTime}}multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/isDateTime}}{{^isDateTime}}{{^isByteArray}}if (m_{{name}}.get())
|
||||
{
|
||||
m_{{name}}->toMultipart(multipart, utility::conversions::to_string_t("{{baseName}}."));
|
||||
}
|
||||
{{/isByteArray}}{{/isDateTime}}{{/isString}}
|
||||
}
|
||||
{{/required}}
|
||||
{{#required}}
|
||||
{{#isString}}
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/isString}}{{#isByteArray}}
|
||||
{{/isString}}
|
||||
{{#isByteArray}}
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/isByteArray}}
|
||||
{{^isString}}
|
||||
{{#isDateTime}}
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/isDateTime}}
|
||||
{{^isDateTime}}{{^isByteArray}}
|
||||
{{^isDateTime}}
|
||||
{{^isByteArray}}if (m_{{name}}.get())
|
||||
{
|
||||
m_{{name}}->toMultipart(multipart, utility::conversions::to_string_t("{{baseName}}."));
|
||||
}
|
||||
{{/isByteArray}}
|
||||
{{/isDateTime}}
|
||||
{{/isString}}
|
||||
}
|
||||
{{/required}}
|
||||
{{#required}}
|
||||
{{#isString}}
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/isString}}
|
||||
{{#isByteArray}}
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/isByteArray}}
|
||||
{{^isString}}
|
||||
{{#isDateTime}}
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/isDateTime}}
|
||||
{{^isDateTime}}
|
||||
{{^isByteArray}}
|
||||
{{#vendorExtensions.x-codegen-file}}
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
|
||||
{{/vendorExtensions.x-codegen-file}}
|
||||
{{^vendorExtensions.x-codegen-file}}
|
||||
m_{{name}}->toMultipart(multipart, utility::conversions::to_string_t("{{baseName}}."));
|
||||
{{/vendorExtensions.x-codegen-file}}
|
||||
{{/isByteArray}}{{/isDateTime}}
|
||||
{{/isByteArray}}
|
||||
{{/isDateTime}}
|
||||
{{/isString}}
|
||||
{{/required}}
|
||||
{{/isPrimitiveType}}
|
||||
@ -513,8 +534,11 @@ void {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
|
||||
{{#isString}}
|
||||
{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
|
||||
{{/isString}}
|
||||
{{#isByteArray}}{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));{{/isByteArray}}
|
||||
{{^isString}}{{^isByteArray}}
|
||||
{{#isByteArray}}
|
||||
{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
|
||||
{{/isByteArray}}
|
||||
{{^isString}}
|
||||
{{^isByteArray}}
|
||||
{{#isDateTime}}
|
||||
{{setter}}(ModelBase::dateFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
|
||||
{{/isDateTime}}
|
||||
@ -526,14 +550,19 @@ void {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
|
||||
{{setter}}( newItem );
|
||||
}
|
||||
{{/isDateTime}}
|
||||
{{/isByteArray}}{{/isString}}
|
||||
{{/isByteArray}}
|
||||
{{/isString}}
|
||||
}
|
||||
{{/required}}
|
||||
{{#required}}
|
||||
{{#isString}}
|
||||
{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
|
||||
{{/isString}}{{#isByteArray}}{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));{{/isByteArray}}
|
||||
{{^isString}}{{^isByteArray}}
|
||||
{{/isString}}
|
||||
{{#isByteArray}}
|
||||
{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
|
||||
{{/isByteArray}}
|
||||
{{^isString}}
|
||||
{{^isByteArray}}
|
||||
{{#isDateTime}}
|
||||
{{setter}}(ModelBase::dateFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
|
||||
{{/isDateTime}}
|
||||
@ -547,7 +576,8 @@ void {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
|
||||
{{setter}}( new{{name}} );
|
||||
{{/vendorExtensions.x-codegen-file}}
|
||||
{{/isDateTime}}
|
||||
{{/isByteArray}}{{/isString}}
|
||||
{{/isByteArray}}
|
||||
{{/isString}}
|
||||
{{/required}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isMapContainer}}
|
||||
|
@ -17,30 +17,35 @@ class {{classname}} {
|
||||
if (json == null) return;
|
||||
{{#vars}}
|
||||
{{#isDateTime}}
|
||||
{{name}} = json['{{name}}'] == null ? null : DateTime.parse(json['{{name}}']);
|
||||
{{name}} = json['{{baseName}}'] == null ? null : DateTime.parse(json['{{baseName}}']);
|
||||
{{/isDateTime}}
|
||||
{{#isDate}}
|
||||
{{name}} = json['{{baseName}}'] == null ? null : DateTime.parse(json['{{baseName}}']);
|
||||
{{/isDate}}
|
||||
{{^isDateTime}}
|
||||
{{^isDate}}
|
||||
{{#complexType}}
|
||||
{{#isListContainer}}
|
||||
{{name}} = {{complexType}}.listFromJson(json['{{name}}']);
|
||||
{{name}} = {{complexType}}.listFromJson(json['{{baseName}}']);
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
{{name}} = {{complexType}}.mapFromJson(json['{{name}}']);
|
||||
{{name}} = {{complexType}}.mapFromJson(json['{{baseName}}']);
|
||||
{{/isMapContainer}}
|
||||
{{^isMapContainer}}
|
||||
{{name}} = new {{complexType}}.fromJson(json['{{name}}']);
|
||||
{{name}} = new {{complexType}}.fromJson(json['{{baseName}}']);
|
||||
{{/isMapContainer}}
|
||||
{{/isListContainer}}
|
||||
{{/complexType}}
|
||||
{{^complexType}}
|
||||
{{#isListContainer}}
|
||||
{{name}} = (json['{{name}}'] as List).map((item) => item as {{items.datatype}}).toList();
|
||||
{{name}} = (json['{{baseName}}'] as List).map((item) => item as {{items.datatype}}).toList();
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
{{name}} = json['{{name}}'];
|
||||
{{name}} = json['{{baseName}}'];
|
||||
{{/isListContainer}}
|
||||
{{/complexType}}
|
||||
{{/isDate}}
|
||||
{{/isDateTime}}
|
||||
{{/vars}}
|
||||
}
|
||||
@ -49,10 +54,15 @@ class {{classname}} {
|
||||
return {
|
||||
{{#vars}}
|
||||
{{#isDateTime}}
|
||||
'{{name}}': {{name}} == null ? '' : {{name}}.toUtc().toIso8601String(){{^-last}},{{/-last}}
|
||||
'{{baseName}}': {{name}} == null ? '' : {{name}}.toUtc().toIso8601String(){{^-last}},{{/-last}}
|
||||
{{/isDateTime}}
|
||||
{{#isDate}}
|
||||
'{{baseName}}': {{name}} == null ? '' : {{name}}.toUtc().toIso8601String(){{^-last}},{{/-last}}
|
||||
{{/isDate}}
|
||||
{{^isDateTime}}
|
||||
'{{name}}': {{name}}{{^-last}},{{/-last}}
|
||||
{{^isDate}}
|
||||
'{{baseName}}': {{name}}{{^-last}},{{/-last}}
|
||||
{{/isDate}}
|
||||
{{/isDateTime}}
|
||||
{{/vars}}
|
||||
};
|
||||
|
@ -1,17 +1,13 @@
|
||||
{{>partial_header}}
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
use futures::Future;
|
||||
|
||||
use super::{Error, configuration};
|
||||
use super::request as __internal_request;
|
||||
|
||||
pub struct {{{classname}}}Client<C: hyper::client::Connect> {
|
||||
configuration: Rc<configuration::Configuration<C>>,
|
||||
@ -38,129 +34,54 @@ impl<C: hyper::client::Connect>{{classname}} for {{classname}}Client<C> {
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
fn {{{operationId}}}(&self, {{#allParams}}{{paramName}}: {{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Box<Future<Item = {{^returnType}}(){{/returnType}}{{#returnType}}{{{.}}}{{/returnType}}, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
__internal_request::Request::new(hyper::Method::{{httpMethod}}, "{{{path}}}".to_string())
|
||||
{{#hasAuthMethods}}
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
{{#isKeyInHeader}}
|
||||
auth_headers.insert("{{keyParamName}}".to_owned(), val);
|
||||
{{/isKeyInHeader}}
|
||||
{{#isKeyInQuery}}
|
||||
auth_query.insert("{{keyParamName}}".to_owned(), val);
|
||||
{{/isKeyInQuery}}
|
||||
};
|
||||
.with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{
|
||||
in_header: {{#isKeyInHeader}}true{{/isKeyInHeader}}{{^isKeyInHeader}}false{{/isKeyInHeader}},
|
||||
in_query: {{#isKeyInQuery}}true{{/isKeyInQuery}}{{^isKeyInQuery}}false{{/isKeyInQuery}},
|
||||
param_name: "{{{keyParamName}}}".to_owned(),
|
||||
}))
|
||||
{{/isApiKey}}
|
||||
{{#isBasic}}
|
||||
if let Some(ref auth_conf) = configuration.basic_auth {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Basic {
|
||||
username: auth_conf.0.to_owned(),
|
||||
password: auth_conf.1.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
.with_auth(__internal_request::Auth::Basic)
|
||||
{{/isBasic}}
|
||||
{{#isOAuth}}
|
||||
if let Some(ref token) = configuration.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
.with_auth(__internal_request::Auth::Oauth)
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
let method = hyper::Method::{{httpMethod}};
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
{{#queryParams}}
|
||||
query.append_pair("{{baseName}}", &{{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string());
|
||||
.with_query_param("{{baseName}}".to_string(), {{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string())
|
||||
{{/queryParams}}
|
||||
{{#hasAuthMethods}}
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
{{/hasAuthMethods}}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}{{{path}}}?{}", configuration.base_path, query_string{{#pathParams}}, {{baseName}}={{paramName}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}}{{/pathParams}});
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{{#pathParams}}
|
||||
.with_path_param("{{baseName}}".to_string(), {{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string())
|
||||
{{/pathParams}}
|
||||
{{#hasHeaderParams}}
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
{{#headerParams}}
|
||||
headers.set_raw("{{baseName}}", {{paramName}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}});
|
||||
.with_header_param("{{baseName}}".to_string(), {{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string())
|
||||
{{/headerParams}}
|
||||
}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
{{#hasAuthMethods}}
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
{{/hasAuthMethods}}
|
||||
|
||||
{{#hasFormParams}}
|
||||
{{#formParams}}
|
||||
{{#isFile}}
|
||||
.with_form_param("{{baseName}}".to_string(), unimplemented!())
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
.with_form_param("{{baseName}}".to_string(), {{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string())
|
||||
{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{/hasFormParams}}
|
||||
{{#hasBodyParam}}
|
||||
{{#bodyParams}}
|
||||
let serialized = serde_json::to_string(&{{paramName}}).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
.with_body_param({{paramName}})
|
||||
{{/bodyParams}}
|
||||
{{/hasBodyParam}}
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
{{^returnType}}
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
.returns_nothing()
|
||||
{{/returnType}}
|
||||
{{#returnType}}
|
||||
.and_then(|body| {
|
||||
let parsed: Result<{{{returnType}}}, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
{{/returnType}}
|
||||
)
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
|
@ -4,6 +4,7 @@ use serde_json;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error<T> {
|
||||
UriError(hyper::error::UriError),
|
||||
Hyper(hyper::Error),
|
||||
Serde(serde_json::Error),
|
||||
ApiError(ApiError<T>),
|
||||
@ -50,6 +51,8 @@ impl<T> From<serde_json::Error> for Error<T> {
|
||||
|
||||
use super::models::*;
|
||||
|
||||
mod request;
|
||||
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
mod {{classFilename}};
|
||||
|
238
modules/openapi-generator/src/main/resources/rust/request.rs
Normal file
238
modules/openapi-generator/src/main/resources/rust/request.rs
Normal file
@ -0,0 +1,238 @@
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::{configuration, Error};
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
use hyper;
|
||||
use hyper::header::UserAgent;
|
||||
use serde;
|
||||
use serde_json;
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum Auth {
|
||||
None,
|
||||
ApiKey(ApiKey),
|
||||
Basic,
|
||||
Oauth,
|
||||
}
|
||||
|
||||
pub(crate) struct Request {
|
||||
auth: 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>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
pub fn new(method: hyper::Method, path: String) -> Self {
|
||||
Request {
|
||||
auth: Auth::None,
|
||||
method: method,
|
||||
path: 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
|
||||
}
|
||||
|
||||
pub fn with_query_param(mut self, basename: String, param: String) -> Self {
|
||||
self.query_params.insert(basename, param);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_path_param(mut self, basename: String, param: String) -> Self {
|
||||
self.path_params.insert(basename, param);
|
||||
self
|
||||
}
|
||||
|
||||
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 = auth;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn execute<'a, C, U>(
|
||||
self,
|
||||
conf: &configuration::Configuration<C>,
|
||||
) -> Box<Future<Item = U, Error = Error<serde_json::Value>> + 'a>
|
||||
where
|
||||
C: hyper::client::Connect,
|
||||
U: Sized + 'a,
|
||||
for<'de> U: serde::Deserialize<'de>,
|
||||
{
|
||||
let mut query_string = ::url::form_urlencoded::Serializer::new("".to_owned());
|
||||
// raw_headers is for headers we don't know the proper type of (e.g. custom api key
|
||||
// headers); headers is for ones we do know the type of.
|
||||
let mut raw_headers = HashMap::new();
|
||||
let mut headers: hyper::header::Headers = hyper::header::Headers::new();
|
||||
|
||||
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 (k, v) in self.header_params {
|
||||
raw_headers.insert(k, v);
|
||||
}
|
||||
|
||||
for (key, val) in self.query_params {
|
||||
query_string.append_pair(&key, &val);
|
||||
}
|
||||
|
||||
match self.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 {
|
||||
raw_headers.insert(apikey.param_name, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
Auth::Basic => {
|
||||
if let Some(ref auth_conf) = conf.basic_auth {
|
||||
let auth = hyper::header::Authorization(hyper::header::Basic {
|
||||
username: auth_conf.0.to_owned(),
|
||||
password: auth_conf.1.to_owned(),
|
||||
});
|
||||
headers.set(auth);
|
||||
}
|
||||
}
|
||||
Auth::Oauth => {
|
||||
if let Some(ref token) = conf.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
});
|
||||
headers.set(auth);
|
||||
}
|
||||
}
|
||||
Auth::None => {}
|
||||
}
|
||||
|
||||
let mut uri_str = format!("{}{}", conf.base_path, path);
|
||||
|
||||
let query_string_str = query_string.finish();
|
||||
if query_string_str != "" {
|
||||
uri_str += "?";
|
||||
uri_str += &query_string_str;
|
||||
}
|
||||
let uri: hyper::Uri = match uri_str.parse() {
|
||||
Err(e) => {
|
||||
return Box::new(futures::future::err(Error::UriError(e)));
|
||||
}
|
||||
Ok(u) => u,
|
||||
};
|
||||
|
||||
let mut req = hyper::Request::new(self.method, uri);
|
||||
{
|
||||
let req_headers = req.headers_mut();
|
||||
if let Some(ref user_agent) = conf.user_agent {
|
||||
req_headers.set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
req_headers.extend(headers.iter());
|
||||
|
||||
for (key, val) in raw_headers {
|
||||
req_headers.set_raw(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
if self.form_params.len() > 0 {
|
||||
req.headers_mut().set(hyper::header::ContentType::form_url_encoded());
|
||||
let mut enc = ::url::form_urlencoded::Serializer::new("".to_owned());
|
||||
for (k, v) in self.form_params {
|
||||
enc.append_pair(&k, &v);
|
||||
}
|
||||
req.set_body(enc.finish());
|
||||
}
|
||||
|
||||
if let Some(body) = self.serialized_body {
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut()
|
||||
.set(hyper::header::ContentLength(body.len() as u64));
|
||||
req.set_body(body);
|
||||
}
|
||||
|
||||
let no_ret_type = self.no_return_type;
|
||||
let res = conf.client
|
||||
.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body()
|
||||
.concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
});
|
||||
Box::new(
|
||||
res
|
||||
.and_then(move |body| {
|
||||
let parsed: Result<U, _> = if no_ret_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.
|
||||
serde_json::from_str("null")
|
||||
} else {
|
||||
serde_json::from_slice(&body)
|
||||
};
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.Paths;
|
||||
import io.swagger.v3.oas.models.media.IntegerSchema;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
import io.swagger.v3.oas.models.parameters.QueryParameter;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponses;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DefaultGeneratorTest {
|
||||
|
||||
@Test
|
||||
public void testProcessPaths() throws Exception {
|
||||
OpenAPI openAPI = TestUtils.createOpenAPI();
|
||||
openAPI.setPaths(new Paths());
|
||||
openAPI.getPaths().addPathItem("path1/", new PathItem().get(new Operation().operationId("op1").responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK")))));
|
||||
openAPI.getPaths().addPathItem("path2/", new PathItem().get(new Operation().operationId("op2").addParametersItem(new QueryParameter().name("p1").schema(new StringSchema())).responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK")))));
|
||||
openAPI.getPaths().addPathItem("path3/", new PathItem().addParametersItem(new QueryParameter().name("p1").schema(new StringSchema())).get(new Operation().operationId("op3").addParametersItem(new QueryParameter().name("p2").schema(new IntegerSchema())).responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK")))));
|
||||
openAPI.getPaths().addPathItem("path4/", new PathItem().addParametersItem(new QueryParameter().name("p1").schema(new StringSchema())).get(new Operation().operationId("op4").responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK")))));
|
||||
|
||||
ClientOptInput opts = new ClientOptInput();
|
||||
opts.setOpenAPI(openAPI);
|
||||
opts.setConfig(new DefaultCodegen());
|
||||
opts.setOpts(new ClientOpts());
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
generator.opts(opts);
|
||||
Map<String, List<CodegenOperation>> result = generator.processPaths(openAPI.getPaths());
|
||||
Assert.assertEquals(result.size(), 1);
|
||||
List<CodegenOperation> defaultList = result.get("Default");
|
||||
Assert.assertEquals(defaultList.size(), 4);
|
||||
Assert.assertEquals(defaultList.get(0).path, "path1/");
|
||||
Assert.assertEquals(defaultList.get(0).allParams.size(), 0);
|
||||
Assert.assertEquals(defaultList.get(1).path, "path2/");
|
||||
Assert.assertEquals(defaultList.get(1).allParams.size(), 1);
|
||||
Assert.assertEquals(defaultList.get(2).path, "path3/");
|
||||
Assert.assertEquals(defaultList.get(2).allParams.size(), 2);
|
||||
Assert.assertEquals(defaultList.get(3).path, "path4/");
|
||||
Assert.assertEquals(defaultList.get(3).allParams.size(), 1);
|
||||
}
|
||||
}
|
@ -242,6 +242,31 @@ public class JavaModelTest {
|
||||
Assert.assertTrue(property.isContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with restriced characters")
|
||||
public void restrictedCharactersPropertiesTest() {
|
||||
final Schema schema = new Schema()
|
||||
.description("a sample model")
|
||||
.addProperties("@Some:restricted%characters#to!handle+", new BooleanSchema());
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", schema, Collections.singletonMap("sample", schema));
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "@Some:restricted%characters#to!handle+");
|
||||
Assert.assertEquals(property.getter, "getAtSomeColonRestrictedPercentCharactersHashToExclamationHandlePlus");
|
||||
Assert.assertEquals(property.setter, "setAtSomeColonRestrictedPercentCharactersHashToExclamationHandlePlus");
|
||||
Assert.assertEquals(property.dataType, "Boolean");
|
||||
Assert.assertEquals(property.name, "atSomeColonRestrictedPercentCharactersHashToExclamationHandlePlus");
|
||||
Assert.assertEquals(property.defaultValue, "null");
|
||||
Assert.assertEquals(property.baseType, "Boolean");
|
||||
Assert.assertFalse(property.required);
|
||||
Assert.assertTrue(property.isNotContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with complex properties")
|
||||
public void complexPropertiesTest() {
|
||||
final Schema schema = new Schema()
|
||||
|
@ -1 +1 @@
|
||||
3.0.0-SNAPSHOT
|
||||
3.1.2-SNAPSHOT
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -12,7 +12,7 @@
|
||||
/*
|
||||
* MultipartFormData.h
|
||||
*
|
||||
* This class represents a container for building a application/x-multipart-formdata requests.
|
||||
* This class represents a container for building application/x-multipart-formdata requests.
|
||||
*/
|
||||
|
||||
#ifndef ORG_OPENAPITOOLS_CLIENT_MODEL_MultipartFormData_H_
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -35,11 +35,16 @@ namespace api {
|
||||
|
||||
using namespace org::openapitools::client::model;
|
||||
|
||||
|
||||
|
||||
class PetApi
|
||||
{
|
||||
public:
|
||||
PetApi( std::shared_ptr<ApiClient> apiClient );
|
||||
virtual ~PetApi();
|
||||
|
||||
explicit PetApi( std::shared_ptr<ApiClient> apiClient );
|
||||
|
||||
virtual ~PetApi() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Add a new pet to the store
|
||||
/// </summary>
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -34,11 +34,16 @@ namespace api {
|
||||
|
||||
using namespace org::openapitools::client::model;
|
||||
|
||||
|
||||
|
||||
class StoreApi
|
||||
{
|
||||
public:
|
||||
StoreApi( std::shared_ptr<ApiClient> apiClient );
|
||||
virtual ~StoreApi();
|
||||
|
||||
explicit StoreApi( std::shared_ptr<ApiClient> apiClient );
|
||||
|
||||
virtual ~StoreApi() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID
|
||||
/// </summary>
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -34,11 +34,16 @@ namespace api {
|
||||
|
||||
using namespace org::openapitools::client::model;
|
||||
|
||||
|
||||
|
||||
class UserApi
|
||||
{
|
||||
public:
|
||||
UserApi( std::shared_ptr<ApiClient> apiClient );
|
||||
virtual ~UserApi();
|
||||
|
||||
explicit UserApi( std::shared_ptr<ApiClient> apiClient );
|
||||
|
||||
virtual ~UserApi() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Create user
|
||||
/// </summary>
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -88,12 +88,10 @@ void ApiResponse::toMultipart(std::shared_ptr<MultipartFormData> multipart, cons
|
||||
if(m_TypeIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("type"), m_Type));
|
||||
|
||||
}
|
||||
if(m_MessageIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("message"), m_Message));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -78,7 +78,6 @@ void Category::toMultipart(std::shared_ptr<MultipartFormData> multipart, const u
|
||||
if(m_NameIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("name"), m_Name));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -126,12 +126,10 @@ void Order::toMultipart(std::shared_ptr<MultipartFormData> multipart, const util
|
||||
if(m_ShipDateIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("shipDate"), m_ShipDate));
|
||||
|
||||
}
|
||||
if(m_StatusIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("status"), m_Status));
|
||||
|
||||
}
|
||||
if(m_CompleteIsSet)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -146,7 +146,6 @@ void Pet::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utilit
|
||||
{
|
||||
m_Category->toMultipart(multipart, utility::conversions::to_string_t("category."));
|
||||
}
|
||||
|
||||
}
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("name"), m_Name));
|
||||
{
|
||||
@ -172,7 +171,6 @@ void Pet::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utilit
|
||||
if(m_StatusIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("status"), m_Status));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -78,7 +78,6 @@ void Tag::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utilit
|
||||
if(m_NameIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("name"), m_Name));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@ -138,32 +138,26 @@ void User::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utili
|
||||
if(m_UsernameIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("username"), m_Username));
|
||||
|
||||
}
|
||||
if(m_FirstNameIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("firstName"), m_FirstName));
|
||||
|
||||
}
|
||||
if(m_LastNameIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("lastName"), m_LastName));
|
||||
|
||||
}
|
||||
if(m_EmailIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("email"), m_Email));
|
||||
|
||||
}
|
||||
if(m_PasswordIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("password"), m_Password));
|
||||
|
||||
}
|
||||
if(m_PhoneIsSet)
|
||||
{
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("phone"), m_Phone));
|
||||
|
||||
}
|
||||
if(m_UserStatusIsSet)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
@ -1 +1 @@
|
||||
3.0.0-SNAPSHOT
|
||||
3.1.0
|
@ -3,10 +3,10 @@ extern crate hyper;
|
||||
extern crate petstore_client;
|
||||
extern crate tokio_core;
|
||||
|
||||
use hyper::Client;
|
||||
use hyper::client::HttpConnector;
|
||||
use tokio_core::reactor::Core;
|
||||
use futures::Future;
|
||||
use hyper::client::HttpConnector;
|
||||
use hyper::Client;
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
fn main() {
|
||||
let mut core = Core::new().expect("failed to init core");
|
||||
@ -20,16 +20,16 @@ fn main() {
|
||||
),
|
||||
);
|
||||
|
||||
let new_pet = petstore_client::models::Pet::new("barker".to_owned(), vec![]).with_id(1337);
|
||||
let new_pet = petstore_client::models::Pet::new("ferris".to_owned(), vec![]).with_id(128149);
|
||||
let work = apicli
|
||||
.pet_api()
|
||||
.add_pet(new_pet)
|
||||
.and_then(|_| {
|
||||
apicli
|
||||
.pet_api()
|
||||
.update_pet_with_form(1337, "barko", "escaped")
|
||||
.update_pet_with_form(128149, "ferris", "rusted")
|
||||
})
|
||||
.and_then(|_| apicli.pet_api().get_pet_by_id(1337))
|
||||
.and_then(|_| apicli.pet_api().get_pet_by_id(128149))
|
||||
.and_then(|pet| {
|
||||
println!("pet: {:?}", pet);
|
||||
futures::future::ok(())
|
||||
|
@ -3,12 +3,12 @@ extern crate hyper;
|
||||
extern crate petstore_client;
|
||||
extern crate tokio_core;
|
||||
|
||||
use hyper::Client;
|
||||
use hyper::client::HttpConnector;
|
||||
use tokio_core::reactor::Core;
|
||||
use futures::Future;
|
||||
use hyper::client::HttpConnector;
|
||||
use hyper::Client;
|
||||
use petstore_client::apis::client::APIClient;
|
||||
use petstore_client::apis::Error;
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
fn main() {
|
||||
let mut core = Core::new().expect("failed to init core");
|
||||
|
@ -4,6 +4,7 @@ use serde_json;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error<T> {
|
||||
UriError(hyper::error::UriError),
|
||||
Hyper(hyper::Error),
|
||||
Serde(serde_json::Error),
|
||||
ApiError(ApiError<T>),
|
||||
@ -50,6 +51,8 @@ impl<T> From<serde_json::Error> for Error<T> {
|
||||
|
||||
use super::models::*;
|
||||
|
||||
mod request;
|
||||
|
||||
mod pet_api;
|
||||
pub use self::pet_api::{ PetApi, PetApiClient };
|
||||
mod store_api;
|
||||
|
@ -10,17 +10,13 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
use futures::Future;
|
||||
|
||||
use super::{Error, configuration};
|
||||
use super::request as __internal_request;
|
||||
|
||||
pub struct PetApiClient<C: hyper::client::Connect> {
|
||||
configuration: Rc<configuration::Configuration<C>>,
|
||||
@ -48,533 +44,72 @@ pub trait PetApi {
|
||||
|
||||
impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
fn add_pet(&self, pet: ::models::Pet) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref token) = configuration.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/pet?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
let serialized = serde_json::to_string(&pet).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Post, "/pet".to_string())
|
||||
.with_auth(__internal_request::Auth::Oauth)
|
||||
.with_body_param(pet)
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn delete_pet(&self, pet_id: i64, api_key: &str) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref token) = configuration.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
let method = hyper::Method::Delete;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/pet/{petId}?{}", configuration.base_path, query_string, petId=pet_id);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
headers.set_raw("api_key", api_key);
|
||||
}
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Delete, "/pet/{petId}".to_string())
|
||||
.with_auth(__internal_request::Auth::Oauth)
|
||||
.with_path_param("petId".to_string(), pet_id.to_string())
|
||||
.with_header_param("api_key".to_string(), api_key.to_string())
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn find_pets_by_status(&self, status: Vec<String>) -> Box<Future<Item = Vec<::models::Pet>, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref token) = configuration.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.append_pair("status", &status.join(",").to_string());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/pet/findByStatus?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<Vec<::models::Pet>, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Get, "/pet/findByStatus".to_string())
|
||||
.with_auth(__internal_request::Auth::Oauth)
|
||||
.with_query_param("status".to_string(), status.join(",").to_string())
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn find_pets_by_tags(&self, tags: Vec<String>) -> Box<Future<Item = Vec<::models::Pet>, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref token) = configuration.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.append_pair("tags", &tags.join(",").to_string());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/pet/findByTags?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<Vec<::models::Pet>, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Get, "/pet/findByTags".to_string())
|
||||
.with_auth(__internal_request::Auth::Oauth)
|
||||
.with_query_param("tags".to_string(), tags.join(",").to_string())
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn get_pet_by_id(&self, pet_id: i64) -> Box<Future<Item = ::models::Pet, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
auth_headers.insert("api_key".to_owned(), val);
|
||||
};
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/pet/{petId}?{}", configuration.base_path, query_string, petId=pet_id);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::Pet, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Get, "/pet/{petId}".to_string())
|
||||
.with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{
|
||||
in_header: true,
|
||||
in_query: false,
|
||||
param_name: "api_key".to_owned(),
|
||||
}))
|
||||
.with_path_param("petId".to_string(), pet_id.to_string())
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn update_pet(&self, pet: ::models::Pet) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref token) = configuration.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
let method = hyper::Method::Put;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/pet?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
let serialized = serde_json::to_string(&pet).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Put, "/pet".to_string())
|
||||
.with_auth(__internal_request::Auth::Oauth)
|
||||
.with_body_param(pet)
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn update_pet_with_form(&self, pet_id: i64, name: &str, status: &str) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref token) = configuration.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/pet/{petId}?{}", configuration.base_path, query_string, petId=pet_id);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Post, "/pet/{petId}".to_string())
|
||||
.with_auth(__internal_request::Auth::Oauth)
|
||||
.with_path_param("petId".to_string(), pet_id.to_string())
|
||||
.with_form_param("name".to_string(), name.to_string())
|
||||
.with_form_param("status".to_string(), status.to_string())
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn upload_file(&self, pet_id: i64, additional_metadata: &str, file: ::models::File) -> Box<Future<Item = ::models::ApiResponse, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref token) = configuration.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(
|
||||
hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
}
|
||||
);
|
||||
auth_headers.insert("Authorization".to_owned(), auth.to_string());
|
||||
};
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/pet/{petId}/uploadImage?{}", configuration.base_path, query_string, petId=pet_id);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::ApiResponse, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Post, "/pet/{petId}/uploadImage".to_string())
|
||||
.with_auth(__internal_request::Auth::Oauth)
|
||||
.with_path_param("petId".to_string(), pet_id.to_string())
|
||||
.with_form_param("additionalMetadata".to_string(), additional_metadata.to_string())
|
||||
.with_form_param("file".to_string(), unimplemented!())
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
}
|
||||
|
238
samples/client/petstore/rust/src/apis/request.rs
Normal file
238
samples/client/petstore/rust/src/apis/request.rs
Normal file
@ -0,0 +1,238 @@
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::{configuration, Error};
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
use hyper;
|
||||
use hyper::header::UserAgent;
|
||||
use serde;
|
||||
use serde_json;
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum Auth {
|
||||
None,
|
||||
ApiKey(ApiKey),
|
||||
Basic,
|
||||
Oauth,
|
||||
}
|
||||
|
||||
pub(crate) struct Request {
|
||||
auth: 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>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
pub fn new(method: hyper::Method, path: String) -> Self {
|
||||
Request {
|
||||
auth: Auth::None,
|
||||
method: method,
|
||||
path: 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
|
||||
}
|
||||
|
||||
pub fn with_query_param(mut self, basename: String, param: String) -> Self {
|
||||
self.query_params.insert(basename, param);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_path_param(mut self, basename: String, param: String) -> Self {
|
||||
self.path_params.insert(basename, param);
|
||||
self
|
||||
}
|
||||
|
||||
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 = auth;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn execute<'a, C, U>(
|
||||
self,
|
||||
conf: &configuration::Configuration<C>,
|
||||
) -> Box<Future<Item = U, Error = Error<serde_json::Value>> + 'a>
|
||||
where
|
||||
C: hyper::client::Connect,
|
||||
U: Sized + 'a,
|
||||
for<'de> U: serde::Deserialize<'de>,
|
||||
{
|
||||
let mut query_string = ::url::form_urlencoded::Serializer::new("".to_owned());
|
||||
// raw_headers is for headers we don't know the proper type of (e.g. custom api key
|
||||
// headers); headers is for ones we do know the type of.
|
||||
let mut raw_headers = HashMap::new();
|
||||
let mut headers: hyper::header::Headers = hyper::header::Headers::new();
|
||||
|
||||
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 (k, v) in self.header_params {
|
||||
raw_headers.insert(k, v);
|
||||
}
|
||||
|
||||
for (key, val) in self.query_params {
|
||||
query_string.append_pair(&key, &val);
|
||||
}
|
||||
|
||||
match self.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 {
|
||||
raw_headers.insert(apikey.param_name, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
Auth::Basic => {
|
||||
if let Some(ref auth_conf) = conf.basic_auth {
|
||||
let auth = hyper::header::Authorization(hyper::header::Basic {
|
||||
username: auth_conf.0.to_owned(),
|
||||
password: auth_conf.1.to_owned(),
|
||||
});
|
||||
headers.set(auth);
|
||||
}
|
||||
}
|
||||
Auth::Oauth => {
|
||||
if let Some(ref token) = conf.oauth_access_token {
|
||||
let auth = hyper::header::Authorization(hyper::header::Bearer {
|
||||
token: token.to_owned(),
|
||||
});
|
||||
headers.set(auth);
|
||||
}
|
||||
}
|
||||
Auth::None => {}
|
||||
}
|
||||
|
||||
let mut uri_str = format!("{}{}", conf.base_path, path);
|
||||
|
||||
let query_string_str = query_string.finish();
|
||||
if query_string_str != "" {
|
||||
uri_str += "?";
|
||||
uri_str += &query_string_str;
|
||||
}
|
||||
let uri: hyper::Uri = match uri_str.parse() {
|
||||
Err(e) => {
|
||||
return Box::new(futures::future::err(Error::UriError(e)));
|
||||
}
|
||||
Ok(u) => u,
|
||||
};
|
||||
|
||||
let mut req = hyper::Request::new(self.method, uri);
|
||||
{
|
||||
let req_headers = req.headers_mut();
|
||||
if let Some(ref user_agent) = conf.user_agent {
|
||||
req_headers.set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
req_headers.extend(headers.iter());
|
||||
|
||||
for (key, val) in raw_headers {
|
||||
req_headers.set_raw(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
if self.form_params.len() > 0 {
|
||||
req.headers_mut().set(hyper::header::ContentType::form_url_encoded());
|
||||
let mut enc = ::url::form_urlencoded::Serializer::new("".to_owned());
|
||||
for (k, v) in self.form_params {
|
||||
enc.append_pair(&k, &v);
|
||||
}
|
||||
req.set_body(enc.finish());
|
||||
}
|
||||
|
||||
if let Some(body) = self.serialized_body {
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut()
|
||||
.set(hyper::header::ContentLength(body.len() as u64));
|
||||
req.set_body(body);
|
||||
}
|
||||
|
||||
let no_ret_type = self.no_return_type;
|
||||
let res = conf.client
|
||||
.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body()
|
||||
.concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
});
|
||||
Box::new(
|
||||
res
|
||||
.and_then(move |body| {
|
||||
let parsed: Result<U, _> = if no_ret_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.
|
||||
serde_json::from_str("null")
|
||||
} else {
|
||||
serde_json::from_slice(&body)
|
||||
};
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
@ -10,17 +10,13 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
use futures::Future;
|
||||
|
||||
use super::{Error, configuration};
|
||||
use super::request as __internal_request;
|
||||
|
||||
pub struct StoreApiClient<C: hyper::client::Connect> {
|
||||
configuration: Rc<configuration::Configuration<C>>,
|
||||
@ -44,220 +40,32 @@ pub trait StoreApi {
|
||||
|
||||
impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
|
||||
fn delete_order(&self, order_id: &str) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Delete;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/store/order/{orderId}?{}", configuration.base_path, query_string, orderId=order_id);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Delete, "/store/order/{orderId}".to_string())
|
||||
.with_path_param("orderId".to_string(), order_id.to_string())
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn get_inventory(&self, ) -> Box<Future<Item = ::std::collections::HashMap<String, i32>, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
auth_headers.insert("api_key".to_owned(), val);
|
||||
};
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/store/inventory?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::std::collections::HashMap<String, i32>, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Get, "/store/inventory".to_string())
|
||||
.with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{
|
||||
in_header: true,
|
||||
in_query: false,
|
||||
param_name: "api_key".to_owned(),
|
||||
}))
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn get_order_by_id(&self, order_id: i64) -> Box<Future<Item = ::models::Order, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/store/order/{orderId}?{}", configuration.base_path, query_string, orderId=order_id);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::Order, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Get, "/store/order/{orderId}".to_string())
|
||||
.with_path_param("orderId".to_string(), order_id.to_string())
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn place_order(&self, order: ::models::Order) -> Box<Future<Item = ::models::Order, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/store/order?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&order).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::Order, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Post, "/store/order".to_string())
|
||||
.with_body_param(order)
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,17 +10,13 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
use futures::Future;
|
||||
|
||||
use super::{Error, configuration};
|
||||
use super::request as __internal_request;
|
||||
|
||||
pub struct UserApiClient<C: hyper::client::Connect> {
|
||||
configuration: Rc<configuration::Configuration<C>>,
|
||||
@ -48,403 +44,58 @@ pub trait UserApi {
|
||||
|
||||
impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
fn create_user(&self, user: ::models::User) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/user?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&user).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Post, "/user".to_string())
|
||||
.with_body_param(user)
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn create_users_with_array_input(&self, user: Vec<::models::User>) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/user/createWithArray?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&user).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Post, "/user/createWithArray".to_string())
|
||||
.with_body_param(user)
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn create_users_with_list_input(&self, user: Vec<::models::User>) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/user/createWithList?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&user).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Post, "/user/createWithList".to_string())
|
||||
.with_body_param(user)
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn delete_user(&self, username: &str) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Delete;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/user/{username}?{}", configuration.base_path, query_string, username=username);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Delete, "/user/{username}".to_string())
|
||||
.with_path_param("username".to_string(), username.to_string())
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn get_user_by_name(&self, username: &str) -> Box<Future<Item = ::models::User, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/user/{username}?{}", configuration.base_path, query_string, username=username);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::User, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Get, "/user/{username}".to_string())
|
||||
.with_path_param("username".to_string(), username.to_string())
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn login_user(&self, username: &str, password: &str) -> Box<Future<Item = String, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.append_pair("username", &username.to_string());
|
||||
query.append_pair("password", &password.to_string());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/user/login?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<String, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Get, "/user/login".to_string())
|
||||
.with_query_param("username".to_string(), username.to_string())
|
||||
.with_query_param("password".to_string(), password.to_string())
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn logout_user(&self, ) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/user/logout?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Get, "/user/logout".to_string())
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
fn update_user(&self, username: &str, user: ::models::User) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let method = hyper::Method::Put;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/user/{username}?{}", configuration.base_path, query_string, username=username);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&user).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|_| futures::future::ok(()))
|
||||
)
|
||||
__internal_request::Request::new(hyper::Method::Put, "/user/{username}".to_string())
|
||||
.with_path_param("username".to_string(), username.to_string())
|
||||
.with_body_param(user)
|
||||
.returns_nothing()
|
||||
.execute(self.configuration.borrow())
|
||||
}
|
||||
|
||||
}
|
||||
|
46
scripts/openapi-generator-cli-completion.bash
Normal file
46
scripts/openapi-generator-cli-completion.bash
Normal file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
###
|
||||
# Provides completion assistance for openapi-generator-cli
|
||||
# Install
|
||||
# Mac:
|
||||
# brew install bash-completion
|
||||
# cp openapi-generator-cli-completion.bash `brew --prefix`/etc/bash_completion.d
|
||||
# Linux: many distributions include this automatically. Search for your distro-specific instructions.
|
||||
# When in doubt, try sourcing this file:
|
||||
# type complete && source openapi-generator-cli
|
||||
#
|
||||
# see http://tldp.org/LDP/abs/html/tabexpansion.html
|
||||
###
|
||||
|
||||
_openapi_generator_cli_completions() {
|
||||
COMPREPLY=()
|
||||
local IFS=$' \t\n'
|
||||
local options=()
|
||||
|
||||
options+=("$($1 completion ${COMP_WORDS[@]:1})")
|
||||
|
||||
case "${COMP_WORDS[1]}" in
|
||||
generate)
|
||||
case "${COMP_WORDS[@]:2}" in
|
||||
-l|--lang|-g|--generator-name)
|
||||
# TODO: This is a nice-to-have and not required.
|
||||
# Apply generator-specific options to additional properties. These can be queried via:
|
||||
# openapi-generator-cli config-help -l YOUR_LANG | grep '^\t' | grep -v '^\t\s\s\s\s' | tr -d '\t'
|
||||
# where YOUR_LANG would need to be evaluated as the value after the current switch.
|
||||
# but rather than switching on 'generate' maybe switch on --additional-properties?
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
# ignore
|
||||
;;
|
||||
esac
|
||||
|
||||
# printf '%s\n' "${options[@]}"
|
||||
if [[ -n "${options[@]}" ]]; then
|
||||
COMPREPLY=( $(compgen -W "${options}" -- ${2}) )
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _openapi_generator_cli_completions openapi-generator-cli
|
Loading…
x
Reference in New Issue
Block a user