mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-13 16:03:43 +00:00
* [typescript-fetch] Fix #1998: namespace reqs. Fix #1998 by namespacing the generated request object types used in the typescript-fetch client codegen. * Update petstore samples. * Add default-false namespacing config option. * Re-run code sample generation. * Add maven build configurations. * Fix sample VERSION files. * Update typescript-fetch docs. * Emulate with-npm-version, adding package.json. * Add Paxos to companies using. * Prefix namespace with basename to avoid collisions.
This commit is contained in:
parent
1a808dd644
commit
b323b0a0af
@ -0,0 +1,73 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptFetchBuildNamespaceParameterInterfacesPestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch Petstore Client (with namespacing for parameter interfaces)</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-build</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>run</argument>
|
||||
<argument>build</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -569,6 +569,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- [Klarna](https://www.klarna.com/)
|
||||
- [Metaswitch](https://www.metaswitch.com/)
|
||||
- [Myworkout](https://myworkout.com)
|
||||
- [Paxos](https://www.paxos.com)
|
||||
- [Prometheus/Alertmanager](https://github.com/prometheus/alertmanager)
|
||||
- [Raiffeisen Schweiz Genossenschaft](https://www.raiffeisen.ch)
|
||||
- [RepreZen API Studio](https://www.reprezen.com/swagger-openapi-code-generation-api-first-microservices-enterprise-development)
|
||||
|
@ -4,3 +4,4 @@
|
||||
./bin/openapi3/typescript-fetch-petstore-with-npm-version.sh
|
||||
./bin/openapi3/typescript-fetch-petstore-interfaces.sh
|
||||
./bin/openapi3/typescript-fetch-petstore.sh
|
||||
./bin/openapi3/typescript-fetch-petstore-namespace-parameter-interfaces.sh
|
||||
|
32
bin/openapi3/typescript-fetch-petstore-namespace-parameter-interfaces.sh
Executable file
32
bin/openapi3/typescript-fetch-petstore-namespace-parameter-interfaces.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g typescript-fetch -o samples/client/petstore/typescript-fetch/builds/namespace-parameter-interfaces --additional-properties namespaceParameterInterfaces=true $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -4,4 +4,5 @@
|
||||
./bin/typescript-fetch-petstore-with-npm-version.sh
|
||||
./bin/typescript-fetch-petstore-interfaces.sh
|
||||
./bin/typescript-fetch-petstore.sh
|
||||
./bin/typescript-fetch-petstore-multiple-parameters.sh
|
||||
./bin/typescript-fetch-petstore-multiple-parameters.sh
|
||||
./bin/typescript-fetch-petstore-namespace-parameter-interfaces.sh
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"npmName": "@openapitools/typescript-fetch-petstore",
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository" : "https://skimdb.npmjs.com/registry",
|
||||
"snapshot" : false,
|
||||
"namespaceParameterInterfaces": true
|
||||
}
|
34
bin/typescript-fetch-petstore-namespace-parameter-interfaces.sh
Executable file
34
bin/typescript-fetch-petstore-namespace-parameter-interfaces.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-fetch -c bin/typescript-fetch-petstore-namespace-parameter-interfaces.json -o samples/client/petstore/typescript-fetch/builds/namespace-parameter-interfaces $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/builds/namespace-parameter-interfaces/pom.xml samples/client/petstore/typescript-fetch/builds/namespace-parameter-interfaces/pom.xml
|
@ -5,3 +5,4 @@ call bin\windows\typescript-fetch-petstore-target-es6.bat
|
||||
call bin\windows\typescript-fetch-petstore-with-npm-version.bat
|
||||
call bin\windows\typescript-fetch-petstore-interfaces.bat
|
||||
call bin\windows\typescript-fetch-petstore-multiple-parameters.bat
|
||||
call bin\windows\typescript-fetch-petstore-namespace-parameter-interfaces.bat
|
||||
|
@ -0,0 +1,12 @@
|
||||
@ECHO OFF
|
||||
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g typescript-fetch -o samples\client\petstore\typescript-fetch\builds\namespace-parameter-interfaces --additional-properties namespaceParameterInterfaces=true
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
@ -19,3 +19,4 @@ sidebar_label: typescript-fetch
|
||||
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
|
||||
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
|
||||
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |true|
|
||||
|namespaceParameterInterfaces|Setting this property to true will generate parameter interface declarations within a dedicated namespace to avoid name conflicts.| |false|
|
||||
|
@ -33,9 +33,11 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
public static final String NPM_REPOSITORY = "npmRepository";
|
||||
public static final String WITH_INTERFACES = "withInterfaces";
|
||||
public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter";
|
||||
public static final String NAMESPACE_PARAMETER_INTERFACES = "namespaceParameterInterfaces";
|
||||
|
||||
protected String npmRepository = null;
|
||||
private boolean useSingleRequestParameter = true;
|
||||
private boolean namespaceParameterInterfaces = false;
|
||||
protected boolean addedApiIndex = false;
|
||||
protected boolean addedModelIndex = false;
|
||||
|
||||
@ -59,6 +61,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString()));
|
||||
this.cliOptions.add(new CliOption(NAMESPACE_PARAMETER_INTERFACES, "Setting this property to true will generate parameter interface declarations within a dedicated namespace to avoid name conflicts.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -94,6 +97,11 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
}
|
||||
writePropertyBack(USE_SINGLE_REQUEST_PARAMETER, getUseSingleRequestParameter());
|
||||
|
||||
if (additionalProperties.containsKey(NAMESPACE_PARAMETER_INTERFACES)) {
|
||||
this.setNamespaceParameterInterfaces(convertPropertyToBoolean(NAMESPACE_PARAMETER_INTERFACES));
|
||||
}
|
||||
writePropertyBack(NAMESPACE_PARAMETER_INTERFACES, getNamespaceParameterInterfaces());
|
||||
|
||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||
addNpmPackageGeneration();
|
||||
}
|
||||
@ -208,6 +216,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
this.addOperationModelImportInfomation(operations);
|
||||
this.updateOperationParameterEnumInformation(operations);
|
||||
this.addOperationObjectResponseInformation(operations);
|
||||
this.addOperationNamespaceParameterInterfacesInformation(operations);
|
||||
return operations;
|
||||
}
|
||||
|
||||
@ -254,6 +263,22 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
}
|
||||
}
|
||||
|
||||
private void addOperationNamespaceParameterInterfacesInformation(Map<String, Object> operations) {
|
||||
Map<String, Object> _operations = (Map<String, Object>) operations.get("operations");
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) _operations.get("operation");
|
||||
if (!operationList.isEmpty() && getNamespaceParameterInterfaces()) {
|
||||
operations.put("namespaceParameterInterfaces", true);
|
||||
operations.put("paramIfaceIndent", " ");
|
||||
operations.put("paramIfaceSuffix", "");
|
||||
operations.put("paramIfaceNsPrefix", operationList.get(0).baseName + "Requests.");
|
||||
} else {
|
||||
operations.put("namespaceParameterInterfaces", false);
|
||||
operations.put("paramIfaceIndent", "");
|
||||
operations.put("paramIfaceSuffix", "Request");
|
||||
operations.put("paramIfaceNsPrefix", "");
|
||||
}
|
||||
}
|
||||
|
||||
private void addExtraReservedWords() {
|
||||
this.reservedWords.add("BASE_PATH");
|
||||
this.reservedWords.add("BaseAPI");
|
||||
@ -289,4 +314,12 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
private void setUseSingleRequestParameter(boolean useSingleRequestParameter) {
|
||||
this.useSingleRequestParameter = useSingleRequestParameter;
|
||||
}
|
||||
|
||||
private boolean getNamespaceParameterInterfaces() {
|
||||
return namespaceParameterInterfaces;
|
||||
}
|
||||
|
||||
private void setNamespaceParameterInterfaces(boolean namespaceParameterInterfaces) {
|
||||
this.namespaceParameterInterfaces = namespaceParameterInterfaces;
|
||||
}
|
||||
}
|
||||
|
@ -13,16 +13,31 @@ import {
|
||||
{{/imports.0}}
|
||||
|
||||
{{#operations}}
|
||||
{{#namespaceParameterInterfaces}}
|
||||
{{#operation.0}}
|
||||
/**
|
||||
* Generated request parameter interface declarations (in namespace to avoid collisions).
|
||||
*/
|
||||
export namespace {{baseName}}Requests {
|
||||
|
||||
{{/operation.0}}
|
||||
{{/namespaceParameterInterfaces}}
|
||||
{{#operation}}
|
||||
{{#allParams.0}}
|
||||
export interface {{operationIdCamelCase}}Request {
|
||||
{{#allParams}}
|
||||
{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
|
||||
{{/allParams}}
|
||||
}
|
||||
{{paramIfaceIndent}}export interface {{operationIdCamelCase}}{{paramIfaceSuffix}} {
|
||||
{{#allParams}}
|
||||
{{paramIfaceIndent}} {{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
|
||||
{{/allParams}}
|
||||
{{paramIfaceIndent}}}
|
||||
|
||||
{{/allParams.0}}
|
||||
{{/operation}}
|
||||
{{#namespaceParameterInterfaces}}
|
||||
{{#operation.0}}
|
||||
}
|
||||
|
||||
{{/operation.0}}
|
||||
{{/namespaceParameterInterfaces}}
|
||||
{{/operations}}
|
||||
{{#operations}}
|
||||
/**
|
||||
@ -39,7 +54,7 @@ export class {{classname}} extends runtime.BaseAPI {
|
||||
* {{&summary}}
|
||||
{{/summary}}
|
||||
*/
|
||||
async {{nickname}}Raw({{#allParams.0}}requestParameters: {{operationIdCamelCase}}Request{{/allParams.0}}): Promise<runtime.ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> {
|
||||
async {{nickname}}Raw({{#allParams.0}}requestParameters: {{paramIfaceNsPrefix}}{{operationIdCamelCase}}{{paramIfaceSuffix}}{{/allParams.0}}): Promise<runtime.ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> {
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
if (requestParameters.{{paramName}} === null || requestParameters.{{paramName}} === undefined) {
|
||||
@ -249,7 +264,7 @@ export class {{classname}} extends runtime.BaseAPI {
|
||||
}
|
||||
{{/useSingleRequestParameter}}
|
||||
{{#useSingleRequestParameter}}
|
||||
async {{nickname}}({{#allParams.0}}requestParameters: {{operationIdCamelCase}}Request{{/allParams.0}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
|
||||
async {{nickname}}({{#allParams.0}}requestParameters: {{paramIfaceNsPrefix}}{{operationIdCamelCase}}{{paramIfaceSuffix}}{{/allParams.0}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
|
||||
{{#returnType}}
|
||||
const response = await this.{{nickname}}Raw({{#allParams.0}}requestParameters{{/allParams.0}});
|
||||
return await response.value();
|
||||
|
@ -52,6 +52,7 @@ public class TypeScriptFetchClientOptionsProvider implements OptionsProvider {
|
||||
.put(TypeScriptFetchClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
|
||||
.put(TypeScriptFetchClientCodegen.WITH_INTERFACES, Boolean.FALSE.toString())
|
||||
.put(TypeScriptFetchClientCodegen.USE_SINGLE_REQUEST_PARAMETER, Boolean.FALSE.toString())
|
||||
.put(TypeScriptFetchClientCodegen.NAMESPACE_PARAMETER_INTERFACES, Boolean.FALSE.toString())
|
||||
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
|
||||
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
|
||||
.build();
|
||||
|
12
pom.xml
12
pom.xml
@ -843,6 +843,18 @@
|
||||
<module>samples/client/petstore/typescript-fetch/builds/with-npm-version</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>typescript-fetch-client-builds-namespace-parameter-interfaces</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/client/petstore/typescript-fetch/builds/namespace-parameter-interfaces</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>typescript-angularjs-client</id>
|
||||
<activation>
|
||||
|
4
samples/client/petstore/typescript-fetch/builds/namespace-parameter-interfaces/.gitignore
vendored
Normal file
4
samples/client/petstore/typescript-fetch/builds/namespace-parameter-interfaces/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
wwwroot/*.js
|
||||
node_modules
|
||||
typings
|
||||
dist
|
@ -0,0 +1 @@
|
||||
README.md
|
@ -0,0 +1,23 @@
|
||||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
@ -0,0 +1 @@
|
||||
4.1.1-SNAPSHOT
|
@ -0,0 +1,45 @@
|
||||
## @openapitools/typescript-fetch-petstore@1.0.0
|
||||
|
||||
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
|
||||
|
||||
Environment
|
||||
* Node.js
|
||||
* Webpack
|
||||
* Browserify
|
||||
|
||||
Language level
|
||||
* ES5 - you must have a Promises/A+ library installed
|
||||
* ES6
|
||||
|
||||
Module system
|
||||
* CommonJS
|
||||
* ES6 module system
|
||||
|
||||
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
|
||||
|
||||
### Building
|
||||
|
||||
To build and compile the typescript sources to javascript use:
|
||||
```
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Publishing
|
||||
|
||||
First build the package then run ```npm publish```
|
||||
|
||||
### Consuming
|
||||
|
||||
navigate to the folder of your consuming project and run one of the following commands.
|
||||
|
||||
_published:_
|
||||
|
||||
```
|
||||
npm install @openapitools/typescript-fetch-petstore@1.0.0 --save
|
||||
```
|
||||
|
||||
_unPublished (not recommended):_
|
||||
|
||||
```
|
||||
npm install PATH_TO_GENERATED_PACKAGE --save
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@openapitools/typescript-fetch-petstore",
|
||||
"version": "1.0.0",
|
||||
"description": "OpenAPI client for @openapitools/typescript-fetch-petstore",
|
||||
"author": "OpenAPI-Generator",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts" : {
|
||||
"build": "tsc",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^2.4"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://skimdb.npmjs.com/registry"
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptFetchBuildNamespaceParameterInterfacesPestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch Petstore Client (with namespacing for parameter interfaces)</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-build</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>run</argument>
|
||||
<argument>build</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,431 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import * as runtime from '../runtime';
|
||||
import {
|
||||
ModelApiResponse,
|
||||
ModelApiResponseFromJSON,
|
||||
ModelApiResponseToJSON,
|
||||
Pet,
|
||||
PetFromJSON,
|
||||
PetToJSON,
|
||||
} from '../models';
|
||||
|
||||
/**
|
||||
* Generated request parameter interface declarations (in namespace to avoid collisions).
|
||||
*/
|
||||
export namespace PetRequests {
|
||||
|
||||
export interface AddPet {
|
||||
body: Pet;
|
||||
}
|
||||
|
||||
export interface DeletePet {
|
||||
petId: number;
|
||||
apiKey?: string;
|
||||
}
|
||||
|
||||
export interface FindPetsByStatus {
|
||||
status: Array<FindPetsByStatusStatusEnum>;
|
||||
}
|
||||
|
||||
export interface FindPetsByTags {
|
||||
tags: Array<string>;
|
||||
}
|
||||
|
||||
export interface GetPetById {
|
||||
petId: number;
|
||||
}
|
||||
|
||||
export interface UpdatePet {
|
||||
body: Pet;
|
||||
}
|
||||
|
||||
export interface UpdatePetWithForm {
|
||||
petId: number;
|
||||
name?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface UploadFile {
|
||||
petId: number;
|
||||
additionalMetadata?: string;
|
||||
file?: Blob;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* no description
|
||||
*/
|
||||
export class PetApi extends runtime.BaseAPI {
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*/
|
||||
async addPetRaw(requestParameters: PetRequests.AddPet): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.body === null || requestParameters.body === undefined) {
|
||||
throw new runtime.RequiredError('body','Required parameter requestParameters.body was null or undefined when calling addPet.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
headerParameters['Content-Type'] = 'application/json';
|
||||
|
||||
if (this.configuration && this.configuration.accessToken) {
|
||||
// oauth required
|
||||
if (typeof this.configuration.accessToken === 'function') {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]);
|
||||
} else {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/pet`,
|
||||
method: 'POST',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: PetToJSON(requestParameters.body),
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*/
|
||||
async addPet(requestParameters: PetRequests.AddPet): Promise<void> {
|
||||
await this.addPetRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*/
|
||||
async deletePetRaw(requestParameters: PetRequests.DeletePet): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.petId === null || requestParameters.petId === undefined) {
|
||||
throw new runtime.RequiredError('petId','Required parameter requestParameters.petId was null or undefined when calling deletePet.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (requestParameters.apiKey !== undefined && requestParameters.apiKey !== null) {
|
||||
headerParameters['api_key'] = String(requestParameters.apiKey);
|
||||
}
|
||||
|
||||
if (this.configuration && this.configuration.accessToken) {
|
||||
// oauth required
|
||||
if (typeof this.configuration.accessToken === 'function') {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]);
|
||||
} else {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/pet/{petId}`.replace(`{${"petId"}}`, encodeURIComponent(String(requestParameters.petId))),
|
||||
method: 'DELETE',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*/
|
||||
async deletePet(requestParameters: PetRequests.DeletePet): Promise<void> {
|
||||
await this.deletePetRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* Finds Pets by status
|
||||
*/
|
||||
async findPetsByStatusRaw(requestParameters: PetRequests.FindPetsByStatus): Promise<runtime.ApiResponse<Array<Pet>>> {
|
||||
if (requestParameters.status === null || requestParameters.status === undefined) {
|
||||
throw new runtime.RequiredError('status','Required parameter requestParameters.status was null or undefined when calling findPetsByStatus.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
if (requestParameters.status) {
|
||||
queryParameters['status'] = requestParameters.status.join(runtime.COLLECTION_FORMATS["csv"]);
|
||||
}
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && this.configuration.accessToken) {
|
||||
// oauth required
|
||||
if (typeof this.configuration.accessToken === 'function') {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]);
|
||||
} else {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/pet/findByStatus`,
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(PetFromJSON));
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* Finds Pets by status
|
||||
*/
|
||||
async findPetsByStatus(requestParameters: PetRequests.FindPetsByStatus): Promise<Array<Pet>> {
|
||||
const response = await this.findPetsByStatusRaw(requestParameters);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* Finds Pets by tags
|
||||
*/
|
||||
async findPetsByTagsRaw(requestParameters: PetRequests.FindPetsByTags): Promise<runtime.ApiResponse<Array<Pet>>> {
|
||||
if (requestParameters.tags === null || requestParameters.tags === undefined) {
|
||||
throw new runtime.RequiredError('tags','Required parameter requestParameters.tags was null or undefined when calling findPetsByTags.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
if (requestParameters.tags) {
|
||||
queryParameters['tags'] = requestParameters.tags.join(runtime.COLLECTION_FORMATS["csv"]);
|
||||
}
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && this.configuration.accessToken) {
|
||||
// oauth required
|
||||
if (typeof this.configuration.accessToken === 'function') {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]);
|
||||
} else {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/pet/findByTags`,
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(PetFromJSON));
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* Finds Pets by tags
|
||||
*/
|
||||
async findPetsByTags(requestParameters: PetRequests.FindPetsByTags): Promise<Array<Pet>> {
|
||||
const response = await this.findPetsByTagsRaw(requestParameters);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single pet
|
||||
* Find pet by ID
|
||||
*/
|
||||
async getPetByIdRaw(requestParameters: PetRequests.GetPetById): Promise<runtime.ApiResponse<Pet>> {
|
||||
if (requestParameters.petId === null || requestParameters.petId === undefined) {
|
||||
throw new runtime.RequiredError('petId','Required parameter requestParameters.petId was null or undefined when calling getPetById.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && this.configuration.apiKey) {
|
||||
headerParameters["api_key"] = this.configuration.apiKey("api_key"); // api_key authentication
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/pet/{petId}`.replace(`{${"petId"}}`, encodeURIComponent(String(requestParameters.petId))),
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => PetFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single pet
|
||||
* Find pet by ID
|
||||
*/
|
||||
async getPetById(requestParameters: PetRequests.GetPetById): Promise<Pet> {
|
||||
const response = await this.getPetByIdRaw(requestParameters);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*/
|
||||
async updatePetRaw(requestParameters: PetRequests.UpdatePet): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.body === null || requestParameters.body === undefined) {
|
||||
throw new runtime.RequiredError('body','Required parameter requestParameters.body was null or undefined when calling updatePet.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
headerParameters['Content-Type'] = 'application/json';
|
||||
|
||||
if (this.configuration && this.configuration.accessToken) {
|
||||
// oauth required
|
||||
if (typeof this.configuration.accessToken === 'function') {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]);
|
||||
} else {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/pet`,
|
||||
method: 'PUT',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: PetToJSON(requestParameters.body),
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*/
|
||||
async updatePet(requestParameters: PetRequests.UpdatePet): Promise<void> {
|
||||
await this.updatePetRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*/
|
||||
async updatePetWithFormRaw(requestParameters: PetRequests.UpdatePetWithForm): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.petId === null || requestParameters.petId === undefined) {
|
||||
throw new runtime.RequiredError('petId','Required parameter requestParameters.petId was null or undefined when calling updatePetWithForm.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && this.configuration.accessToken) {
|
||||
// oauth required
|
||||
if (typeof this.configuration.accessToken === 'function') {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]);
|
||||
} else {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
if (requestParameters.name !== undefined) {
|
||||
formData.append('name', requestParameters.name as any);
|
||||
}
|
||||
|
||||
if (requestParameters.status !== undefined) {
|
||||
formData.append('status', requestParameters.status as any);
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/pet/{petId}`.replace(`{${"petId"}}`, encodeURIComponent(String(requestParameters.petId))),
|
||||
method: 'POST',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: formData,
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*/
|
||||
async updatePetWithForm(requestParameters: PetRequests.UpdatePetWithForm): Promise<void> {
|
||||
await this.updatePetWithFormRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*/
|
||||
async uploadFileRaw(requestParameters: PetRequests.UploadFile): Promise<runtime.ApiResponse<ModelApiResponse>> {
|
||||
if (requestParameters.petId === null || requestParameters.petId === undefined) {
|
||||
throw new runtime.RequiredError('petId','Required parameter requestParameters.petId was null or undefined when calling uploadFile.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && this.configuration.accessToken) {
|
||||
// oauth required
|
||||
if (typeof this.configuration.accessToken === 'function') {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]);
|
||||
} else {
|
||||
headerParameters["Authorization"] = this.configuration.accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
if (requestParameters.additionalMetadata !== undefined) {
|
||||
formData.append('additionalMetadata', requestParameters.additionalMetadata as any);
|
||||
}
|
||||
|
||||
if (requestParameters.file !== undefined) {
|
||||
formData.append('file', requestParameters.file as any);
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/pet/{petId}/uploadImage`.replace(`{${"petId"}}`, encodeURIComponent(String(requestParameters.petId))),
|
||||
method: 'POST',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: formData,
|
||||
});
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => ModelApiResponseFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*/
|
||||
async uploadFile(requestParameters: PetRequests.UploadFile): Promise<ModelApiResponse> {
|
||||
const response = await this.uploadFileRaw(requestParameters);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @enum {string}
|
||||
*/
|
||||
export enum FindPetsByStatusStatusEnum {
|
||||
Available = 'available',
|
||||
Pending = 'pending',
|
||||
Sold = 'sold'
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import * as runtime from '../runtime';
|
||||
import {
|
||||
Order,
|
||||
OrderFromJSON,
|
||||
OrderToJSON,
|
||||
} from '../models';
|
||||
|
||||
/**
|
||||
* Generated request parameter interface declarations (in namespace to avoid collisions).
|
||||
*/
|
||||
export namespace StoreRequests {
|
||||
|
||||
export interface DeleteOrder {
|
||||
orderId: string;
|
||||
}
|
||||
|
||||
export interface GetOrderById {
|
||||
orderId: number;
|
||||
}
|
||||
|
||||
export interface PlaceOrder {
|
||||
body: Order;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* no description
|
||||
*/
|
||||
export class StoreApi extends runtime.BaseAPI {
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* Delete purchase order by ID
|
||||
*/
|
||||
async deleteOrderRaw(requestParameters: StoreRequests.DeleteOrder): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.orderId === null || requestParameters.orderId === undefined) {
|
||||
throw new runtime.RequiredError('orderId','Required parameter requestParameters.orderId was null or undefined when calling deleteOrder.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
const response = await this.request({
|
||||
path: `/store/order/{orderId}`.replace(`{${"orderId"}}`, encodeURIComponent(String(requestParameters.orderId))),
|
||||
method: 'DELETE',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* Delete purchase order by ID
|
||||
*/
|
||||
async deleteOrder(requestParameters: StoreRequests.DeleteOrder): Promise<void> {
|
||||
await this.deleteOrderRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of status codes to quantities
|
||||
* Returns pet inventories by status
|
||||
*/
|
||||
async getInventoryRaw(): Promise<runtime.ApiResponse<{ [key: string]: number; }>> {
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && this.configuration.apiKey) {
|
||||
headerParameters["api_key"] = this.configuration.apiKey("api_key"); // api_key authentication
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
path: `/store/inventory`,
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.JSONApiResponse<any>(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of status codes to quantities
|
||||
* Returns pet inventories by status
|
||||
*/
|
||||
async getInventory(): Promise<{ [key: string]: number; }> {
|
||||
const response = await this.getInventoryRaw();
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* Find purchase order by ID
|
||||
*/
|
||||
async getOrderByIdRaw(requestParameters: StoreRequests.GetOrderById): Promise<runtime.ApiResponse<Order>> {
|
||||
if (requestParameters.orderId === null || requestParameters.orderId === undefined) {
|
||||
throw new runtime.RequiredError('orderId','Required parameter requestParameters.orderId was null or undefined when calling getOrderById.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
const response = await this.request({
|
||||
path: `/store/order/{orderId}`.replace(`{${"orderId"}}`, encodeURIComponent(String(requestParameters.orderId))),
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => OrderFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* Find purchase order by ID
|
||||
*/
|
||||
async getOrderById(requestParameters: StoreRequests.GetOrderById): Promise<Order> {
|
||||
const response = await this.getOrderByIdRaw(requestParameters);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*/
|
||||
async placeOrderRaw(requestParameters: StoreRequests.PlaceOrder): Promise<runtime.ApiResponse<Order>> {
|
||||
if (requestParameters.body === null || requestParameters.body === undefined) {
|
||||
throw new runtime.RequiredError('body','Required parameter requestParameters.body was null or undefined when calling placeOrder.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
headerParameters['Content-Type'] = 'application/json';
|
||||
|
||||
const response = await this.request({
|
||||
path: `/store/order`,
|
||||
method: 'POST',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: OrderToJSON(requestParameters.body),
|
||||
});
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => OrderFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*/
|
||||
async placeOrder(requestParameters: StoreRequests.PlaceOrder): Promise<Order> {
|
||||
const response = await this.placeOrderRaw(requestParameters);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,328 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import * as runtime from '../runtime';
|
||||
import {
|
||||
User,
|
||||
UserFromJSON,
|
||||
UserToJSON,
|
||||
} from '../models';
|
||||
|
||||
/**
|
||||
* Generated request parameter interface declarations (in namespace to avoid collisions).
|
||||
*/
|
||||
export namespace UserRequests {
|
||||
|
||||
export interface CreateUser {
|
||||
body: User;
|
||||
}
|
||||
|
||||
export interface CreateUsersWithArrayInput {
|
||||
body: Array<User>;
|
||||
}
|
||||
|
||||
export interface CreateUsersWithListInput {
|
||||
body: Array<User>;
|
||||
}
|
||||
|
||||
export interface DeleteUser {
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface GetUserByName {
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface LoginUser {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface UpdateUser {
|
||||
username: string;
|
||||
body: User;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* no description
|
||||
*/
|
||||
export class UserApi extends runtime.BaseAPI {
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Create user
|
||||
*/
|
||||
async createUserRaw(requestParameters: UserRequests.CreateUser): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.body === null || requestParameters.body === undefined) {
|
||||
throw new runtime.RequiredError('body','Required parameter requestParameters.body was null or undefined when calling createUser.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
headerParameters['Content-Type'] = 'application/json';
|
||||
|
||||
const response = await this.request({
|
||||
path: `/user`,
|
||||
method: 'POST',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: UserToJSON(requestParameters.body),
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Create user
|
||||
*/
|
||||
async createUser(requestParameters: UserRequests.CreateUser): Promise<void> {
|
||||
await this.createUserRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
async createUsersWithArrayInputRaw(requestParameters: UserRequests.CreateUsersWithArrayInput): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.body === null || requestParameters.body === undefined) {
|
||||
throw new runtime.RequiredError('body','Required parameter requestParameters.body was null or undefined when calling createUsersWithArrayInput.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
headerParameters['Content-Type'] = 'application/json';
|
||||
|
||||
const response = await this.request({
|
||||
path: `/user/createWithArray`,
|
||||
method: 'POST',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: requestParameters.body.map(UserToJSON),
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
async createUsersWithArrayInput(requestParameters: UserRequests.CreateUsersWithArrayInput): Promise<void> {
|
||||
await this.createUsersWithArrayInputRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
async createUsersWithListInputRaw(requestParameters: UserRequests.CreateUsersWithListInput): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.body === null || requestParameters.body === undefined) {
|
||||
throw new runtime.RequiredError('body','Required parameter requestParameters.body was null or undefined when calling createUsersWithListInput.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
headerParameters['Content-Type'] = 'application/json';
|
||||
|
||||
const response = await this.request({
|
||||
path: `/user/createWithList`,
|
||||
method: 'POST',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: requestParameters.body.map(UserToJSON),
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
async createUsersWithListInput(requestParameters: UserRequests.CreateUsersWithListInput): Promise<void> {
|
||||
await this.createUsersWithListInputRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Delete user
|
||||
*/
|
||||
async deleteUserRaw(requestParameters: UserRequests.DeleteUser): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.username === null || requestParameters.username === undefined) {
|
||||
throw new runtime.RequiredError('username','Required parameter requestParameters.username was null or undefined when calling deleteUser.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
const response = await this.request({
|
||||
path: `/user/{username}`.replace(`{${"username"}}`, encodeURIComponent(String(requestParameters.username))),
|
||||
method: 'DELETE',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Delete user
|
||||
*/
|
||||
async deleteUser(requestParameters: UserRequests.DeleteUser): Promise<void> {
|
||||
await this.deleteUserRaw(requestParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*/
|
||||
async getUserByNameRaw(requestParameters: UserRequests.GetUserByName): Promise<runtime.ApiResponse<User>> {
|
||||
if (requestParameters.username === null || requestParameters.username === undefined) {
|
||||
throw new runtime.RequiredError('username','Required parameter requestParameters.username was null or undefined when calling getUserByName.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
const response = await this.request({
|
||||
path: `/user/{username}`.replace(`{${"username"}}`, encodeURIComponent(String(requestParameters.username))),
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => UserFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*/
|
||||
async getUserByName(requestParameters: UserRequests.GetUserByName): Promise<User> {
|
||||
const response = await this.getUserByNameRaw(requestParameters);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*/
|
||||
async loginUserRaw(requestParameters: UserRequests.LoginUser): Promise<runtime.ApiResponse<string>> {
|
||||
if (requestParameters.username === null || requestParameters.username === undefined) {
|
||||
throw new runtime.RequiredError('username','Required parameter requestParameters.username was null or undefined when calling loginUser.');
|
||||
}
|
||||
|
||||
if (requestParameters.password === null || requestParameters.password === undefined) {
|
||||
throw new runtime.RequiredError('password','Required parameter requestParameters.password was null or undefined when calling loginUser.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
if (requestParameters.username !== undefined) {
|
||||
queryParameters['username'] = requestParameters.username;
|
||||
}
|
||||
|
||||
if (requestParameters.password !== undefined) {
|
||||
queryParameters['password'] = requestParameters.password;
|
||||
}
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
const response = await this.request({
|
||||
path: `/user/login`,
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.TextApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*/
|
||||
async loginUser(requestParameters: UserRequests.LoginUser): Promise<string> {
|
||||
const response = await this.loginUserRaw(requestParameters);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*/
|
||||
async logoutUserRaw(): Promise<runtime.ApiResponse<void>> {
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
const response = await this.request({
|
||||
path: `/user/logout`,
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*/
|
||||
async logoutUser(): Promise<void> {
|
||||
await this.logoutUserRaw();
|
||||
}
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Updated user
|
||||
*/
|
||||
async updateUserRaw(requestParameters: UserRequests.UpdateUser): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters.username === null || requestParameters.username === undefined) {
|
||||
throw new runtime.RequiredError('username','Required parameter requestParameters.username was null or undefined when calling updateUser.');
|
||||
}
|
||||
|
||||
if (requestParameters.body === null || requestParameters.body === undefined) {
|
||||
throw new runtime.RequiredError('body','Required parameter requestParameters.body was null or undefined when calling updateUser.');
|
||||
}
|
||||
|
||||
const queryParameters: runtime.HTTPQuery = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
headerParameters['Content-Type'] = 'application/json';
|
||||
|
||||
const response = await this.request({
|
||||
path: `/user/{username}`.replace(`{${"username"}}`, encodeURIComponent(String(requestParameters.username))),
|
||||
method: 'PUT',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: UserToJSON(requestParameters.body),
|
||||
});
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Updated user
|
||||
*/
|
||||
async updateUser(requestParameters: UserRequests.UpdateUser): Promise<void> {
|
||||
await this.updateUserRaw(requestParameters);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export * from './PetApi';
|
||||
export * from './StoreApi';
|
||||
export * from './UserApi';
|
@ -0,0 +1,3 @@
|
||||
export * from './runtime';
|
||||
export * from './apis';
|
||||
export * from './models';
|
@ -0,0 +1,52 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { exists, mapValues } from '../runtime';
|
||||
/**
|
||||
* A category for a pet
|
||||
* @export
|
||||
* @interface Category
|
||||
*/
|
||||
export interface Category {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Category
|
||||
*/
|
||||
id?: number;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Category
|
||||
*/
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export function CategoryFromJSON(json: any): Category {
|
||||
return {
|
||||
'id': !exists(json, 'id') ? undefined : json['id'],
|
||||
'name': !exists(json, 'name') ? undefined : json['name'],
|
||||
};
|
||||
}
|
||||
|
||||
export function CategoryToJSON(value?: Category): any {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
'id': value.id,
|
||||
'name': value.name,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,60 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { exists, mapValues } from '../runtime';
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
* @export
|
||||
* @interface ModelApiResponse
|
||||
*/
|
||||
export interface ModelApiResponse {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof ModelApiResponse
|
||||
*/
|
||||
code?: number;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ModelApiResponse
|
||||
*/
|
||||
type?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ModelApiResponse
|
||||
*/
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export function ModelApiResponseFromJSON(json: any): ModelApiResponse {
|
||||
return {
|
||||
'code': !exists(json, 'code') ? undefined : json['code'],
|
||||
'type': !exists(json, 'type') ? undefined : json['type'],
|
||||
'message': !exists(json, 'message') ? undefined : json['message'],
|
||||
};
|
||||
}
|
||||
|
||||
export function ModelApiResponseToJSON(value?: ModelApiResponse): any {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
'code': value.code,
|
||||
'type': value.type,
|
||||
'message': value.message,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,94 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { exists, mapValues } from '../runtime';
|
||||
/**
|
||||
* An order for a pets from the pet store
|
||||
* @export
|
||||
* @interface Order
|
||||
*/
|
||||
export interface Order {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Order
|
||||
*/
|
||||
id?: number;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Order
|
||||
*/
|
||||
petId?: number;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Order
|
||||
*/
|
||||
quantity?: number;
|
||||
/**
|
||||
*
|
||||
* @type {Date}
|
||||
* @memberof Order
|
||||
*/
|
||||
shipDate?: Date;
|
||||
/**
|
||||
* Order Status
|
||||
* @type {string}
|
||||
* @memberof Order
|
||||
*/
|
||||
status?: OrderStatusEnum;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof Order
|
||||
*/
|
||||
complete?: boolean;
|
||||
}
|
||||
|
||||
export function OrderFromJSON(json: any): Order {
|
||||
return {
|
||||
'id': !exists(json, 'id') ? undefined : json['id'],
|
||||
'petId': !exists(json, 'petId') ? undefined : json['petId'],
|
||||
'quantity': !exists(json, 'quantity') ? undefined : json['quantity'],
|
||||
'shipDate': !exists(json, 'shipDate') ? undefined : new Date(json['shipDate']),
|
||||
'status': !exists(json, 'status') ? undefined : json['status'],
|
||||
'complete': !exists(json, 'complete') ? undefined : json['complete'],
|
||||
};
|
||||
}
|
||||
|
||||
export function OrderToJSON(value?: Order): any {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
'id': value.id,
|
||||
'petId': value.petId,
|
||||
'quantity': value.quantity,
|
||||
'shipDate': value.shipDate === undefined ? undefined : value.shipDate.toISOString(),
|
||||
'status': value.status,
|
||||
'complete': value.complete,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @enum {string}
|
||||
*/
|
||||
export enum OrderStatusEnum {
|
||||
Placed = 'placed',
|
||||
Approved = 'approved',
|
||||
Delivered = 'delivered'
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,103 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { exists, mapValues } from '../runtime';
|
||||
import {
|
||||
Category,
|
||||
CategoryFromJSON,
|
||||
CategoryToJSON,
|
||||
Tag,
|
||||
TagFromJSON,
|
||||
TagToJSON,
|
||||
} from './';
|
||||
|
||||
/**
|
||||
* A pet for sale in the pet store
|
||||
* @export
|
||||
* @interface Pet
|
||||
*/
|
||||
export interface Pet {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Pet
|
||||
*/
|
||||
id?: number;
|
||||
/**
|
||||
*
|
||||
* @type {Category}
|
||||
* @memberof Pet
|
||||
*/
|
||||
category?: Category;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Pet
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
*
|
||||
* @type {Array<string>}
|
||||
* @memberof Pet
|
||||
*/
|
||||
photoUrls: Array<string>;
|
||||
/**
|
||||
*
|
||||
* @type {Array<Tag>}
|
||||
* @memberof Pet
|
||||
*/
|
||||
tags?: Array<Tag>;
|
||||
/**
|
||||
* pet status in the store
|
||||
* @type {string}
|
||||
* @memberof Pet
|
||||
*/
|
||||
status?: PetStatusEnum;
|
||||
}
|
||||
|
||||
export function PetFromJSON(json: any): Pet {
|
||||
return {
|
||||
'id': !exists(json, 'id') ? undefined : json['id'],
|
||||
'category': !exists(json, 'category') ? undefined : CategoryFromJSON(json['category']),
|
||||
'name': json['name'],
|
||||
'photoUrls': json['photoUrls'],
|
||||
'tags': !exists(json, 'tags') ? undefined : (json['tags'] as Array<any>).map(TagFromJSON),
|
||||
'status': !exists(json, 'status') ? undefined : json['status'],
|
||||
};
|
||||
}
|
||||
|
||||
export function PetToJSON(value?: Pet): any {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
'id': value.id,
|
||||
'category': CategoryToJSON(value.category),
|
||||
'name': value.name,
|
||||
'photoUrls': value.photoUrls,
|
||||
'tags': value.tags === undefined ? undefined : (value.tags as Array<any>).map(TagToJSON),
|
||||
'status': value.status,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @enum {string}
|
||||
*/
|
||||
export enum PetStatusEnum {
|
||||
Available = 'available',
|
||||
Pending = 'pending',
|
||||
Sold = 'sold'
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { exists, mapValues } from '../runtime';
|
||||
/**
|
||||
* A tag for a pet
|
||||
* @export
|
||||
* @interface Tag
|
||||
*/
|
||||
export interface Tag {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Tag
|
||||
*/
|
||||
id?: number;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Tag
|
||||
*/
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export function TagFromJSON(json: any): Tag {
|
||||
return {
|
||||
'id': !exists(json, 'id') ? undefined : json['id'],
|
||||
'name': !exists(json, 'name') ? undefined : json['name'],
|
||||
};
|
||||
}
|
||||
|
||||
export function TagToJSON(value?: Tag): any {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
'id': value.id,
|
||||
'name': value.name,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,100 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { exists, mapValues } from '../runtime';
|
||||
/**
|
||||
* A User who is purchasing from the pet store
|
||||
* @export
|
||||
* @interface User
|
||||
*/
|
||||
export interface User {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof User
|
||||
*/
|
||||
id?: number;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof User
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof User
|
||||
*/
|
||||
firstName?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof User
|
||||
*/
|
||||
lastName?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof User
|
||||
*/
|
||||
email?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof User
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof User
|
||||
*/
|
||||
phone?: string;
|
||||
/**
|
||||
* User Status
|
||||
* @type {number}
|
||||
* @memberof User
|
||||
*/
|
||||
userStatus?: number;
|
||||
}
|
||||
|
||||
export function UserFromJSON(json: any): User {
|
||||
return {
|
||||
'id': !exists(json, 'id') ? undefined : json['id'],
|
||||
'username': !exists(json, 'username') ? undefined : json['username'],
|
||||
'firstName': !exists(json, 'firstName') ? undefined : json['firstName'],
|
||||
'lastName': !exists(json, 'lastName') ? undefined : json['lastName'],
|
||||
'email': !exists(json, 'email') ? undefined : json['email'],
|
||||
'password': !exists(json, 'password') ? undefined : json['password'],
|
||||
'phone': !exists(json, 'phone') ? undefined : json['phone'],
|
||||
'userStatus': !exists(json, 'userStatus') ? undefined : json['userStatus'],
|
||||
};
|
||||
}
|
||||
|
||||
export function UserToJSON(value?: User): any {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
'id': value.id,
|
||||
'username': value.username,
|
||||
'firstName': value.firstName,
|
||||
'lastName': value.lastName,
|
||||
'email': value.email,
|
||||
'password': value.password,
|
||||
'phone': value.phone,
|
||||
'userStatus': value.userStatus,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
export * from './Category';
|
||||
export * from './ModelApiResponse';
|
||||
export * from './Order';
|
||||
export * from './Pet';
|
||||
export * from './Tag';
|
||||
export * from './User';
|
@ -0,0 +1,302 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
||||
|
||||
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
|
||||
|
||||
/**
|
||||
* This is the base class for all generated API classes.
|
||||
*/
|
||||
export class BaseAPI {
|
||||
|
||||
private middleware: Middleware[];
|
||||
|
||||
constructor(protected configuration = new Configuration()) {
|
||||
this.middleware = configuration.middleware;
|
||||
}
|
||||
|
||||
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
|
||||
const next = this.clone<T>();
|
||||
next.middleware = next.middleware.concat(...middlewares);
|
||||
return next;
|
||||
}
|
||||
|
||||
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
|
||||
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
||||
return this.withMiddleware<T>(...middlewares);
|
||||
}
|
||||
|
||||
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
|
||||
const middlewares = postMiddlewares.map((post) => ({ post }));
|
||||
return this.withMiddleware<T>(...middlewares);
|
||||
}
|
||||
|
||||
protected async request(context: RequestOpts): Promise<Response> {
|
||||
const { url, init } = this.createFetchParams(context);
|
||||
const response = await this.fetchApi(url, init);
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response;
|
||||
}
|
||||
throw response;
|
||||
}
|
||||
|
||||
private createFetchParams(context: RequestOpts) {
|
||||
let url = this.configuration.basePath + context.path;
|
||||
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
||||
// only add the querystring to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a "?" character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
url += '?' + this.configuration.queryParamsStringify(context.query);
|
||||
}
|
||||
const body = (context.body instanceof FormData || isBlob(context.body))
|
||||
? context.body
|
||||
: JSON.stringify(context.body);
|
||||
|
||||
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
||||
const init = {
|
||||
method: context.method,
|
||||
headers: headers,
|
||||
body,
|
||||
credentials: this.configuration.credentials
|
||||
};
|
||||
return { url, init };
|
||||
}
|
||||
|
||||
private fetchApi = async (url: string, init: RequestInit) => {
|
||||
let fetchParams = { url, init };
|
||||
for (const middleware of this.middleware) {
|
||||
if (middleware.pre) {
|
||||
fetchParams = await middleware.pre({
|
||||
fetch: this.fetchApi,
|
||||
...fetchParams,
|
||||
}) || fetchParams;
|
||||
}
|
||||
}
|
||||
let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init);
|
||||
for (const middleware of this.middleware) {
|
||||
if (middleware.post) {
|
||||
response = await middleware.post({
|
||||
fetch: this.fetchApi,
|
||||
url,
|
||||
init,
|
||||
response: response.clone(),
|
||||
}) || response;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shallow clone of `this` by constructing a new instance
|
||||
* and then shallow cloning data members.
|
||||
*/
|
||||
private clone<T extends BaseAPI>(this: T): T {
|
||||
const constructor = this.constructor as any;
|
||||
const next = new constructor(this.configuration);
|
||||
next.middleware = this.middleware.slice();
|
||||
return next;
|
||||
}
|
||||
};
|
||||
|
||||
export class RequiredError extends Error {
|
||||
name: "RequiredError" = "RequiredError";
|
||||
constructor(public field: string, msg?: string) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
export const COLLECTION_FORMATS = {
|
||||
csv: ",",
|
||||
ssv: " ",
|
||||
tsv: "\t",
|
||||
pipes: "|",
|
||||
};
|
||||
|
||||
export type FetchAPI = GlobalFetch['fetch'];
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
basePath?: string; // override base path
|
||||
fetchApi?: FetchAPI; // override for fetch implementation
|
||||
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
||||
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
|
||||
username?: string; // parameter for basic security
|
||||
password?: string; // parameter for basic security
|
||||
apiKey?: string | ((name: string) => string); // parameter for apiKey security
|
||||
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
|
||||
headers?: HTTPHeaders; //header params we want to use on every request
|
||||
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
constructor(private configuration: ConfigurationParameters = {}) {}
|
||||
|
||||
get basePath(): string {
|
||||
return this.configuration.basePath || BASE_PATH;
|
||||
}
|
||||
|
||||
get fetchApi(): FetchAPI {
|
||||
return this.configuration.fetchApi || window.fetch.bind(window);
|
||||
}
|
||||
|
||||
get middleware(): Middleware[] {
|
||||
return this.configuration.middleware || [];
|
||||
}
|
||||
|
||||
get queryParamsStringify(): (params: HTTPQuery) => string {
|
||||
return this.configuration.queryParamsStringify || querystring;
|
||||
}
|
||||
|
||||
get username(): string | undefined {
|
||||
return this.configuration.username;
|
||||
}
|
||||
|
||||
get password(): string | undefined {
|
||||
return this.configuration.password;
|
||||
}
|
||||
|
||||
get apiKey(): ((name: string) => string) | undefined {
|
||||
const apiKey = this.configuration.apiKey;
|
||||
if (apiKey) {
|
||||
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
|
||||
const accessToken = this.configuration.accessToken;
|
||||
if (accessToken) {
|
||||
return typeof accessToken === 'function' ? accessToken : () => accessToken;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
get headers(): HTTPHeaders | undefined {
|
||||
return this.configuration.headers;
|
||||
}
|
||||
|
||||
get credentials(): RequestCredentials | undefined {
|
||||
return this.configuration.credentials;
|
||||
}
|
||||
}
|
||||
|
||||
export type Json = any;
|
||||
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
|
||||
export type HTTPHeaders = { [key: string]: string };
|
||||
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | HTTPQuery };
|
||||
export type HTTPBody = Json | FormData;
|
||||
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
|
||||
|
||||
export interface FetchParams {
|
||||
url: string;
|
||||
init: RequestInit;
|
||||
}
|
||||
|
||||
export interface RequestOpts {
|
||||
path: string;
|
||||
method: HTTPMethod;
|
||||
headers: HTTPHeaders;
|
||||
query?: HTTPQuery;
|
||||
body?: HTTPBody;
|
||||
}
|
||||
|
||||
export function exists(json: any, key: string) {
|
||||
const value = json[key];
|
||||
return value !== null && value !== undefined;
|
||||
}
|
||||
|
||||
export function querystring(params: HTTPQuery, prefix: string = ''): string {
|
||||
return Object.keys(params)
|
||||
.map((key) => {
|
||||
const fullKey = prefix + (prefix.length ? `[${key}]` : key);
|
||||
const value = params[key];
|
||||
if (value instanceof Array) {
|
||||
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
||||
.join(`&${encodeURIComponent(fullKey)}=`);
|
||||
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
||||
}
|
||||
if (value instanceof Object) {
|
||||
return querystring(value as HTTPQuery, fullKey);
|
||||
}
|
||||
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
||||
})
|
||||
.filter(part => part.length > 0)
|
||||
.join('&');
|
||||
}
|
||||
|
||||
export function mapValues(data: any, fn: (item: any) => any) {
|
||||
return Object.keys(data).reduce(
|
||||
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
export interface RequestContext {
|
||||
fetch: FetchAPI;
|
||||
url: string;
|
||||
init: RequestInit;
|
||||
}
|
||||
|
||||
export interface ResponseContext {
|
||||
fetch: FetchAPI;
|
||||
url: string;
|
||||
init: RequestInit;
|
||||
response: Response;
|
||||
}
|
||||
|
||||
export interface Middleware {
|
||||
pre?(context: RequestContext): Promise<FetchParams | void>;
|
||||
post?(context: ResponseContext): Promise<Response | void>;
|
||||
}
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
raw: Response;
|
||||
value(): Promise<T>;
|
||||
}
|
||||
|
||||
export interface ResponseTransformer<T> {
|
||||
(json: any): T;
|
||||
}
|
||||
|
||||
export class JSONApiResponse<T> {
|
||||
constructor(public raw: Response, private transformer: ResponseTransformer<T> = (jsonValue: any) => jsonValue) {}
|
||||
|
||||
async value() {
|
||||
return this.transformer(await this.raw.json());
|
||||
}
|
||||
}
|
||||
|
||||
export class VoidApiResponse {
|
||||
constructor(public raw: Response) {}
|
||||
|
||||
async value() {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class BlobApiResponse {
|
||||
constructor(public raw: Response) {}
|
||||
|
||||
async value() {
|
||||
return await this.raw.blob();
|
||||
};
|
||||
}
|
||||
|
||||
export class TextApiResponse {
|
||||
constructor(public raw: Response) {}
|
||||
|
||||
async value() {
|
||||
return await this.raw.text();
|
||||
};
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "dist",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
]
|
||||
},
|
||||
"exclude": [
|
||||
"dist",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user