[typescript][typescript-node] Serialize/deserialize maps and nullable types correctly (#19362)

* Remove deprecated suppressImplicitAnyIndexErrors property from templates

* Add encoding / decoding tests for the typescript generator

* Add encoding / decoding tests for the typescript-node generator

* [Typescript][Typescript Node] fix deserializing complex types

This fixes deserializing of models that are composed with null,
undefined, or are inside of a map.

* Use more sensible `startsWith` implementation

* Remove use of magic number offsets

* Fix endsWith bounds checking

* Regenerate samples
This commit is contained in:
Simon Abbott 2024-09-25 13:21:11 -05:00 committed by GitHub
parent 9147e998ff
commit a6581e8e4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
89 changed files with 14438 additions and 143 deletions

View File

@ -0,0 +1,37 @@
name: TypeScript Client (Encoding / Decoding Test)
on:
pull_request:
paths:
- samples/client/others/typescript/encode-decode/**
- .github/workflows/samples-typescript-encode-decode.yaml
jobs:
build:
name: Test TypeScript Encoding / Decoding
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
# clients
- samples/client/others/typescript/encode-decode/test
node-version:
- 16
- 18
- 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
working-directory: ${{ matrix.sample }}
run: |
npm run preinstall
npm i
- name: Test
working-directory: ${{ matrix.sample }}
run: npm test

View File

@ -0,0 +1,37 @@
name: TypeScript Node Client (Encoding / Decoding Test)
on:
pull_request:
paths:
- samples/client/others/typescript-node/encode-decode/**
- .github/workflows/samples-typescript-node-encode-decode.yaml
jobs:
build:
name: Test TypeScript Node Encoding / Decoding
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
# clients
- samples/client/others/typescript-node/encode-decode/test
node-version:
- 16
- 18
- 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
working-directory: ${{ matrix.sample }}
run: |
npm run preinstall
npm i
- name: Test
working-directory: ${{ matrix.sample }}
run: npm test

View File

@ -0,0 +1,11 @@
generatorName: typescript
outputDir: samples/client/others/typescript/encode-decode/build
inputSpec: modules/openapi-generator/src/test/resources/3_1/encode-decode.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript
additionalProperties:
artifactId: encode-decode-typescript
hideGenerationTimestamp: "true"
npmVersion: 1.0.0
npmName: '@openapitools/typescript-encode-decode'
nullSafeAdditionalProps: true
platform: node

View File

@ -0,0 +1,10 @@
generatorName: typescript-node
outputDir: samples/client/others/typescript-node/encode-decode/build
inputSpec: modules/openapi-generator/src/test/resources/3_1/encode-decode.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-node
additionalProperties:
artifactId: encode-decode-typescript-node
hideGenerationTimestamp: "true"
npmVersion: 1.0.0
npmName: '@openapitools/typescript-node-encode-decode'
nullSafeAdditionalProps: true

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}es5{{/supportsES6}}",
"module": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}commonjs{{/supportsES6}}",
"moduleResolution": "node",

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}es5{{/supportsES6}}",
"module": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}commonjs{{/supportsES6}}",
"moduleResolution": "node",

View File

@ -2,7 +2,6 @@
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
"moduleResolution": "node",
"removeComments": true,

View File

@ -68,6 +68,23 @@ let typeMap: {[index: string]: any} = {
{{/models}}
}
// Check if a string starts with another string without using es6 features
function startsWith(str: string, match: string): boolean {
return str.substring(0, match.length) === match;
}
// Check if a string ends with another string without using es6 features
function endsWith(str: string, match: string): boolean {
return str.length >= match.length && str.substring(str.length - match.length) === match;
}
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -104,20 +121,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string) {
public static serialize(data: any, type: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (endsWith(type, nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType);
} else if (endsWith(type, optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType);
} else if (startsWith(type, arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.serialize(datum, subType));
}
return transformedData;
} else if (startsWith(type, mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
);
}
return transformedData;
} else if (type === "Date") {
return data.toISOString();
} else {
@ -142,22 +174,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string) {
public static deserialize(data: any, type: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (endsWith(type, nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType);
} else if (endsWith(type, optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType);
} else if (startsWith(type, arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.deserialize(datum, subType));
}
return transformedData;
} else if (startsWith(type, mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -2,7 +2,6 @@
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,

View File

@ -101,6 +101,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -140,19 +147,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -185,21 +208,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -0,0 +1,401 @@
openapi: 3.1.0
info:
title: 'Encoding / Decoding Test'
description: 'A spec to ensure encoding and decoding of types (both primitive and compound) works as expected'
version: latest
paths:
/test/decode/primitive/boolean:
get:
responses:
'200':
description: 'Decodes a boolean'
content:
application/json:
schema:
type: boolean
/test/decode/primitive/integer:
get:
responses:
'200':
description: 'Decodes an integer'
content:
application/json:
schema:
type: integer
/test/decode/primitive/number:
get:
responses:
'200':
description: 'Decodes a number'
content:
application/json:
schema:
type: number
/test/decode/primitive/string:
get:
responses:
'200':
description: 'Decodes a string'
content:
application/json:
schema:
type: string
/test/decode/nullable:
get:
responses:
'200':
description: 'Decodes a nullable type'
content:
application/json:
schema:
type: [string, 'null']
/test/decode/array-of:
get:
responses:
'200':
description: 'Decodes an array of primitive types'
content:
application/json:
schema:
type: array
items:
type: string
/test/decode/array-of/nullable:
get:
responses:
'200':
description: 'Decodes an array of nullable types'
content:
application/json:
schema:
type: array
items:
type: [string, 'null']
/test/decode/nullable-array:
get:
responses:
'200':
description: 'Decodes a nullable array'
content:
application/json:
schema:
type: [array, 'null']
items:
type: string
/test/decode/array-of-arrays:
get:
responses:
'200':
description: 'Decodes an array of arrays'
content:
application/json:
schema:
type: array
items:
type: array
items:
type: string
/test/decode/object:
get:
responses:
'200':
description: 'Decodes an object'
content:
application/json:
schema:
$ref: '#/components/schemas/ComplexObject'
/test/decode/map-of/primitive:
get:
responses:
'200':
description: 'Decodes a map of primitive types'
content:
application/json:
schema:
type: object
additionalProperties:
type: string
/test/decode/map-of/objects:
get:
responses:
'200':
description: 'Decodes a map of objects'
content:
application/json:
schema:
type: object
additionalProperties:
$ref: '#/components/schemas/ComplexObject'
/test/decode/map-of/maps-of/objects:
get:
responses:
'200':
description: 'Decodes a map of maps of objects'
content:
application/json:
schema:
type: object
additionalProperties:
type: object
additionalProperties:
$ref: '#/components/schemas/ComplexObject'
/test/decode/array-of/maps-of/objects:
get:
responses:
'200':
description: 'Decodes an array of maps of complex objects'
content:
application/json:
schema:
type: array
items:
type: object
additionalProperties:
$ref: '#/components/schemas/ComplexObject'
/test/decode/array-of/nullable-objects:
get:
responses:
'200':
description: 'Decodes an array of nullable objects'
content:
application/json:
schema:
type: array
items:
oneOf:
- $ref: '#/components/schemas/ComplexObject'
- type: 'null'
/test/decode/composite-objects:
get:
responses:
'200':
description: 'Decodes a composite object'
content:
application/json:
schema:
$ref: '#/components/schemas/CompositeObject'
/test/encode/primitive/boolean:
post:
requestBody:
required: true
content:
application/json:
schema:
type: boolean
responses:
'200':
description: 'Encodes a boolean'
/test/encode/primitive/integer:
post:
requestBody:
required: true
content:
application/json:
schema:
type: integer
responses:
'200':
description: 'Encodes an integer'
/test/encode/primitive/number:
post:
requestBody:
required: true
content:
application/json:
schema:
type: number
responses:
'200':
description: 'Encodes a number'
/test/encode/primitive/string:
post:
requestBody:
required: true
content:
application/json:
schema:
type: string
responses:
'200':
description: 'Encodes a string'
/test/encode/nullable:
post:
requestBody:
required: false
content:
application/json:
schema:
type: [string, 'null']
responses:
'200':
description: 'Encodes a nullable type'
/test/encode/array-of:
post:
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: string
responses:
'200':
description: 'Encodes an array of primitive types'
/test/encode/array-of/nullable:
post:
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: [string, 'null']
responses:
'200':
description: 'Encodes an array of nullable types'
/test/encode/nullable-array:
post:
requestBody:
required: false
content:
application/json:
schema:
type: [array, 'null']
items:
type: string
responses:
'200':
description: 'Encodes a nullable array'
/test/encode/array-of-arrays:
post:
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: array
items:
type: string
responses:
'200':
description: 'Encodes an array of arrays'
/test/encode/object:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ComplexObject'
responses:
'200':
description: 'Encodes an object'
/test/encode/map-of/primitive:
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
additionalProperties:
type: string
responses:
'200':
description: 'Encodes a map of primitive types'
/test/encode/map-of/objects:
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
additionalProperties:
$ref: '#/components/schemas/ComplexObject'
responses:
'200':
description: 'Encodes a map of objects'
/test/encode/map-of/maps-of/objects:
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
additionalProperties:
type: object
additionalProperties:
$ref: '#/components/schemas/ComplexObject'
responses:
'200':
description: 'Encodes a map of maps of objects'
/test/encode/array-of/maps-of/objects:
post:
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: object
additionalProperties:
$ref: '#/components/schemas/ComplexObject'
responses:
'200':
description: 'Encodes an array of maps of complex objects'
/test/encode/array-of/nullable-objects:
post:
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
oneOf:
- $ref: '#/components/schemas/ComplexObject'
- type: 'null'
responses:
'200':
description: 'Encodes an array of nullable objects'
/test/encode/composite-objects:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CompositeObject'
responses:
'200':
description: 'Encodes a composite object'
components:
schemas:
ComplexObject:
type: object
required:
- required_property
- required_nullable_property
properties:
required_property:
type: string
required_nullable_property:
type: [string, 'null']
optional_property:
type: string
optional_nullable_property:
type: [string, 'null']
CompositeObject:
type: object
properties:
optional_nullable_inner_object:
oneOf:
- $ref: '#/components/schemas/ComplexObject'
- type: 'null'

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",

View File

@ -2,7 +2,6 @@
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "ES5",
"moduleResolution": "node",
"removeComments": true,

View File

@ -2,7 +2,6 @@
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "ES5",
"strict": true,
"moduleResolution": "node",

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",

View File

@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist

View File

@ -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

View File

@ -0,0 +1,10 @@
.gitignore
api.ts
api/apis.ts
api/defaultApi.ts
git_push.sh
model/complexObject.ts
model/compositeObject.ts
model/models.ts
package.json
tsconfig.json

View File

@ -0,0 +1,3 @@
// This is the entrypoint for the package
export * from './api/apis';
export * from './model/models';

View File

@ -0,0 +1,14 @@
export * from './defaultApi';
import { DefaultApi } from './defaultApi';
import * as http from 'http';
export class HttpError extends Error {
constructor (public response: http.IncomingMessage, public body: any, public statusCode?: number) {
super('HTTP request failed');
this.name = 'HttpError';
}
}
export { RequestFile } from '../model/models';
export const APIS = [DefaultApi];

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
git_user_id=$1
git_repo_id=$2
release_note=$3
git_host=$4
if [ "$git_host" = "" ]; then
git_host="github.com"
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
fi
if [ "$git_user_id" = "" ]; then
git_user_id="GIT_USER_ID"
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi
if [ "$git_repo_id" = "" ]; then
git_repo_id="GIT_REPO_ID"
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi
if [ "$release_note" = "" ]; then
release_note="Minor update"
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi
# Initialize the local directory as a Git repository
git init
# Adds the files in the local repository and stages them for commit.
git add .
# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"
# Sets the new remote
git_remote=$(git remote)
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
fi
fi
git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'

View File

@ -0,0 +1,49 @@
/**
* Encoding / Decoding Test
* A spec to ensure encoding and decoding of types (both primitive and compound) works as expected
*
* The version of the OpenAPI document: latest
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { RequestFile } from './models';
export class ComplexObject {
'requiredProperty': string;
'requiredNullableProperty': string | null;
'optionalProperty'?: string;
'optionalNullableProperty'?: string | null;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "requiredProperty",
"baseName": "required_property",
"type": "string"
},
{
"name": "requiredNullableProperty",
"baseName": "required_nullable_property",
"type": "string"
},
{
"name": "optionalProperty",
"baseName": "optional_property",
"type": "string"
},
{
"name": "optionalNullableProperty",
"baseName": "optional_nullable_property",
"type": "string"
} ];
static getAttributeTypeMap() {
return ComplexObject.attributeTypeMap;
}
}

View File

@ -0,0 +1,32 @@
/**
* Encoding / Decoding Test
* A spec to ensure encoding and decoding of types (both primitive and compound) works as expected
*
* The version of the OpenAPI document: latest
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { RequestFile } from './models';
import { ComplexObject } from './complexObject';
export class CompositeObject {
'optionalNullableInnerObject'?: ComplexObject | null;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "optionalNullableInnerObject",
"baseName": "optional_nullable_inner_object",
"type": "ComplexObject"
} ];
static getAttributeTypeMap() {
return CompositeObject.attributeTypeMap;
}
}

View File

@ -0,0 +1,272 @@
import localVarRequest from 'request';
export * from './complexObject';
export * from './compositeObject';
import * as fs from 'fs';
export interface RequestDetailedFile {
value: Buffer;
options?: {
filename?: string;
contentType?: string;
}
}
export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
import { ComplexObject } from './complexObject';
import { CompositeObject } from './compositeObject';
/* tslint:disable:no-unused-variable */
let primitives = [
"string",
"boolean",
"double",
"integer",
"long",
"float",
"number",
"any"
];
let enumsMap: {[index: string]: any} = {
}
let typeMap: {[index: string]: any} = {
"ComplexObject": ComplexObject,
"CompositeObject": CompositeObject,
}
// Check if a string starts with another string without using es6 features
function startsWith(str: string, match: string): boolean {
return str.substring(0, match.length) === match;
}
// Check if a string ends with another string without using es6 features
function endsWith(str: string, match: string): boolean {
return str.length >= match.length && str.substring(str.length - match.length) === match;
}
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
return expectedType;
} else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) {
return expectedType;
} else if (expectedType === "Date") {
return expectedType;
} else {
if (enumsMap[expectedType]) {
return expectedType;
}
if (!typeMap[expectedType]) {
return expectedType; // w/e we don't know the type
}
// Check the discriminator
let discriminatorProperty = typeMap[expectedType].discriminator;
if (discriminatorProperty == null) {
return expectedType; // the type does not have a discriminator. use it.
} else {
if (data[discriminatorProperty]) {
var discriminatorType = data[discriminatorProperty];
if(typeMap[discriminatorType]){
return discriminatorType; // use the type given in the discriminator
} else {
return expectedType; // discriminator did not map to a type
}
} else {
return expectedType; // discriminator was not present (or an empty string)
}
}
}
}
public static serialize(data: any, type: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (endsWith(type, nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType);
} else if (endsWith(type, optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType);
} else if (startsWith(type, arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.serialize(datum, subType));
}
return transformedData;
} else if (startsWith(type, mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
);
}
return transformedData;
} else if (type === "Date") {
return data.toISOString();
} else {
if (enumsMap[type]) {
return data;
}
if (!typeMap[type]) { // in case we dont know the type
return data;
}
// Get the actual type of this object
type = this.findCorrectType(data, type);
// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance: {[index: string]: any} = {};
for (let index = 0; index < attributeTypes.length; index++) {
let attributeType = attributeTypes[index];
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
}
return instance;
}
}
public static deserialize(data: any, type: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (endsWith(type, nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType);
} else if (endsWith(type, optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType);
} else if (startsWith(type, arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.deserialize(datum, subType));
}
return transformedData;
} else if (startsWith(type, mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {
if (enumsMap[type]) {// is Enum
return data;
}
if (!typeMap[type]) { // dont know the type
return data;
}
let instance = new typeMap[type]();
let attributeTypes = typeMap[type].getAttributeTypeMap();
for (let index = 0; index < attributeTypes.length; index++) {
let attributeType = attributeTypes[index];
instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type);
}
return instance;
}
}
}
export interface Authentication {
/**
* Apply authentication settings to header and query params.
*/
applyToRequest(requestOptions: localVarRequest.Options): Promise<void> | void;
}
export class HttpBasicAuth implements Authentication {
public username: string = '';
public password: string = '';
applyToRequest(requestOptions: localVarRequest.Options): void {
requestOptions.auth = {
username: this.username, password: this.password
}
}
}
export class HttpBearerAuth implements Authentication {
public accessToken: string | (() => string) = '';
applyToRequest(requestOptions: localVarRequest.Options): void {
if (requestOptions && requestOptions.headers) {
const accessToken = typeof this.accessToken === 'function'
? this.accessToken()
: this.accessToken;
requestOptions.headers["Authorization"] = "Bearer " + accessToken;
}
}
}
export class ApiKeyAuth implements Authentication {
public apiKey: string = '';
constructor(private location: string, private paramName: string) {
}
applyToRequest(requestOptions: localVarRequest.Options): void {
if (this.location == "query") {
(<any>requestOptions.qs)[this.paramName] = this.apiKey;
} else if (this.location == "header" && requestOptions && requestOptions.headers) {
requestOptions.headers[this.paramName] = this.apiKey;
} else if (this.location == 'cookie' && requestOptions && requestOptions.headers) {
if (requestOptions.headers['Cookie']) {
requestOptions.headers['Cookie'] += '; ' + this.paramName + '=' + encodeURIComponent(this.apiKey);
}
else {
requestOptions.headers['Cookie'] = this.paramName + '=' + encodeURIComponent(this.apiKey);
}
}
}
}
export class OAuth implements Authentication {
public accessToken: string = '';
applyToRequest(requestOptions: localVarRequest.Options): void {
if (requestOptions && requestOptions.headers) {
requestOptions.headers["Authorization"] = "Bearer " + this.accessToken;
}
}
}
export class VoidAuth implements Authentication {
public username: string = '';
public password: string = '';
applyToRequest(_: localVarRequest.Options): void {
// Do nothing
}
}
export type Interceptor = (requestOptions: localVarRequest.Options) => (Promise<void> | void);

View File

@ -0,0 +1,28 @@
{
"name": "@openapitools/typescript-node-encode-decode",
"version": "1.0.0",
"description": "NodeJS client for @openapitools/typescript-node-encode-decode",
"repository": {
"type": "git",
"url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
},
"main": "dist/api.js",
"types": "dist/api.d.ts",
"scripts": {
"clean": "rm -Rf node_modules/ *.js",
"build": "tsc",
"test": "npm run build && node dist/client.js"
},
"author": "OpenAPI-Generator Contributors",
"license": "Unlicense",
"dependencies": {
"bluebird": "^3.7.2",
"request": "^2.88.2"
},
"devDependencies": {
"@types/bluebird": "^3.5.33",
"@types/node": "^12",
"@types/request": "^2.48.8",
"typescript": "^4.0 || ^5.0"
}
}

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"target": "ES5",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strict": true,
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"noLib": false,
"declaration": true,
"lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"],
"outDir": "dist",
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"dist",
"node_modules"
]
}

View File

@ -0,0 +1,2 @@
dist
node_modules

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
{
"private": true,
"dependencies": {
"@openapitools/typescript-node-encode-decode": "file:../build",
"@types/chai": "^4.3.0",
"@types/mocha": "^10.0.0",
"@types/node": "^16.6.2",
"chai": "^4.3.0",
"nock": "^13.5.4",
"mocha": "^10.2.0",
"ts-node": "^10.9.0",
"typescript": "^5.2.2"
},
"scripts": {
"preinstall": "npm --prefix ../build install && npm --prefix ../build run build",
"test": "mocha test/*.spec.ts --require ts-node/register --timeout 10000"
},
"name": "typescript-node-encode-decode-test",
"version": "1.0.0",
"directories": {
"test": "test"
},
"author": "",
"license": "ISC",
"description": ""
}

View File

@ -0,0 +1,425 @@
import {
DefaultApi,
} from '@openapitools/typescript-node-encode-decode';
import { expect } from 'chai';
import { BASE_URL, encodeMock } from './server';
const api = new DefaultApi(BASE_URL);
describe('deserialization', () => {
it('deserializes primitive booleans', async () => {
const { body: response } = await api.testDecodePrimitiveBooleanGet();
expect(response).to.be.true;
});
it('deserializes primitive integers', async () => {
const { body: response } = await api.testDecodePrimitiveIntegerGet();
expect(response).to.equal(42);
});
it('deserializes primitive numbers', async () => {
const { body: response } = await api.testDecodePrimitiveNumberGet();
expect(response).to.equal(42.42);
});
it('deserializes primitive strings', async () => {
const { body: response } = await api.testDecodePrimitiveStringGet();
expect(response).to.equal('some string value');
});
it('deserializes nullable strings', async () => {
const { body: response } = await api.testDecodeNullableGet();
expect(response).to.equal(null);
});
it('deserializes arrays of strings', async () => {
const { body: response } = await api.testDecodeArrayOfGet();
expect(response).to.deep.equal(["first", "second", "third"]);
});
it('deserializes arrays of nullable strings', async () => {
const { body: response } = await api.testDecodeArrayOfNullableGet();
expect(response).to.deep.equal(["first", null, "third"]);
});
it('deserializes nullable arrays', async () => {
const { body: response } = await api.testDecodeNullableArrayGet();
expect(response).to.equal(null);
});
it('deserializes arrays of arrays', async () => {
const { body: response } = await api.testDecodeArrayOfArraysGet();
expect(response).to.deep.equal([["first", "second"], ["third"]]);
});
it('deserializes objects', async () => {
const { body: response } = await api.testDecodeObjectGet();
expect(response).to.deep.equal({
requiredProperty: "required",
optionalProperty: undefined,
requiredNullableProperty: null,
optionalNullableProperty: null,
});
});
it('deserializes maps of primitives', async () => {
const { body: response } = await api.testDecodeMapOfPrimitiveGet();
expect(response).to.deep.equal({
key1: "value1",
key2: "value2",
});
});
it('deserializes maps of objects', async () => {
const { body: response } = await api.testDecodeMapOfObjectsGet();
expect(response).to.deep.equal({
barebones: {
requiredProperty: "first",
requiredNullableProperty: null,
optionalProperty: undefined,
optionalNullableProperty: undefined,
},
nulls: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalProperty: undefined,
optionalNullableProperty: null,
},
values: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
});
});
it('deserializes maps of maps of objects', async () => {
const { body: response } = await api.testDecodeMapOfMapsOfObjectsGet();
expect(response).to.deep.equal({
key1: {
key1: {
requiredProperty: "first",
requiredNullableProperty: null,
optionalProperty: undefined,
optionalNullableProperty: undefined,
},
key2: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalProperty: undefined,
optionalNullableProperty: null,
},
},
key2: {
key3: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
}
});
});
it('deserializes arrays of maps of objects', async () => {
const { body: response } = await api.testDecodeArrayOfMapsOfObjectsGet();
expect(response).to.deep.equal([
{
key1: {
requiredProperty: "first",
requiredNullableProperty: null,
optionalProperty: undefined,
optionalNullableProperty: undefined,
},
key2: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalProperty: undefined,
optionalNullableProperty: null,
},
},
{
key3: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
}
]);
});
it('deserializes arrays of nullable objects', async () => {
const { body: response } = await api.testDecodeArrayOfNullableObjectsGet();
expect(response).to.deep.equal([
{
requiredProperty: "first",
requiredNullableProperty: null,
optionalProperty: undefined,
optionalNullableProperty: undefined,
},
null,
{
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
]);
});
it('deserializes composite objects', async () => {
const { body: response } = await api.testDecodeCompositeObjectsGet();
expect(response).to.deep.equal({
optionalNullableInnerObject: {
requiredProperty: "required",
requiredNullableProperty: null,
optionalProperty: undefined,
optionalNullableProperty: undefined,
},
});
});
});
describe("serialization", () => {
it("serializes primitive booleans", async () => {
await api.testEncodePrimitiveBooleanPost(true);
expect(encodeMock.lastRequestBody).to.equal(true);
});
it("serializes primitive integers", async () => {
await api.testEncodePrimitiveIntegerPost(42);
expect(encodeMock.lastRequestBody).to.equal(42);
});
it("serializes primitive numbers", async () => {
await api.testEncodePrimitiveNumberPost(42.42);
expect(encodeMock.lastRequestBody).to.equal(42.42);
});
it("serializes primitive strings", async () => {
await api.testEncodePrimitiveStringPost("some string value");
expect(encodeMock.lastRequestBody).to.equal("some string value");
});
it("serializes nullable strings", async () => {
await api.testEncodeNullablePost(null);
expect(encodeMock.lastRequestBody).to.equal(null);
});
it("serializes arrays of strings", async () => {
await api.testEncodeArrayOfPost(["first", "second", "third"]);
expect(encodeMock.lastRequestBody).to.deep.equal(["first", "second", "third"]);
});
it("serializes arrays of nullable strings", async () => {
await api.testEncodeArrayOfNullablePost(["first", null, "third"]);
expect(encodeMock.lastRequestBody).to.deep.equal(["first", null, "third"]);
});
it("serializes nullable arrays", async () => {
await api.testEncodeNullableArrayPost(null);
expect(encodeMock.lastRequestBody).to.equal(null);
});
it("serializes arrays of arrays", async () => {
await api.testEncodeArrayOfArraysPost([["first", "second"], ["third"]]);
expect(encodeMock.lastRequestBody).to.deep.equal([["first", "second"], ["third"]]);
});
it("serializes objects", async () => {
await api.testEncodeObjectPost({
requiredProperty: "required",
requiredNullableProperty: null,
optionalNullableProperty: null,
});
expect(encodeMock.lastRequestBody).to.deep.equal({
required_property: "required",
required_nullable_property: null,
optional_nullable_property: null,
});
});
it("serializes maps of primitives", async () => {
await api.testEncodeMapOfPrimitivePost({
key1: "value1",
key2: "value2",
});
expect(encodeMock.lastRequestBody).to.deep.equal({
key1: "value1",
key2: "value2",
});
});
it("serializes maps of objects", async () => {
await api.testEncodeMapOfObjectsPost({
barebones: {
requiredProperty: "first",
requiredNullableProperty: null,
},
nulls: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
values: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
});
expect(encodeMock.lastRequestBody).to.deep.equal({
barebones: {
required_property: "first",
required_nullable_property: null,
},
nulls: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
values: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
});
});
it("serializes maps of maps of objects", async () => {
await api.testEncodeMapOfMapsOfObjectsPost({
key1: {
key1: {
requiredProperty: "first",
requiredNullableProperty: null,
},
key2: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
},
key2: {
key3: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
}
});
expect(encodeMock.lastRequestBody).to.deep.equal({
key1: {
key1: {
required_property: "first",
required_nullable_property: null,
},
key2: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
},
key2: {
key3: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
}
});
});
it("serializes arrays of maps of objects", async () => {
await api.testEncodeArrayOfMapsOfObjectsPost([
{
key1: {
requiredProperty: "first",
requiredNullableProperty: null,
},
key2: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
},
{
key3: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
}
]);
expect(encodeMock.lastRequestBody).to.deep.equal([
{
key1: {
required_property: "first",
required_nullable_property: null,
},
key2: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
},
{
key3: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
}
]);
});
it("serializes arrays of nullable objects", async () => {
await api.testEncodeArrayOfNullableObjectsPost([
{
requiredProperty: "first",
requiredNullableProperty: null,
},
null,
{
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
]);
expect(encodeMock.lastRequestBody).to.deep.equal([
{
required_property: "first",
required_nullable_property: null,
},
null,
{
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
]);
});
it("serializes composite objects", async () => {
await api.testEncodeCompositeObjectsPost({
optionalNullableInnerObject: {
requiredProperty: "required",
requiredNullableProperty: null,
},
});
expect(encodeMock.lastRequestBody).to.deep.equal({
optional_nullable_inner_object: {
required_property: "required",
required_nullable_property: null,
},
});
});
});

View File

@ -0,0 +1,123 @@
import * as nock from 'nock';
export const BASE_URL = 'http://localhost:1234';
// Prevent any unmocked requests from making actual HTTP requests.
nock.disableNetConnect();
function mockPath(path: string, value: any) {
const body = JSON.stringify(value);
const headers = { 'content-type': 'application/json' };
nock(BASE_URL).get(path).reply(200, body, headers).persist();
}
mockPath('/test/decode/primitive/boolean', true);
mockPath('/test/decode/primitive/integer', 42);
mockPath('/test/decode/primitive/number', 42.42);
mockPath('/test/decode/primitive/string', 'some string value');
mockPath('/test/decode/nullable', null);
mockPath('/test/decode/array-of', ["first", "second", "third"]);
mockPath('/test/decode/array-of/nullable', ["first", null, "third"]);
mockPath('/test/decode/nullable-array', null);
mockPath('/test/decode/array-of-arrays', [["first", "second"], ["third"]]);
mockPath('/test/decode/object', {
required_property: "required",
required_nullable_property: null,
optional_nullable_property: null,
});
mockPath('/test/decode/map-of/primitive', {
key1: "value1",
key2: "value2",
});
mockPath('/test/decode/map-of/objects', {
barebones: {
required_property: "first",
required_nullable_property: null,
},
nulls: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
values: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
});
mockPath('/test/decode/map-of/maps-of/objects', {
key1: {
key1: {
required_property: "first",
required_nullable_property: null,
},
key2: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
},
key2: {
key3: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
}
});
mockPath('/test/decode/array-of/maps-of/objects', [
{
key1: {
required_property: "first",
required_nullable_property: null,
},
key2: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
},
{
key3: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
}
]);
mockPath('/test/decode/composite-objects', {
optional_nullable_inner_object: {
required_property: "required",
required_nullable_property: null,
},
});
mockPath('/test/decode/array-of/nullable-objects', [
{
required_property: "first",
required_nullable_property: null,
},
null,
{
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
]);
export const encodeMock = {
lastRequestBody: "",
};
nock(BASE_URL)
.filteringPath(/^\/test\/encode\/.*/, '/test/encode')
.post('/test/encode')
.reply(200, (uri: string, requestBody: string) => {
encodeMock.lastRequestBody = requestBody;
return "";
})
.persist();

View File

@ -0,0 +1,20 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "CommonJS",
"target": "ES5",
"noImplicitAny": true,
"sourceMap": false,
"outDir": "dist",
"types": [
"mocha"
],
"lib": [
"es6",
"dom"
]
},
"exclude": [
"node_modules"
]
}

View File

@ -76,6 +76,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -115,19 +122,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -160,21 +183,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -73,6 +73,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -112,19 +119,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -157,21 +180,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -0,0 +1 @@
dist

View File

@ -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

View File

@ -0,0 +1,25 @@
.gitignore
DefaultApi.md
README.md
apis/DefaultApi.ts
apis/baseapi.ts
apis/exception.ts
auth/auth.ts
configuration.ts
git_push.sh
http/http.ts
http/isomorphic-fetch.ts
index.ts
middleware.ts
models/ComplexObject.ts
models/CompositeObject.ts
models/ObjectSerializer.ts
models/all.ts
package.json
rxjsStub.ts
servers.ts
tsconfig.json
types/ObjectParamAPI.ts
types/ObservableAPI.ts
types/PromiseAPI.ts
util.ts

View File

@ -0,0 +1 @@
7.9.0-SNAPSHOT

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,80 @@
## @openapitools/typescript-encode-decode@1.0.0
This generator creates TypeScript/JavaScript client that utilizes fetch-api.
### 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-encode-decode@1.0.0 --save
```
_unPublished (not recommended):_
```
npm install PATH_TO_GENERATED_PACKAGE --save
```
### Usage
Below code snippet shows exemplary usage of the configuration and the API based
on the typical `PetStore` example used for OpenAPI.
```
import * as your_api from 'your_api_package'
// Covers all auth methods included in your OpenAPI yaml definition
const authConfig: your_api.AuthMethodsConfiguration = {
"api_key": "YOUR_API_KEY"
}
// Implements a simple middleware to modify requests before (`pre`) they are sent
// and after (`post`) they have been received
class Test implements your_api.Middleware {
pre(context: your_api.RequestContext): Promise<your_api.RequestContext> {
// Modify context here and return
return Promise.resolve(context);
}
post(context: your_api.ResponseContext): Promise<your_api.ResponseContext> {
return Promise.resolve(context);
}
}
// Create configuration parameter object
const configurationParameters = {
httpApi: new your_api.JQueryHttpLibrary(), // Can also be ignored - default is usually fine
baseServer: your_api.servers[0], // First server is default
authMethods: authConfig, // No auth is default
promiseMiddleware: [new Test()],
}
// Convert to actual configuration
const config = your_api.createConfiguration(configurationParameters);
// Use configuration with your_api
const api = new your_api.PetApi(config);
your_api.Pet p = new your_api.Pet();
p.name = "My new pet";
p.photoUrls = [];
p.tags = [];
p.status = "available";
Promise<your_api.Pet> createdPet = api.addPet(p);
```

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
import { Configuration } from '../configuration'
/**
*
* @export
*/
export const COLLECTION_FORMATS = {
csv: ",",
ssv: " ",
tsv: "\t",
pipes: "|",
};
/**
*
* @export
* @class BaseAPI
*/
export class BaseAPIRequestFactory {
constructor(protected configuration: Configuration) {
}
};
/**
*
* @export
* @class RequiredError
* @extends {Error}
*/
export class RequiredError extends Error {
name: "RequiredError" = "RequiredError";
constructor(public api: string, public method: string, public field: string) {
super("Required parameter " + field + " was null or undefined when calling " + api + "." + method + ".");
}
}

View File

@ -0,0 +1,15 @@
/**
* Represents an error caused by an api call i.e. it has attributes for a HTTP status code
* and the returned body object.
*
* Example
* API returns a ErrorMessageObject whenever HTTP status code is not in [200, 299]
* => ApiException(404, someErrorMessageObject)
*
*/
export class ApiException<T> extends Error {
public constructor(public code: number, message: string, public body: T, public headers: { [key: string]: string; }) {
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body) + "\nHeaders: " +
JSON.stringify(headers))
}
}

View File

@ -0,0 +1,51 @@
import { RequestContext } from "../http/http";
/**
* Interface authentication schemes.
*/
export interface SecurityAuthentication {
/*
* @return returns the name of the security authentication as specified in OAI
*/
getName(): string;
/**
* Applies the authentication scheme to the request context
*
* @params context the request context which should use this authentication scheme
*/
applySecurityAuthentication(context: RequestContext): void | Promise<void>;
}
export interface TokenProvider {
getToken(): Promise<string> | string;
}
export type AuthMethods = {
"default"?: SecurityAuthentication,
}
export type ApiKeyConfiguration = string;
export type HttpBasicConfiguration = { "username": string, "password": string };
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
export type OAuth2Configuration = { accessToken: string };
export type AuthMethodsConfiguration = {
"default"?: SecurityAuthentication,
}
/**
* Creates the authentication methods from a swagger description.
*
*/
export function configureAuthMethods(config: AuthMethodsConfiguration | undefined): AuthMethods {
let authMethods: AuthMethods = {}
if (!config) {
return authMethods;
}
authMethods["default"] = config["default"]
return authMethods;
}

View File

@ -0,0 +1,82 @@
import { HttpLibrary } from "./http/http";
import { Middleware, PromiseMiddleware, PromiseMiddlewareWrapper } from "./middleware";
import { IsomorphicFetchHttpLibrary as DefaultHttpLibrary } from "./http/isomorphic-fetch";
import { BaseServerConfiguration, server1 } from "./servers";
import { configureAuthMethods, AuthMethods, AuthMethodsConfiguration } from "./auth/auth";
export interface Configuration {
readonly baseServer: BaseServerConfiguration;
readonly httpApi: HttpLibrary;
readonly middleware: Middleware[];
readonly authMethods: AuthMethods;
}
/**
* Interface with which a configuration object can be configured.
*/
export interface ConfigurationParameters {
/**
* Default server to use - a list of available servers (according to the
* OpenAPI yaml definition) is included in the `servers` const in `./servers`. You can also
* create your own server with the `ServerConfiguration` class from the same
* file.
*/
baseServer?: BaseServerConfiguration;
/**
* HTTP library to use e.g. IsomorphicFetch. This can usually be skipped as
* all generators come with a default library.
* If available, additional libraries can be imported from `./http/*`
*/
httpApi?: HttpLibrary;
/**
* The middlewares which will be applied to requests and responses. You can
* add any number of middleware components to modify requests before they
* are sent or before they are deserialized by implementing the `Middleware`
* interface defined in `./middleware`
*/
middleware?: Middleware[];
/**
* Configures middleware functions that return promises instead of
* Observables (which are used by `middleware`). Otherwise allows for the
* same functionality as `middleware`, i.e., modifying requests before they
* are sent and before they are deserialized.
*/
promiseMiddleware?: PromiseMiddleware[];
/**
* Configuration for the available authentication methods (e.g., api keys)
* according to the OpenAPI yaml definition. For the definition, please refer to
* `./auth/auth`
*/
authMethods?: AuthMethodsConfiguration
}
/**
* Provide your `ConfigurationParameters` to this function to get a `Configuration`
* object that can be used to configure your APIs (in the constructor or
* for each request individually).
*
* If a property is not included in conf, a default is used:
* - baseServer: server1
* - httpApi: IsomorphicFetchHttpLibrary
* - middleware: []
* - promiseMiddleware: []
* - authMethods: {}
*
* @param conf partial configuration
*/
export function createConfiguration(conf: ConfigurationParameters = {}): Configuration {
const configuration: Configuration = {
baseServer: conf.baseServer !== undefined ? conf.baseServer : server1,
httpApi: conf.httpApi || new DefaultHttpLibrary(),
middleware: conf.middleware || [],
authMethods: configureAuthMethods(conf.authMethods)
};
if (conf.promiseMiddleware) {
conf.promiseMiddleware.forEach(
m => configuration.middleware.push(new PromiseMiddlewareWrapper(m))
);
}
return configuration;
}

View File

@ -0,0 +1,51 @@
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update"
git_user_id=$1
git_repo_id=$2
release_note=$3
if [ "$git_user_id" = "" ]; then
git_user_id="GIT_USER_ID"
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi
if [ "$git_repo_id" = "" ]; then
git_repo_id="GIT_REPO_ID"
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi
if [ "$release_note" = "" ]; then
release_note="Minor update"
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi
# Initialize the local directory as a Git repository
git init
# Adds the files in the local repository and stages them for commit.
git add .
# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"
# Sets the new remote
git_remote=$(git remote)
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@github.com/${git_user_id}/${git_repo_id}.git
fi
fi
git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'

View File

@ -0,0 +1,251 @@
// TODO: evaluate if we can easily get rid of this library
import * as FormData from "form-data";
import { URL, URLSearchParams } from 'url';
import * as http from 'http';
import * as https from 'https';
import { Observable, from } from '../rxjsStub';
export * from './isomorphic-fetch';
/**
* Represents an HTTP method.
*/
export enum HttpMethod {
GET = "GET",
HEAD = "HEAD",
POST = "POST",
PUT = "PUT",
DELETE = "DELETE",
CONNECT = "CONNECT",
OPTIONS = "OPTIONS",
TRACE = "TRACE",
PATCH = "PATCH"
}
/**
* Represents an HTTP file which will be transferred from or to a server.
*/
export type HttpFile = {
data: Buffer,
name: string
};
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
}
}
/**
* Represents the body of an outgoing HTTP request.
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
}
throw new Error("You need to define an absolute base url for the server.");
}
/**
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
/**
* Creates the request context using a http method and request resource url
*
* @param url url of the requested resource
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URL(ensureAbsoluteUrl(url));
}
/*
* Returns the url set in the constructor including the query string
*
*/
public getUrl(): string {
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
* Replaces the url set in the constructor with this url.
*
*/
public setUrl(url: string) {
this.url = new URL(ensureAbsoluteUrl(url));
}
/**
* Sets the body of the http request either as a string or FormData
*
* Note that setting a body on a HTTP GET, HEAD, DELETE, CONNECT or TRACE
* request is discouraged.
* https://httpwg.org/http-core/draft-ietf-httpbis-semantics-latest.html#rfc.section.7.3.1
*
* @param body the body of the request
*/
public setBody(body: RequestBody) {
this.body = body;
}
public getHttpMethod(): HttpMethod {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
return this.headers;
}
public getBody(): RequestBody {
return this.body;
}
public setQueryParam(name: string, value: string) {
this.url.searchParams.set(name, value);
}
public appendQueryParam(name: string, value: string) {
this.url.searchParams.append(name, value);
}
/**
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
*
*/
public addCookie(name: string, value: string): void {
if (!this.headers["Cookie"]) {
this.headers["Cookie"] = "";
}
this.headers["Cookie"] += name + "=" + value + "; ";
}
public setHeaderParam(key: string, value: string): void {
this.headers[key] = value;
}
public setAgent(agent: http.Agent | https.Agent) {
this.agent = agent;
}
public getAgent(): http.Agent | https.Agent | undefined {
return this.agent;
}
}
export interface ResponseBody {
text(): Promise<string>;
binary(): Promise<Buffer>;
}
/**
* Helper class to generate a `ResponseBody` from binary data
*/
export class SelfDecodingBody implements ResponseBody {
constructor(private dataSource: Promise<Buffer>) {}
binary(): Promise<Buffer> {
return this.dataSource;
}
async text(): Promise<string> {
const data: Buffer = await this.dataSource;
return data.toString();
}
}
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public body: ResponseBody
) {}
/**
* Parse header value in the form `value; param1="value1"`
*
* E.g. for Content-Type or Content-Disposition
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
if (!this.headers[headerName]) {
return result;
}
const parameters = this.headers[headerName].split(";");
for (const parameter of parameters) {
let [key, value] = parameter.split("=", 2);
key = key.toLowerCase().trim();
if (value === undefined) {
result[""] = key;
} else {
value = value.trim();
if (value.startsWith('"') && value.endsWith('"')) {
value = value.substring(1, value.length - 1);
}
result[key] = value;
}
}
return result;
}
public async getBodyAsFile(): Promise<HttpFile> {
const data = await this.body.binary();
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
return { data, name: fileName };
}
/**
* Use a heuristic to get a body of unknown data structure.
* Return as string if possible, otherwise as binary.
*/
public getBodyAsAny(): Promise<string | Buffer | undefined> {
try {
return this.body.text();
} catch {}
try {
return this.body.binary();
} catch {}
return Promise.resolve(undefined);
}
}
export interface HttpLibrary {
send(request: RequestContext): Observable<ResponseContext>;
}
export interface PromiseHttpLibrary {
send(request: RequestContext): Promise<ResponseContext>;
}
export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLibrary {
return {
send(request: RequestContext): Observable<ResponseContext> {
return from(promiseHttpLibrary.send(request));
}
}
}
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public body: ResponseBody,
public data: T,
) {
super(httpStatusCode, headers, body);
}
}

View File

@ -0,0 +1,32 @@
import {HttpLibrary, RequestContext, ResponseContext} from './http';
import { from, Observable } from '../rxjsStub';
import fetch from "node-fetch";
export class IsomorphicFetchHttpLibrary implements HttpLibrary {
public send(request: RequestContext): Observable<ResponseContext> {
let method = request.getHttpMethod().toString();
let body = request.getBody();
const resultPromise = fetch(request.getUrl(), {
method: method,
body: body as any,
headers: request.getHeaders(),
agent: request.getAgent(),
}).then((resp: any) => {
const headers: { [name: string]: string } = {};
resp.headers.forEach((value: string, name: string) => {
headers[name] = value;
});
const body = {
text: () => resp.text(),
binary: () => resp.buffer()
};
return new ResponseContext(resp.status, headers, body);
});
return from<Promise<ResponseContext>>(resultPromise);
}
}

View File

@ -0,0 +1,12 @@
export * from "./http/http";
export * from "./auth/auth";
export * from "./models/all";
export { createConfiguration } from "./configuration"
export { Configuration } from "./configuration"
export * from "./apis/exception";
export * from "./servers";
export { RequiredError } from "./apis/baseapi";
export { PromiseMiddleware as Middleware } from './middleware';
export { PromiseDefaultApi as DefaultApi } from './types/PromiseAPI';

View File

@ -0,0 +1,66 @@
import {RequestContext, ResponseContext} from './http/http';
import { Observable, from } from './rxjsStub';
/**
* Defines the contract for a middleware intercepting requests before
* they are sent (but after the RequestContext was created)
* and before the ResponseContext is unwrapped.
*
*/
export interface Middleware {
/**
* Modifies the request before the request is sent.
*
* @param context RequestContext of a request which is about to be sent to the server
* @returns an observable of the updated request context
*
*/
pre(context: RequestContext): Observable<RequestContext>;
/**
* Modifies the returned response before it is deserialized.
*
* @param context ResponseContext of a sent request
* @returns an observable of the modified response context
*/
post(context: ResponseContext): Observable<ResponseContext>;
}
export class PromiseMiddlewareWrapper implements Middleware {
public constructor(private middleware: PromiseMiddleware) {
}
pre(context: RequestContext): Observable<RequestContext> {
return from(this.middleware.pre(context));
}
post(context: ResponseContext): Observable<ResponseContext> {
return from(this.middleware.post(context));
}
}
/**
* Defines the contract for a middleware intercepting requests before
* they are sent (but after the RequestContext was created)
* and before the ResponseContext is unwrapped.
*
*/
export interface PromiseMiddleware {
/**
* Modifies the request before the request is sent.
*
* @param context RequestContext of a request which is about to be sent to the server
* @returns an observable of the updated request context
*
*/
pre(context: RequestContext): Promise<RequestContext>;
/**
* Modifies the returned response before it is deserialized.
*
* @param context ResponseContext of a sent request
* @returns an observable of the modified response context
*/
post(context: ResponseContext): Promise<ResponseContext>;
}

View File

@ -0,0 +1,57 @@
/**
* Encoding / Decoding Test
* A spec to ensure encoding and decoding of types (both primitive and compound) works as expected
*
* OpenAPI spec version: latest
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { HttpFile } from '../http/http';
export class ComplexObject {
'requiredProperty': string;
'requiredNullableProperty': string | null;
'optionalProperty'?: string;
'optionalNullableProperty'?: string | null;
static readonly discriminator: string | undefined = undefined;
static readonly mapping: {[index: string]: string} | undefined = undefined;
static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
{
"name": "requiredProperty",
"baseName": "required_property",
"type": "string",
"format": ""
},
{
"name": "requiredNullableProperty",
"baseName": "required_nullable_property",
"type": "string",
"format": ""
},
{
"name": "optionalProperty",
"baseName": "optional_property",
"type": "string",
"format": ""
},
{
"name": "optionalNullableProperty",
"baseName": "optional_nullable_property",
"type": "string",
"format": ""
} ];
static getAttributeTypeMap() {
return ComplexObject.attributeTypeMap;
}
public constructor() {
}
}

View File

@ -0,0 +1,37 @@
/**
* Encoding / Decoding Test
* A spec to ensure encoding and decoding of types (both primitive and compound) works as expected
*
* OpenAPI spec version: latest
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { ComplexObject } from '../models/ComplexObject';
import { HttpFile } from '../http/http';
export class CompositeObject {
'optionalNullableInnerObject'?: ComplexObject | null;
static readonly discriminator: string | undefined = undefined;
static readonly mapping: {[index: string]: string} | undefined = undefined;
static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
{
"name": "optionalNullableInnerObject",
"baseName": "optional_nullable_inner_object",
"type": "ComplexObject",
"format": ""
} ];
static getAttributeTypeMap() {
return CompositeObject.attributeTypeMap;
}
public constructor() {
}
}

View File

@ -0,0 +1,311 @@
export * from '../models/ComplexObject';
export * from '../models/CompositeObject';
import { ComplexObject } from '../models/ComplexObject';
import { CompositeObject } from '../models/CompositeObject';
/* tslint:disable:no-unused-variable */
let primitives = [
"string",
"boolean",
"double",
"integer",
"long",
"float",
"number",
"any"
];
let enumsMap: Set<string> = new Set<string>([
]);
let typeMap: {[index: string]: any} = {
"ComplexObject": ComplexObject,
"CompositeObject": CompositeObject,
}
type MimeTypeDescriptor = {
type: string;
subtype: string;
subtypeTokens: string[];
};
/**
* Every mime-type consists of a type, subtype, and optional parameters.
* The subtype can be composite, including information about the content format.
* For example: `application/json-patch+json`, `application/merge-patch+json`.
*
* This helper transforms a string mime-type into an internal representation.
* This simplifies the implementation of predicates that in turn define common rules for parsing or stringifying
* the payload.
*/
const parseMimeType = (mimeType: string): MimeTypeDescriptor => {
const [type, subtype] = mimeType.split('/');
return {
type,
subtype,
subtypeTokens: subtype.split('+'),
};
};
type MimeTypePredicate = (mimeType: string) => boolean;
// This factory creates a predicate function that checks a string mime-type against defined rules.
const mimeTypePredicateFactory = (predicate: (descriptor: MimeTypeDescriptor) => boolean): MimeTypePredicate => (mimeType) => predicate(parseMimeType(mimeType));
// Use this factory when you need to define a simple predicate based only on type and, if applicable, subtype.
const mimeTypeSimplePredicateFactory = (type: string, subtype?: string): MimeTypePredicate => mimeTypePredicateFactory((descriptor) => {
if (descriptor.type !== type) return false;
if (subtype != null && descriptor.subtype !== subtype) return false;
return true;
});
// Creating a set of named predicates that will help us determine how to handle different mime-types
const isTextLikeMimeType = mimeTypeSimplePredicateFactory('text');
const isJsonMimeType = mimeTypeSimplePredicateFactory('application', 'json');
const isJsonLikeMimeType = mimeTypePredicateFactory((descriptor) => descriptor.type === 'application' && descriptor.subtypeTokens.some((item) => item === 'json'));
const isOctetStreamMimeType = mimeTypeSimplePredicateFactory('application', 'octet-stream');
const isFormUrlencodedMimeType = mimeTypeSimplePredicateFactory('application', 'x-www-form-urlencoded');
// Defining a list of mime-types in the order of prioritization for handling.
const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isJsonMimeType,
isJsonLikeMimeType,
isTextLikeMimeType,
isOctetStreamMimeType,
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
return expectedType;
} else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) {
return expectedType;
} else if (expectedType === "Date") {
return expectedType;
} else {
if (enumsMap.has(expectedType)) {
return expectedType;
}
if (!typeMap[expectedType]) {
return expectedType; // w/e we don't know the type
}
// Check the discriminator
let discriminatorProperty = typeMap[expectedType].discriminator;
if (discriminatorProperty == null) {
return expectedType; // the type does not have a discriminator. use it.
} else {
if (data[discriminatorProperty]) {
var discriminatorType = data[discriminatorProperty];
let mapping = typeMap[expectedType].mapping;
if (mapping != undefined && mapping[discriminatorType]) {
return mapping[discriminatorType]; // use the type given in the discriminator
} else if(typeMap[discriminatorType]) {
return discriminatorType;
} else {
return expectedType; // discriminator did not map to a type
}
} else {
return expectedType; // discriminator was not present (or an empty string)
}
}
}
}
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
month = month < 10 ? "0" + month.toString() : month.toString()
let day = data.getDate();
day = day < 10 ? "0" + day.toString() : day.toString();
return data.getFullYear() + "-" + month + "-" + day;
} else {
return data.toISOString();
}
} else {
if (enumsMap.has(type)) {
return data;
}
if (!typeMap[type]) { // in case we dont know the type
return data;
}
// Get the actual type of this object
type = this.findCorrectType(data, type);
// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance: {[index: string]: any} = {};
for (let attributeType of attributeTypes) {
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type, attributeType.format);
}
return instance;
}
}
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {
if (enumsMap.has(type)) {// is Enum
return data;
}
if (!typeMap[type]) { // dont know the type
return data;
}
let instance = new typeMap[type]();
let attributeTypes = typeMap[type].getAttributeTypeMap();
for (let attributeType of attributeTypes) {
let value = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type, attributeType.format);
if (value !== undefined) {
instance[attributeType.name] = value;
}
}
return instance;
}
}
/**
* Normalize media type
*
* We currently do not handle any media types attributes, i.e. anything
* after a semicolon. All content is assumed to be UTF-8 compatible.
*/
public static normalizeMediaType(mediaType: string | undefined): string | undefined {
if (mediaType === undefined) {
return undefined;
}
return mediaType.split(";")[0].trim().toLowerCase();
}
/**
* From a list of possible media types, choose the one we can handle best.
*
* The order of the given media types does not have any impact on the choice
* made.
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (mediaTypes.length === 0) {
return "application/json";
}
const normalMediaTypes = mediaTypes.map(this.normalizeMediaType);
for (const predicate of supportedMimeTypePredicatesWithPriority) {
for (const mediaType of normalMediaTypes) {
if (mediaType != null && predicate(mediaType)) {
return mediaType;
}
}
}
throw new Error("None of the given media types are supported: " + mediaTypes.join(", "));
}
/**
* Convert data to a string according the given media type
*/
public static stringify(data: any, mediaType: string): string {
if (isTextLikeMimeType(mediaType)) {
return String(data);
}
if (isJsonLikeMimeType(mediaType)) {
return JSON.stringify(data);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify.");
}
/**
* Parse data from a string according to the given media type
*/
public static parse(rawData: string, mediaType: string | undefined) {
if (mediaType === undefined) {
throw new Error("Cannot parse content. No Content-Type defined.");
}
if (isTextLikeMimeType(mediaType)) {
return rawData;
}
if (isJsonLikeMimeType(mediaType)) {
return JSON.parse(rawData);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse.");
}
}

View File

@ -0,0 +1,2 @@
export * from '../models/ComplexObject'
export * from '../models/CompositeObject'

View File

@ -0,0 +1,45 @@
{
"name": "@openapitools/typescript-encode-decode",
"version": "1.0.0",
"description": "OpenAPI client for @openapitools/typescript-encode-decode",
"author": "OpenAPI-Generator Contributors",
"repository": {
"type": "git",
"url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
},
"keywords": [
"fetch",
"typescript",
"openapi-client",
"openapi-generator"
],
"license": "Unlicense",
"main": "./dist/index.js",
"type": "commonjs",
"exports": {
".": {
"require": "./dist/index.js",
"types": "./dist/index.d.js"
}
},
"files": [
"dist"
],
"typings": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"prepare": "npm run build"
},
"dependencies": {
"node-fetch": "^2.6.0",
"@types/node-fetch": "^2.5.7",
"@types/node": "*",
"form-data": "^2.5.0",
"es6-promise": "^4.2.4",
"url-parse": "^1.4.3"
},
"devDependencies": {
"typescript": "^4.0",
"@types/url-parse": "1.4.4"
}
}

View File

@ -0,0 +1,27 @@
export class Observable<T> {
constructor(private promise: Promise<T>) {}
toPromise() {
return this.promise;
}
pipe<S>(callback: (value: T) => S | Promise<S>): Observable<S> {
return new Observable(this.promise.then(callback));
}
}
export function from<T>(promise: Promise<any>) {
return new Observable(promise);
}
export function of<T>(value: T) {
return new Observable<T>(Promise.resolve(value));
}
export function mergeMap<T, S>(callback: (value: T) => Observable<S>) {
return (value: T) => callback(value).toPromise();
}
export function map(callback: any) {
return callback;
}

View File

@ -0,0 +1,55 @@
import { RequestContext, HttpMethod } from "./http/http";
export interface BaseServerConfiguration {
makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
}
/**
*
* Represents the configuration of a server including its
* url template and variable configuration based on the url.
*
*/
export class ServerConfiguration<T extends { [key: string]: string }> implements BaseServerConfiguration {
public constructor(private url: string, private variableConfiguration: T) {}
/**
* Sets the value of the variables of this server. Variables are included in
* the `url` of this ServerConfiguration in the form `{variableName}`
*
* @param variableConfiguration a partial variable configuration for the
* variables contained in the url
*/
public setVariables(variableConfiguration: Partial<T>) {
Object.assign(this.variableConfiguration, variableConfiguration);
}
public getConfiguration(): T {
return this.variableConfiguration
}
private getUrl() {
let replacedUrl = this.url;
for (const key in this.variableConfiguration) {
var re = new RegExp("{" + key + "}","g");
replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]);
}
return replacedUrl
}
/**
* Creates a new request context for this server using the url with variables
* replaced with their respective values and the endpoint of the request appended.
*
* @param endpoint the endpoint to be queried on the server
* @param httpMethod httpMethod to be used
*
*/
public makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext {
return new RequestContext(this.getUrl() + endpoint, httpMethod);
}
}
export const server1 = new ServerConfiguration<{ }>("", { })
export const servers = [server1];

View File

@ -0,0 +1,28 @@
{
"compilerOptions": {
"strict": true,
/* Basic Options */
"target": "es5",
"moduleResolution": "node",
"declaration": true,
/* Additional Checks */
"noUnusedLocals": false, /* Report errors on unused locals. */ // TODO: reenable (unused imports!)
"noUnusedParameters": false, /* Report errors on unused parameters. */ // TODO: set to true again
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
"removeComments": true,
"sourceMap": true,
"outDir": "./dist",
"noLib": false,
"lib": [ "es6" ],
},
"exclude": [
"dist",
"node_modules"
],
"filesGlob": [
"./**/*.ts",
]
}

View File

@ -0,0 +1,657 @@
import { ResponseContext, RequestContext, HttpFile, HttpInfo } from '../http/http';
import { Configuration} from '../configuration'
import { ComplexObject } from '../models/ComplexObject';
import { CompositeObject } from '../models/CompositeObject';
import { ObservableDefaultApi } from "./ObservableAPI";
import { DefaultApiRequestFactory, DefaultApiResponseProcessor} from "../apis/DefaultApi";
export interface DefaultApiTestDecodeArrayOfArraysGetRequest {
}
export interface DefaultApiTestDecodeArrayOfGetRequest {
}
export interface DefaultApiTestDecodeArrayOfMapsOfObjectsGetRequest {
}
export interface DefaultApiTestDecodeArrayOfNullableGetRequest {
}
export interface DefaultApiTestDecodeArrayOfNullableObjectsGetRequest {
}
export interface DefaultApiTestDecodeCompositeObjectsGetRequest {
}
export interface DefaultApiTestDecodeMapOfMapsOfObjectsGetRequest {
}
export interface DefaultApiTestDecodeMapOfObjectsGetRequest {
}
export interface DefaultApiTestDecodeMapOfPrimitiveGetRequest {
}
export interface DefaultApiTestDecodeNullableArrayGetRequest {
}
export interface DefaultApiTestDecodeNullableGetRequest {
}
export interface DefaultApiTestDecodeObjectGetRequest {
}
export interface DefaultApiTestDecodePrimitiveBooleanGetRequest {
}
export interface DefaultApiTestDecodePrimitiveIntegerGetRequest {
}
export interface DefaultApiTestDecodePrimitiveNumberGetRequest {
}
export interface DefaultApiTestDecodePrimitiveStringGetRequest {
}
export interface DefaultApiTestEncodeArrayOfArraysPostRequest {
/**
*
* @type Array&lt;Array&lt;string&gt;&gt;
* @memberof DefaultApitestEncodeArrayOfArraysPost
*/
requestBody: Array<Array<string>>
}
export interface DefaultApiTestEncodeArrayOfMapsOfObjectsPostRequest {
/**
*
* @type Array&lt;{ [key: string]: ComplexObject; }&gt;
* @memberof DefaultApitestEncodeArrayOfMapsOfObjectsPost
*/
complexObject: Array<{ [key: string]: ComplexObject; }>
}
export interface DefaultApiTestEncodeArrayOfNullableObjectsPostRequest {
/**
*
* @type Array&lt;ComplexObject&gt;
* @memberof DefaultApitestEncodeArrayOfNullableObjectsPost
*/
complexObject: Array<ComplexObject>
}
export interface DefaultApiTestEncodeArrayOfNullablePostRequest {
/**
*
* @type Array&lt;string | null&gt;
* @memberof DefaultApitestEncodeArrayOfNullablePost
*/
requestBody: Array<string | null>
}
export interface DefaultApiTestEncodeArrayOfPostRequest {
/**
*
* @type Array&lt;string&gt;
* @memberof DefaultApitestEncodeArrayOfPost
*/
requestBody: Array<string>
}
export interface DefaultApiTestEncodeCompositeObjectsPostRequest {
/**
*
* @type CompositeObject
* @memberof DefaultApitestEncodeCompositeObjectsPost
*/
compositeObject: CompositeObject
}
export interface DefaultApiTestEncodeMapOfMapsOfObjectsPostRequest {
/**
*
* @type { [key: string]: { [key: string]: ComplexObject; }; }
* @memberof DefaultApitestEncodeMapOfMapsOfObjectsPost
*/
requestBody: { [key: string]: { [key: string]: ComplexObject; }; }
}
export interface DefaultApiTestEncodeMapOfObjectsPostRequest {
/**
*
* @type { [key: string]: ComplexObject | null; }
* @memberof DefaultApitestEncodeMapOfObjectsPost
*/
requestBody: { [key: string]: ComplexObject | null; }
}
export interface DefaultApiTestEncodeMapOfPrimitivePostRequest {
/**
*
* @type { [key: string]: string; }
* @memberof DefaultApitestEncodeMapOfPrimitivePost
*/
requestBody: { [key: string]: string; }
}
export interface DefaultApiTestEncodeNullableArrayPostRequest {
/**
*
* @type Array&lt;string&gt;
* @memberof DefaultApitestEncodeNullableArrayPost
*/
requestBody?: Array<string>
}
export interface DefaultApiTestEncodeNullablePostRequest {
/**
*
* @type string
* @memberof DefaultApitestEncodeNullablePost
*/
body?: string
}
export interface DefaultApiTestEncodeObjectPostRequest {
/**
*
* @type ComplexObject
* @memberof DefaultApitestEncodeObjectPost
*/
complexObject: ComplexObject
}
export interface DefaultApiTestEncodePrimitiveBooleanPostRequest {
/**
*
* @type boolean
* @memberof DefaultApitestEncodePrimitiveBooleanPost
*/
body: boolean
}
export interface DefaultApiTestEncodePrimitiveIntegerPostRequest {
/**
*
* @type number
* @memberof DefaultApitestEncodePrimitiveIntegerPost
*/
body: number
}
export interface DefaultApiTestEncodePrimitiveNumberPostRequest {
/**
*
* @type number
* @memberof DefaultApitestEncodePrimitiveNumberPost
*/
body: number
}
export interface DefaultApiTestEncodePrimitiveStringPostRequest {
/**
*
* @type string
* @memberof DefaultApitestEncodePrimitiveStringPost
*/
body: string
}
export class ObjectDefaultApi {
private api: ObservableDefaultApi
public constructor(configuration: Configuration, requestFactory?: DefaultApiRequestFactory, responseProcessor?: DefaultApiResponseProcessor) {
this.api = new ObservableDefaultApi(configuration, requestFactory, responseProcessor);
}
/**
* @param param the request object
*/
public testDecodeArrayOfArraysGetWithHttpInfo(param: DefaultApiTestDecodeArrayOfArraysGetRequest = {}, options?: Configuration): Promise<HttpInfo<Array<Array<string>>>> {
return this.api.testDecodeArrayOfArraysGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfArraysGet(param: DefaultApiTestDecodeArrayOfArraysGetRequest = {}, options?: Configuration): Promise<Array<Array<string>>> {
return this.api.testDecodeArrayOfArraysGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfGetWithHttpInfo(param: DefaultApiTestDecodeArrayOfGetRequest = {}, options?: Configuration): Promise<HttpInfo<Array<string>>> {
return this.api.testDecodeArrayOfGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfGet(param: DefaultApiTestDecodeArrayOfGetRequest = {}, options?: Configuration): Promise<Array<string>> {
return this.api.testDecodeArrayOfGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfMapsOfObjectsGetWithHttpInfo(param: DefaultApiTestDecodeArrayOfMapsOfObjectsGetRequest = {}, options?: Configuration): Promise<HttpInfo<Array<{ [key: string]: ComplexObject; }>>> {
return this.api.testDecodeArrayOfMapsOfObjectsGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfMapsOfObjectsGet(param: DefaultApiTestDecodeArrayOfMapsOfObjectsGetRequest = {}, options?: Configuration): Promise<Array<{ [key: string]: ComplexObject; }>> {
return this.api.testDecodeArrayOfMapsOfObjectsGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfNullableGetWithHttpInfo(param: DefaultApiTestDecodeArrayOfNullableGetRequest = {}, options?: Configuration): Promise<HttpInfo<Array<string | null>>> {
return this.api.testDecodeArrayOfNullableGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfNullableGet(param: DefaultApiTestDecodeArrayOfNullableGetRequest = {}, options?: Configuration): Promise<Array<string | null>> {
return this.api.testDecodeArrayOfNullableGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfNullableObjectsGetWithHttpInfo(param: DefaultApiTestDecodeArrayOfNullableObjectsGetRequest = {}, options?: Configuration): Promise<HttpInfo<Array<ComplexObject>>> {
return this.api.testDecodeArrayOfNullableObjectsGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeArrayOfNullableObjectsGet(param: DefaultApiTestDecodeArrayOfNullableObjectsGetRequest = {}, options?: Configuration): Promise<Array<ComplexObject>> {
return this.api.testDecodeArrayOfNullableObjectsGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeCompositeObjectsGetWithHttpInfo(param: DefaultApiTestDecodeCompositeObjectsGetRequest = {}, options?: Configuration): Promise<HttpInfo<CompositeObject>> {
return this.api.testDecodeCompositeObjectsGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeCompositeObjectsGet(param: DefaultApiTestDecodeCompositeObjectsGetRequest = {}, options?: Configuration): Promise<CompositeObject> {
return this.api.testDecodeCompositeObjectsGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeMapOfMapsOfObjectsGetWithHttpInfo(param: DefaultApiTestDecodeMapOfMapsOfObjectsGetRequest = {}, options?: Configuration): Promise<HttpInfo<{ [key: string]: { [key: string]: ComplexObject; }; }>> {
return this.api.testDecodeMapOfMapsOfObjectsGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeMapOfMapsOfObjectsGet(param: DefaultApiTestDecodeMapOfMapsOfObjectsGetRequest = {}, options?: Configuration): Promise<{ [key: string]: { [key: string]: ComplexObject; }; }> {
return this.api.testDecodeMapOfMapsOfObjectsGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeMapOfObjectsGetWithHttpInfo(param: DefaultApiTestDecodeMapOfObjectsGetRequest = {}, options?: Configuration): Promise<HttpInfo<{ [key: string]: ComplexObject | null; }>> {
return this.api.testDecodeMapOfObjectsGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeMapOfObjectsGet(param: DefaultApiTestDecodeMapOfObjectsGetRequest = {}, options?: Configuration): Promise<{ [key: string]: ComplexObject | null; }> {
return this.api.testDecodeMapOfObjectsGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeMapOfPrimitiveGetWithHttpInfo(param: DefaultApiTestDecodeMapOfPrimitiveGetRequest = {}, options?: Configuration): Promise<HttpInfo<{ [key: string]: string; }>> {
return this.api.testDecodeMapOfPrimitiveGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeMapOfPrimitiveGet(param: DefaultApiTestDecodeMapOfPrimitiveGetRequest = {}, options?: Configuration): Promise<{ [key: string]: string; }> {
return this.api.testDecodeMapOfPrimitiveGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeNullableArrayGetWithHttpInfo(param: DefaultApiTestDecodeNullableArrayGetRequest = {}, options?: Configuration): Promise<HttpInfo<Array<string>>> {
return this.api.testDecodeNullableArrayGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeNullableArrayGet(param: DefaultApiTestDecodeNullableArrayGetRequest = {}, options?: Configuration): Promise<Array<string>> {
return this.api.testDecodeNullableArrayGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeNullableGetWithHttpInfo(param: DefaultApiTestDecodeNullableGetRequest = {}, options?: Configuration): Promise<HttpInfo<string>> {
return this.api.testDecodeNullableGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeNullableGet(param: DefaultApiTestDecodeNullableGetRequest = {}, options?: Configuration): Promise<string> {
return this.api.testDecodeNullableGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeObjectGetWithHttpInfo(param: DefaultApiTestDecodeObjectGetRequest = {}, options?: Configuration): Promise<HttpInfo<ComplexObject>> {
return this.api.testDecodeObjectGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodeObjectGet(param: DefaultApiTestDecodeObjectGetRequest = {}, options?: Configuration): Promise<ComplexObject> {
return this.api.testDecodeObjectGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodePrimitiveBooleanGetWithHttpInfo(param: DefaultApiTestDecodePrimitiveBooleanGetRequest = {}, options?: Configuration): Promise<HttpInfo<boolean>> {
return this.api.testDecodePrimitiveBooleanGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodePrimitiveBooleanGet(param: DefaultApiTestDecodePrimitiveBooleanGetRequest = {}, options?: Configuration): Promise<boolean> {
return this.api.testDecodePrimitiveBooleanGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodePrimitiveIntegerGetWithHttpInfo(param: DefaultApiTestDecodePrimitiveIntegerGetRequest = {}, options?: Configuration): Promise<HttpInfo<number>> {
return this.api.testDecodePrimitiveIntegerGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodePrimitiveIntegerGet(param: DefaultApiTestDecodePrimitiveIntegerGetRequest = {}, options?: Configuration): Promise<number> {
return this.api.testDecodePrimitiveIntegerGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodePrimitiveNumberGetWithHttpInfo(param: DefaultApiTestDecodePrimitiveNumberGetRequest = {}, options?: Configuration): Promise<HttpInfo<number>> {
return this.api.testDecodePrimitiveNumberGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodePrimitiveNumberGet(param: DefaultApiTestDecodePrimitiveNumberGetRequest = {}, options?: Configuration): Promise<number> {
return this.api.testDecodePrimitiveNumberGet( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodePrimitiveStringGetWithHttpInfo(param: DefaultApiTestDecodePrimitiveStringGetRequest = {}, options?: Configuration): Promise<HttpInfo<string>> {
return this.api.testDecodePrimitiveStringGetWithHttpInfo( options).toPromise();
}
/**
* @param param the request object
*/
public testDecodePrimitiveStringGet(param: DefaultApiTestDecodePrimitiveStringGetRequest = {}, options?: Configuration): Promise<string> {
return this.api.testDecodePrimitiveStringGet( options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfArraysPostWithHttpInfo(param: DefaultApiTestEncodeArrayOfArraysPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeArrayOfArraysPostWithHttpInfo(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfArraysPost(param: DefaultApiTestEncodeArrayOfArraysPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeArrayOfArraysPost(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfMapsOfObjectsPostWithHttpInfo(param: DefaultApiTestEncodeArrayOfMapsOfObjectsPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeArrayOfMapsOfObjectsPostWithHttpInfo(param.complexObject, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfMapsOfObjectsPost(param: DefaultApiTestEncodeArrayOfMapsOfObjectsPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeArrayOfMapsOfObjectsPost(param.complexObject, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfNullableObjectsPostWithHttpInfo(param: DefaultApiTestEncodeArrayOfNullableObjectsPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeArrayOfNullableObjectsPostWithHttpInfo(param.complexObject, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfNullableObjectsPost(param: DefaultApiTestEncodeArrayOfNullableObjectsPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeArrayOfNullableObjectsPost(param.complexObject, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfNullablePostWithHttpInfo(param: DefaultApiTestEncodeArrayOfNullablePostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeArrayOfNullablePostWithHttpInfo(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfNullablePost(param: DefaultApiTestEncodeArrayOfNullablePostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeArrayOfNullablePost(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfPostWithHttpInfo(param: DefaultApiTestEncodeArrayOfPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeArrayOfPostWithHttpInfo(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeArrayOfPost(param: DefaultApiTestEncodeArrayOfPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeArrayOfPost(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeCompositeObjectsPostWithHttpInfo(param: DefaultApiTestEncodeCompositeObjectsPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeCompositeObjectsPostWithHttpInfo(param.compositeObject, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeCompositeObjectsPost(param: DefaultApiTestEncodeCompositeObjectsPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeCompositeObjectsPost(param.compositeObject, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeMapOfMapsOfObjectsPostWithHttpInfo(param: DefaultApiTestEncodeMapOfMapsOfObjectsPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeMapOfMapsOfObjectsPostWithHttpInfo(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeMapOfMapsOfObjectsPost(param: DefaultApiTestEncodeMapOfMapsOfObjectsPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeMapOfMapsOfObjectsPost(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeMapOfObjectsPostWithHttpInfo(param: DefaultApiTestEncodeMapOfObjectsPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeMapOfObjectsPostWithHttpInfo(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeMapOfObjectsPost(param: DefaultApiTestEncodeMapOfObjectsPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeMapOfObjectsPost(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeMapOfPrimitivePostWithHttpInfo(param: DefaultApiTestEncodeMapOfPrimitivePostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeMapOfPrimitivePostWithHttpInfo(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeMapOfPrimitivePost(param: DefaultApiTestEncodeMapOfPrimitivePostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeMapOfPrimitivePost(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeNullableArrayPostWithHttpInfo(param: DefaultApiTestEncodeNullableArrayPostRequest = {}, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeNullableArrayPostWithHttpInfo(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeNullableArrayPost(param: DefaultApiTestEncodeNullableArrayPostRequest = {}, options?: Configuration): Promise<void> {
return this.api.testEncodeNullableArrayPost(param.requestBody, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeNullablePostWithHttpInfo(param: DefaultApiTestEncodeNullablePostRequest = {}, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeNullablePostWithHttpInfo(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeNullablePost(param: DefaultApiTestEncodeNullablePostRequest = {}, options?: Configuration): Promise<void> {
return this.api.testEncodeNullablePost(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeObjectPostWithHttpInfo(param: DefaultApiTestEncodeObjectPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodeObjectPostWithHttpInfo(param.complexObject, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodeObjectPost(param: DefaultApiTestEncodeObjectPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodeObjectPost(param.complexObject, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodePrimitiveBooleanPostWithHttpInfo(param: DefaultApiTestEncodePrimitiveBooleanPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodePrimitiveBooleanPostWithHttpInfo(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodePrimitiveBooleanPost(param: DefaultApiTestEncodePrimitiveBooleanPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodePrimitiveBooleanPost(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodePrimitiveIntegerPostWithHttpInfo(param: DefaultApiTestEncodePrimitiveIntegerPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodePrimitiveIntegerPostWithHttpInfo(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodePrimitiveIntegerPost(param: DefaultApiTestEncodePrimitiveIntegerPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodePrimitiveIntegerPost(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodePrimitiveNumberPostWithHttpInfo(param: DefaultApiTestEncodePrimitiveNumberPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodePrimitiveNumberPostWithHttpInfo(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodePrimitiveNumberPost(param: DefaultApiTestEncodePrimitiveNumberPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodePrimitiveNumberPost(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodePrimitiveStringPostWithHttpInfo(param: DefaultApiTestEncodePrimitiveStringPostRequest, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.testEncodePrimitiveStringPostWithHttpInfo(param.body, options).toPromise();
}
/**
* @param param the request object
*/
public testEncodePrimitiveStringPost(param: DefaultApiTestEncodePrimitiveStringPostRequest, options?: Configuration): Promise<void> {
return this.api.testEncodePrimitiveStringPost(param.body, options).toPromise();
}
}

View File

@ -0,0 +1,920 @@
import { ResponseContext, RequestContext, HttpFile, HttpInfo } from '../http/http';
import { Configuration} from '../configuration'
import { Observable, of, from } from '../rxjsStub';
import {mergeMap, map} from '../rxjsStub';
import { ComplexObject } from '../models/ComplexObject';
import { CompositeObject } from '../models/CompositeObject';
import { DefaultApiRequestFactory, DefaultApiResponseProcessor} from "../apis/DefaultApi";
export class ObservableDefaultApi {
private requestFactory: DefaultApiRequestFactory;
private responseProcessor: DefaultApiResponseProcessor;
private configuration: Configuration;
public constructor(
configuration: Configuration,
requestFactory?: DefaultApiRequestFactory,
responseProcessor?: DefaultApiResponseProcessor
) {
this.configuration = configuration;
this.requestFactory = requestFactory || new DefaultApiRequestFactory(configuration);
this.responseProcessor = responseProcessor || new DefaultApiResponseProcessor();
}
/**
*/
public testDecodeArrayOfArraysGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<Array<Array<string>>>> {
const requestContextPromise = this.requestFactory.testDecodeArrayOfArraysGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeArrayOfArraysGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeArrayOfArraysGet(_options?: Configuration): Observable<Array<Array<string>>> {
return this.testDecodeArrayOfArraysGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<Array<Array<string>>>) => apiResponse.data));
}
/**
*/
public testDecodeArrayOfGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<Array<string>>> {
const requestContextPromise = this.requestFactory.testDecodeArrayOfGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeArrayOfGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeArrayOfGet(_options?: Configuration): Observable<Array<string>> {
return this.testDecodeArrayOfGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<Array<string>>) => apiResponse.data));
}
/**
*/
public testDecodeArrayOfMapsOfObjectsGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<Array<{ [key: string]: ComplexObject; }>>> {
const requestContextPromise = this.requestFactory.testDecodeArrayOfMapsOfObjectsGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeArrayOfMapsOfObjectsGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeArrayOfMapsOfObjectsGet(_options?: Configuration): Observable<Array<{ [key: string]: ComplexObject; }>> {
return this.testDecodeArrayOfMapsOfObjectsGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<Array<{ [key: string]: ComplexObject; }>>) => apiResponse.data));
}
/**
*/
public testDecodeArrayOfNullableGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<Array<string | null>>> {
const requestContextPromise = this.requestFactory.testDecodeArrayOfNullableGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeArrayOfNullableGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeArrayOfNullableGet(_options?: Configuration): Observable<Array<string | null>> {
return this.testDecodeArrayOfNullableGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<Array<string | null>>) => apiResponse.data));
}
/**
*/
public testDecodeArrayOfNullableObjectsGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<Array<ComplexObject>>> {
const requestContextPromise = this.requestFactory.testDecodeArrayOfNullableObjectsGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeArrayOfNullableObjectsGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeArrayOfNullableObjectsGet(_options?: Configuration): Observable<Array<ComplexObject>> {
return this.testDecodeArrayOfNullableObjectsGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<Array<ComplexObject>>) => apiResponse.data));
}
/**
*/
public testDecodeCompositeObjectsGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<CompositeObject>> {
const requestContextPromise = this.requestFactory.testDecodeCompositeObjectsGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeCompositeObjectsGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeCompositeObjectsGet(_options?: Configuration): Observable<CompositeObject> {
return this.testDecodeCompositeObjectsGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<CompositeObject>) => apiResponse.data));
}
/**
*/
public testDecodeMapOfMapsOfObjectsGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<{ [key: string]: { [key: string]: ComplexObject; }; }>> {
const requestContextPromise = this.requestFactory.testDecodeMapOfMapsOfObjectsGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeMapOfMapsOfObjectsGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeMapOfMapsOfObjectsGet(_options?: Configuration): Observable<{ [key: string]: { [key: string]: ComplexObject; }; }> {
return this.testDecodeMapOfMapsOfObjectsGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<{ [key: string]: { [key: string]: ComplexObject; }; }>) => apiResponse.data));
}
/**
*/
public testDecodeMapOfObjectsGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<{ [key: string]: ComplexObject | null; }>> {
const requestContextPromise = this.requestFactory.testDecodeMapOfObjectsGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeMapOfObjectsGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeMapOfObjectsGet(_options?: Configuration): Observable<{ [key: string]: ComplexObject | null; }> {
return this.testDecodeMapOfObjectsGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<{ [key: string]: ComplexObject | null; }>) => apiResponse.data));
}
/**
*/
public testDecodeMapOfPrimitiveGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<{ [key: string]: string; }>> {
const requestContextPromise = this.requestFactory.testDecodeMapOfPrimitiveGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeMapOfPrimitiveGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeMapOfPrimitiveGet(_options?: Configuration): Observable<{ [key: string]: string; }> {
return this.testDecodeMapOfPrimitiveGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<{ [key: string]: string; }>) => apiResponse.data));
}
/**
*/
public testDecodeNullableArrayGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<Array<string>>> {
const requestContextPromise = this.requestFactory.testDecodeNullableArrayGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeNullableArrayGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeNullableArrayGet(_options?: Configuration): Observable<Array<string>> {
return this.testDecodeNullableArrayGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<Array<string>>) => apiResponse.data));
}
/**
*/
public testDecodeNullableGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<string>> {
const requestContextPromise = this.requestFactory.testDecodeNullableGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeNullableGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeNullableGet(_options?: Configuration): Observable<string> {
return this.testDecodeNullableGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<string>) => apiResponse.data));
}
/**
*/
public testDecodeObjectGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<ComplexObject>> {
const requestContextPromise = this.requestFactory.testDecodeObjectGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodeObjectGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodeObjectGet(_options?: Configuration): Observable<ComplexObject> {
return this.testDecodeObjectGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<ComplexObject>) => apiResponse.data));
}
/**
*/
public testDecodePrimitiveBooleanGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<boolean>> {
const requestContextPromise = this.requestFactory.testDecodePrimitiveBooleanGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodePrimitiveBooleanGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodePrimitiveBooleanGet(_options?: Configuration): Observable<boolean> {
return this.testDecodePrimitiveBooleanGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<boolean>) => apiResponse.data));
}
/**
*/
public testDecodePrimitiveIntegerGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<number>> {
const requestContextPromise = this.requestFactory.testDecodePrimitiveIntegerGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodePrimitiveIntegerGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodePrimitiveIntegerGet(_options?: Configuration): Observable<number> {
return this.testDecodePrimitiveIntegerGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<number>) => apiResponse.data));
}
/**
*/
public testDecodePrimitiveNumberGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<number>> {
const requestContextPromise = this.requestFactory.testDecodePrimitiveNumberGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodePrimitiveNumberGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodePrimitiveNumberGet(_options?: Configuration): Observable<number> {
return this.testDecodePrimitiveNumberGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<number>) => apiResponse.data));
}
/**
*/
public testDecodePrimitiveStringGetWithHttpInfo(_options?: Configuration): Observable<HttpInfo<string>> {
const requestContextPromise = this.requestFactory.testDecodePrimitiveStringGet(_options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testDecodePrimitiveStringGetWithHttpInfo(rsp)));
}));
}
/**
*/
public testDecodePrimitiveStringGet(_options?: Configuration): Observable<string> {
return this.testDecodePrimitiveStringGetWithHttpInfo(_options).pipe(map((apiResponse: HttpInfo<string>) => apiResponse.data));
}
/**
* @param requestBody
*/
public testEncodeArrayOfArraysPostWithHttpInfo(requestBody: Array<Array<string>>, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeArrayOfArraysPost(requestBody, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeArrayOfArraysPostWithHttpInfo(rsp)));
}));
}
/**
* @param requestBody
*/
public testEncodeArrayOfArraysPost(requestBody: Array<Array<string>>, _options?: Configuration): Observable<void> {
return this.testEncodeArrayOfArraysPostWithHttpInfo(requestBody, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param complexObject
*/
public testEncodeArrayOfMapsOfObjectsPostWithHttpInfo(complexObject: Array<{ [key: string]: ComplexObject; }>, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeArrayOfMapsOfObjectsPost(complexObject, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeArrayOfMapsOfObjectsPostWithHttpInfo(rsp)));
}));
}
/**
* @param complexObject
*/
public testEncodeArrayOfMapsOfObjectsPost(complexObject: Array<{ [key: string]: ComplexObject; }>, _options?: Configuration): Observable<void> {
return this.testEncodeArrayOfMapsOfObjectsPostWithHttpInfo(complexObject, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param complexObject
*/
public testEncodeArrayOfNullableObjectsPostWithHttpInfo(complexObject: Array<ComplexObject>, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeArrayOfNullableObjectsPost(complexObject, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeArrayOfNullableObjectsPostWithHttpInfo(rsp)));
}));
}
/**
* @param complexObject
*/
public testEncodeArrayOfNullableObjectsPost(complexObject: Array<ComplexObject>, _options?: Configuration): Observable<void> {
return this.testEncodeArrayOfNullableObjectsPostWithHttpInfo(complexObject, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param requestBody
*/
public testEncodeArrayOfNullablePostWithHttpInfo(requestBody: Array<string | null>, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeArrayOfNullablePost(requestBody, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeArrayOfNullablePostWithHttpInfo(rsp)));
}));
}
/**
* @param requestBody
*/
public testEncodeArrayOfNullablePost(requestBody: Array<string | null>, _options?: Configuration): Observable<void> {
return this.testEncodeArrayOfNullablePostWithHttpInfo(requestBody, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param requestBody
*/
public testEncodeArrayOfPostWithHttpInfo(requestBody: Array<string>, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeArrayOfPost(requestBody, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeArrayOfPostWithHttpInfo(rsp)));
}));
}
/**
* @param requestBody
*/
public testEncodeArrayOfPost(requestBody: Array<string>, _options?: Configuration): Observable<void> {
return this.testEncodeArrayOfPostWithHttpInfo(requestBody, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param compositeObject
*/
public testEncodeCompositeObjectsPostWithHttpInfo(compositeObject: CompositeObject, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeCompositeObjectsPost(compositeObject, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeCompositeObjectsPostWithHttpInfo(rsp)));
}));
}
/**
* @param compositeObject
*/
public testEncodeCompositeObjectsPost(compositeObject: CompositeObject, _options?: Configuration): Observable<void> {
return this.testEncodeCompositeObjectsPostWithHttpInfo(compositeObject, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param requestBody
*/
public testEncodeMapOfMapsOfObjectsPostWithHttpInfo(requestBody: { [key: string]: { [key: string]: ComplexObject; }; }, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeMapOfMapsOfObjectsPost(requestBody, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeMapOfMapsOfObjectsPostWithHttpInfo(rsp)));
}));
}
/**
* @param requestBody
*/
public testEncodeMapOfMapsOfObjectsPost(requestBody: { [key: string]: { [key: string]: ComplexObject; }; }, _options?: Configuration): Observable<void> {
return this.testEncodeMapOfMapsOfObjectsPostWithHttpInfo(requestBody, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param requestBody
*/
public testEncodeMapOfObjectsPostWithHttpInfo(requestBody: { [key: string]: ComplexObject | null; }, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeMapOfObjectsPost(requestBody, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeMapOfObjectsPostWithHttpInfo(rsp)));
}));
}
/**
* @param requestBody
*/
public testEncodeMapOfObjectsPost(requestBody: { [key: string]: ComplexObject | null; }, _options?: Configuration): Observable<void> {
return this.testEncodeMapOfObjectsPostWithHttpInfo(requestBody, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param requestBody
*/
public testEncodeMapOfPrimitivePostWithHttpInfo(requestBody: { [key: string]: string; }, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeMapOfPrimitivePost(requestBody, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeMapOfPrimitivePostWithHttpInfo(rsp)));
}));
}
/**
* @param requestBody
*/
public testEncodeMapOfPrimitivePost(requestBody: { [key: string]: string; }, _options?: Configuration): Observable<void> {
return this.testEncodeMapOfPrimitivePostWithHttpInfo(requestBody, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param requestBody
*/
public testEncodeNullableArrayPostWithHttpInfo(requestBody?: Array<string>, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeNullableArrayPost(requestBody, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeNullableArrayPostWithHttpInfo(rsp)));
}));
}
/**
* @param requestBody
*/
public testEncodeNullableArrayPost(requestBody?: Array<string>, _options?: Configuration): Observable<void> {
return this.testEncodeNullableArrayPostWithHttpInfo(requestBody, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param body
*/
public testEncodeNullablePostWithHttpInfo(body?: string, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeNullablePost(body, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeNullablePostWithHttpInfo(rsp)));
}));
}
/**
* @param body
*/
public testEncodeNullablePost(body?: string, _options?: Configuration): Observable<void> {
return this.testEncodeNullablePostWithHttpInfo(body, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param complexObject
*/
public testEncodeObjectPostWithHttpInfo(complexObject: ComplexObject, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodeObjectPost(complexObject, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodeObjectPostWithHttpInfo(rsp)));
}));
}
/**
* @param complexObject
*/
public testEncodeObjectPost(complexObject: ComplexObject, _options?: Configuration): Observable<void> {
return this.testEncodeObjectPostWithHttpInfo(complexObject, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param body
*/
public testEncodePrimitiveBooleanPostWithHttpInfo(body: boolean, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodePrimitiveBooleanPost(body, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodePrimitiveBooleanPostWithHttpInfo(rsp)));
}));
}
/**
* @param body
*/
public testEncodePrimitiveBooleanPost(body: boolean, _options?: Configuration): Observable<void> {
return this.testEncodePrimitiveBooleanPostWithHttpInfo(body, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param body
*/
public testEncodePrimitiveIntegerPostWithHttpInfo(body: number, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodePrimitiveIntegerPost(body, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodePrimitiveIntegerPostWithHttpInfo(rsp)));
}));
}
/**
* @param body
*/
public testEncodePrimitiveIntegerPost(body: number, _options?: Configuration): Observable<void> {
return this.testEncodePrimitiveIntegerPostWithHttpInfo(body, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param body
*/
public testEncodePrimitiveNumberPostWithHttpInfo(body: number, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodePrimitiveNumberPost(body, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodePrimitiveNumberPostWithHttpInfo(rsp)));
}));
}
/**
* @param body
*/
public testEncodePrimitiveNumberPost(body: number, _options?: Configuration): Observable<void> {
return this.testEncodePrimitiveNumberPostWithHttpInfo(body, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
/**
* @param body
*/
public testEncodePrimitiveStringPostWithHttpInfo(body: string, _options?: Configuration): Observable<HttpInfo<void>> {
const requestContextPromise = this.requestFactory.testEncodePrimitiveStringPost(body, _options);
// build promise chain
let middlewarePreObservable = from<RequestContext>(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
pipe(mergeMap((response: ResponseContext) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.testEncodePrimitiveStringPostWithHttpInfo(rsp)));
}));
}
/**
* @param body
*/
public testEncodePrimitiveStringPost(body: string, _options?: Configuration): Observable<void> {
return this.testEncodePrimitiveStringPostWithHttpInfo(body, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
}
}

View File

@ -0,0 +1,504 @@
import { ResponseContext, RequestContext, HttpFile, HttpInfo } from '../http/http';
import { Configuration} from '../configuration'
import { ComplexObject } from '../models/ComplexObject';
import { CompositeObject } from '../models/CompositeObject';
import { ObservableDefaultApi } from './ObservableAPI';
import { DefaultApiRequestFactory, DefaultApiResponseProcessor} from "../apis/DefaultApi";
export class PromiseDefaultApi {
private api: ObservableDefaultApi
public constructor(
configuration: Configuration,
requestFactory?: DefaultApiRequestFactory,
responseProcessor?: DefaultApiResponseProcessor
) {
this.api = new ObservableDefaultApi(configuration, requestFactory, responseProcessor);
}
/**
*/
public testDecodeArrayOfArraysGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<Array<Array<string>>>> {
const result = this.api.testDecodeArrayOfArraysGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfArraysGet(_options?: Configuration): Promise<Array<Array<string>>> {
const result = this.api.testDecodeArrayOfArraysGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<Array<string>>> {
const result = this.api.testDecodeArrayOfGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfGet(_options?: Configuration): Promise<Array<string>> {
const result = this.api.testDecodeArrayOfGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfMapsOfObjectsGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<Array<{ [key: string]: ComplexObject; }>>> {
const result = this.api.testDecodeArrayOfMapsOfObjectsGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfMapsOfObjectsGet(_options?: Configuration): Promise<Array<{ [key: string]: ComplexObject; }>> {
const result = this.api.testDecodeArrayOfMapsOfObjectsGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfNullableGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<Array<string | null>>> {
const result = this.api.testDecodeArrayOfNullableGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfNullableGet(_options?: Configuration): Promise<Array<string | null>> {
const result = this.api.testDecodeArrayOfNullableGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfNullableObjectsGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<Array<ComplexObject>>> {
const result = this.api.testDecodeArrayOfNullableObjectsGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeArrayOfNullableObjectsGet(_options?: Configuration): Promise<Array<ComplexObject>> {
const result = this.api.testDecodeArrayOfNullableObjectsGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeCompositeObjectsGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<CompositeObject>> {
const result = this.api.testDecodeCompositeObjectsGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeCompositeObjectsGet(_options?: Configuration): Promise<CompositeObject> {
const result = this.api.testDecodeCompositeObjectsGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeMapOfMapsOfObjectsGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<{ [key: string]: { [key: string]: ComplexObject; }; }>> {
const result = this.api.testDecodeMapOfMapsOfObjectsGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeMapOfMapsOfObjectsGet(_options?: Configuration): Promise<{ [key: string]: { [key: string]: ComplexObject; }; }> {
const result = this.api.testDecodeMapOfMapsOfObjectsGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeMapOfObjectsGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<{ [key: string]: ComplexObject | null; }>> {
const result = this.api.testDecodeMapOfObjectsGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeMapOfObjectsGet(_options?: Configuration): Promise<{ [key: string]: ComplexObject | null; }> {
const result = this.api.testDecodeMapOfObjectsGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeMapOfPrimitiveGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<{ [key: string]: string; }>> {
const result = this.api.testDecodeMapOfPrimitiveGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeMapOfPrimitiveGet(_options?: Configuration): Promise<{ [key: string]: string; }> {
const result = this.api.testDecodeMapOfPrimitiveGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeNullableArrayGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<Array<string>>> {
const result = this.api.testDecodeNullableArrayGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeNullableArrayGet(_options?: Configuration): Promise<Array<string>> {
const result = this.api.testDecodeNullableArrayGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeNullableGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<string>> {
const result = this.api.testDecodeNullableGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeNullableGet(_options?: Configuration): Promise<string> {
const result = this.api.testDecodeNullableGet(_options);
return result.toPromise();
}
/**
*/
public testDecodeObjectGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<ComplexObject>> {
const result = this.api.testDecodeObjectGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodeObjectGet(_options?: Configuration): Promise<ComplexObject> {
const result = this.api.testDecodeObjectGet(_options);
return result.toPromise();
}
/**
*/
public testDecodePrimitiveBooleanGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<boolean>> {
const result = this.api.testDecodePrimitiveBooleanGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodePrimitiveBooleanGet(_options?: Configuration): Promise<boolean> {
const result = this.api.testDecodePrimitiveBooleanGet(_options);
return result.toPromise();
}
/**
*/
public testDecodePrimitiveIntegerGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<number>> {
const result = this.api.testDecodePrimitiveIntegerGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodePrimitiveIntegerGet(_options?: Configuration): Promise<number> {
const result = this.api.testDecodePrimitiveIntegerGet(_options);
return result.toPromise();
}
/**
*/
public testDecodePrimitiveNumberGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<number>> {
const result = this.api.testDecodePrimitiveNumberGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodePrimitiveNumberGet(_options?: Configuration): Promise<number> {
const result = this.api.testDecodePrimitiveNumberGet(_options);
return result.toPromise();
}
/**
*/
public testDecodePrimitiveStringGetWithHttpInfo(_options?: Configuration): Promise<HttpInfo<string>> {
const result = this.api.testDecodePrimitiveStringGetWithHttpInfo(_options);
return result.toPromise();
}
/**
*/
public testDecodePrimitiveStringGet(_options?: Configuration): Promise<string> {
const result = this.api.testDecodePrimitiveStringGet(_options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeArrayOfArraysPostWithHttpInfo(requestBody: Array<Array<string>>, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeArrayOfArraysPostWithHttpInfo(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeArrayOfArraysPost(requestBody: Array<Array<string>>, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeArrayOfArraysPost(requestBody, _options);
return result.toPromise();
}
/**
* @param complexObject
*/
public testEncodeArrayOfMapsOfObjectsPostWithHttpInfo(complexObject: Array<{ [key: string]: ComplexObject; }>, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeArrayOfMapsOfObjectsPostWithHttpInfo(complexObject, _options);
return result.toPromise();
}
/**
* @param complexObject
*/
public testEncodeArrayOfMapsOfObjectsPost(complexObject: Array<{ [key: string]: ComplexObject; }>, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeArrayOfMapsOfObjectsPost(complexObject, _options);
return result.toPromise();
}
/**
* @param complexObject
*/
public testEncodeArrayOfNullableObjectsPostWithHttpInfo(complexObject: Array<ComplexObject>, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeArrayOfNullableObjectsPostWithHttpInfo(complexObject, _options);
return result.toPromise();
}
/**
* @param complexObject
*/
public testEncodeArrayOfNullableObjectsPost(complexObject: Array<ComplexObject>, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeArrayOfNullableObjectsPost(complexObject, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeArrayOfNullablePostWithHttpInfo(requestBody: Array<string | null>, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeArrayOfNullablePostWithHttpInfo(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeArrayOfNullablePost(requestBody: Array<string | null>, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeArrayOfNullablePost(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeArrayOfPostWithHttpInfo(requestBody: Array<string>, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeArrayOfPostWithHttpInfo(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeArrayOfPost(requestBody: Array<string>, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeArrayOfPost(requestBody, _options);
return result.toPromise();
}
/**
* @param compositeObject
*/
public testEncodeCompositeObjectsPostWithHttpInfo(compositeObject: CompositeObject, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeCompositeObjectsPostWithHttpInfo(compositeObject, _options);
return result.toPromise();
}
/**
* @param compositeObject
*/
public testEncodeCompositeObjectsPost(compositeObject: CompositeObject, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeCompositeObjectsPost(compositeObject, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeMapOfMapsOfObjectsPostWithHttpInfo(requestBody: { [key: string]: { [key: string]: ComplexObject; }; }, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeMapOfMapsOfObjectsPostWithHttpInfo(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeMapOfMapsOfObjectsPost(requestBody: { [key: string]: { [key: string]: ComplexObject; }; }, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeMapOfMapsOfObjectsPost(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeMapOfObjectsPostWithHttpInfo(requestBody: { [key: string]: ComplexObject | null; }, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeMapOfObjectsPostWithHttpInfo(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeMapOfObjectsPost(requestBody: { [key: string]: ComplexObject | null; }, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeMapOfObjectsPost(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeMapOfPrimitivePostWithHttpInfo(requestBody: { [key: string]: string; }, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeMapOfPrimitivePostWithHttpInfo(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeMapOfPrimitivePost(requestBody: { [key: string]: string; }, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeMapOfPrimitivePost(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeNullableArrayPostWithHttpInfo(requestBody?: Array<string>, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeNullableArrayPostWithHttpInfo(requestBody, _options);
return result.toPromise();
}
/**
* @param requestBody
*/
public testEncodeNullableArrayPost(requestBody?: Array<string>, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeNullableArrayPost(requestBody, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodeNullablePostWithHttpInfo(body?: string, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeNullablePostWithHttpInfo(body, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodeNullablePost(body?: string, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeNullablePost(body, _options);
return result.toPromise();
}
/**
* @param complexObject
*/
public testEncodeObjectPostWithHttpInfo(complexObject: ComplexObject, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodeObjectPostWithHttpInfo(complexObject, _options);
return result.toPromise();
}
/**
* @param complexObject
*/
public testEncodeObjectPost(complexObject: ComplexObject, _options?: Configuration): Promise<void> {
const result = this.api.testEncodeObjectPost(complexObject, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodePrimitiveBooleanPostWithHttpInfo(body: boolean, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodePrimitiveBooleanPostWithHttpInfo(body, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodePrimitiveBooleanPost(body: boolean, _options?: Configuration): Promise<void> {
const result = this.api.testEncodePrimitiveBooleanPost(body, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodePrimitiveIntegerPostWithHttpInfo(body: number, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodePrimitiveIntegerPostWithHttpInfo(body, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodePrimitiveIntegerPost(body: number, _options?: Configuration): Promise<void> {
const result = this.api.testEncodePrimitiveIntegerPost(body, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodePrimitiveNumberPostWithHttpInfo(body: number, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodePrimitiveNumberPostWithHttpInfo(body, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodePrimitiveNumberPost(body: number, _options?: Configuration): Promise<void> {
const result = this.api.testEncodePrimitiveNumberPost(body, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodePrimitiveStringPostWithHttpInfo(body: string, _options?: Configuration): Promise<HttpInfo<void>> {
const result = this.api.testEncodePrimitiveStringPostWithHttpInfo(body, _options);
return result.toPromise();
}
/**
* @param body
*/
public testEncodePrimitiveStringPost(body: string, _options?: Configuration): Promise<void> {
const result = this.api.testEncodePrimitiveStringPost(body, _options);
return result.toPromise();
}
}

View File

@ -0,0 +1,37 @@
/**
* Returns if a specific http code is in a given code range
* where the code range is defined as a combination of digits
* and "X" (the letter X) with a length of 3
*
* @param codeRange string with length 3 consisting of digits and "X" (the letter X)
* @param code the http status code to be checked against the code range
*/
export function isCodeInRange(codeRange: string, code: number): boolean {
// This is how the default value is encoded in OAG
if (codeRange === "0") {
return true;
}
if (codeRange == code.toString()) {
return true;
} else {
const codeString = code.toString();
if (codeString.length != codeRange.length) {
return false;
}
for (let i = 0; i < codeString.length; i++) {
if (codeRange.charAt(i) != "X" && codeRange.charAt(i) != codeString.charAt(i)) {
return false;
}
}
return true;
}
}
/**
* Returns if it can consume form
*
* @param consumes array
*/
export function canConsumeForm(contentTypes: string[]): boolean {
return contentTypes.indexOf('multipart/form-data') !== -1
}

View File

@ -0,0 +1,2 @@
dist
node_modules

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
{
"private": true,
"dependencies": {
"@openapitools/typescript-encode-decode": "file:../build",
"@types/chai": "^4.3.0",
"@types/mocha": "^10.0.0",
"@types/node": "^16.6.2",
"chai": "^4.3.0",
"mocha": "^10.2.0",
"ts-node": "^10.9.0",
"typescript": "^5.2.2"
},
"scripts": {
"preinstall": "npm --prefix ../build install",
"test": "mocha test/*.spec.ts --require ts-node/register --timeout 10000"
},
"name": "typescript-encode-decode-test",
"version": "1.0.0",
"directories": {
"test": "test"
},
"author": "",
"license": "ISC",
"description": ""
}

View File

@ -0,0 +1,407 @@
import {
DefaultApi,
} from '@openapitools/typescript-encode-decode';
import { expect } from 'chai';
import { apiConfiguration, mockServer } from './server';
const api = new DefaultApi(apiConfiguration);
describe('deserialization', () => {
it('deserializes primitive booleans', async () => {
const response = await api.testDecodePrimitiveBooleanGet();
expect(response).to.be.true;
});
it('deserializes primitive integers', async () => {
const response = await api.testDecodePrimitiveIntegerGet();
expect(response).to.equal(42);
});
it('deserializes primitive numbers', async () => {
const response = await api.testDecodePrimitiveNumberGet();
expect(response).to.equal(42.42);
});
it('deserializes primitive strings', async () => {
const response = await api.testDecodePrimitiveStringGet();
expect(response).to.equal('some string value');
});
it('deserializes nullable strings', async () => {
const response = await api.testDecodeNullableGet();
expect(response).to.equal(null);
});
it('deserializes arrays of strings', async () => {
const response = await api.testDecodeArrayOfGet();
expect(response).to.deep.equal(["first", "second", "third"]);
});
it('deserializes arrays of nullable strings', async () => {
const response = await api.testDecodeArrayOfNullableGet();
expect(response).to.deep.equal(["first", null, "third"]);
});
it('deserializes nullable arrays', async () => {
const response = await api.testDecodeNullableArrayGet();
expect(response).to.equal(null);
});
it('deserializes arrays of arrays', async () => {
const response = await api.testDecodeArrayOfArraysGet();
expect(response).to.deep.equal([["first", "second"], ["third"]]);
});
it('deserializes objects', async () => {
const response = await api.testDecodeObjectGet();
expect(response).to.deep.equal({
requiredProperty: "required",
requiredNullableProperty: null,
optionalNullableProperty: null,
});
});
it('deserializes maps of primitives', async () => {
const response = await api.testDecodeMapOfPrimitiveGet();
expect(response).to.deep.equal({
key1: "value1",
key2: "value2",
});
});
it('deserializes maps of objects', async () => {
const response = await api.testDecodeMapOfObjectsGet();
expect(response).to.deep.equal({
barebones: {
requiredProperty: "first",
requiredNullableProperty: null,
},
nulls: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
values: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
});
});
it('deserializes maps of maps of objects', async () => {
const response = await api.testDecodeMapOfMapsOfObjectsGet();
expect(response).to.deep.equal({
key1: {
key1: {
requiredProperty: "first",
requiredNullableProperty: null,
},
key2: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
},
key2: {
key3: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
}
});
});
it('deserializes arrays of maps of objects', async () => {
const response = await api.testDecodeArrayOfMapsOfObjectsGet();
expect(response).to.deep.equal([
{
key1: {
requiredProperty: "first",
requiredNullableProperty: null,
},
key2: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
},
{
key3: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
}
]);
});
it('deserializes arrays of nullable objects', async () => {
const response = await api.testDecodeArrayOfNullableObjectsGet();
expect(response).to.deep.equal([
{
requiredProperty: "first",
requiredNullableProperty: null,
},
null,
{
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
]);
});
it('deserializes composite objects', async () => {
const response = await api.testDecodeCompositeObjectsGet();
expect(response).to.deep.equal({
optionalNullableInnerObject: {
requiredProperty: "required",
requiredNullableProperty: null,
},
});
});
});
describe("serialization", () => {
it("serializes primitive booleans", async () => {
await api.testEncodePrimitiveBooleanPost(true);
expect(mockServer.lastRequestBody).to.equal(true);
});
it("serializes primitive integers", async () => {
await api.testEncodePrimitiveIntegerPost(42);
expect(mockServer.lastRequestBody).to.equal(42);
});
it("serializes primitive numbers", async () => {
await api.testEncodePrimitiveNumberPost(42.42);
expect(mockServer.lastRequestBody).to.equal(42.42);
});
it("serializes primitive strings", async () => {
await api.testEncodePrimitiveStringPost("some string value");
expect(mockServer.lastRequestBody).to.equal("some string value");
});
it("serializes nullable strings", async () => {
await api.testEncodeNullablePost(null);
expect(mockServer.lastRequestBody).to.equal(null);
});
it("serializes arrays of strings", async () => {
await api.testEncodeArrayOfPost(["first", "second", "third"]);
expect(mockServer.lastRequestBody).to.deep.equal(["first", "second", "third"]);
});
it("serializes arrays of nullable strings", async () => {
await api.testEncodeArrayOfNullablePost(["first", null, "third"]);
expect(mockServer.lastRequestBody).to.deep.equal(["first", null, "third"]);
});
it("serializes nullable arrays", async () => {
await api.testEncodeNullableArrayPost(null);
expect(mockServer.lastRequestBody).to.equal(null);
});
it("serializes arrays of arrays", async () => {
await api.testEncodeArrayOfArraysPost([["first", "second"], ["third"]]);
expect(mockServer.lastRequestBody).to.deep.equal([["first", "second"], ["third"]]);
});
it("serializes objects", async () => {
await api.testEncodeObjectPost({
requiredProperty: "required",
requiredNullableProperty: null,
optionalNullableProperty: null,
});
expect(mockServer.lastRequestBody).to.deep.equal({
required_property: "required",
required_nullable_property: null,
optional_nullable_property: null,
});
});
it("serializes maps of primitives", async () => {
await api.testEncodeMapOfPrimitivePost({
key1: "value1",
key2: "value2",
});
expect(mockServer.lastRequestBody).to.deep.equal({
key1: "value1",
key2: "value2",
});
});
it("serializes maps of objects", async () => {
await api.testEncodeMapOfObjectsPost({
barebones: {
requiredProperty: "first",
requiredNullableProperty: null,
},
nulls: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
values: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
});
expect(mockServer.lastRequestBody).to.deep.equal({
barebones: {
required_property: "first",
required_nullable_property: null,
},
nulls: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
values: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
});
});
it("serializes maps of maps of objects", async () => {
await api.testEncodeMapOfMapsOfObjectsPost({
key1: {
key1: {
requiredProperty: "first",
requiredNullableProperty: null,
},
key2: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
},
key2: {
key3: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
}
});
expect(mockServer.lastRequestBody).to.deep.equal({
key1: {
key1: {
required_property: "first",
required_nullable_property: null,
},
key2: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
},
key2: {
key3: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
}
});
});
it("serializes arrays of maps of objects", async () => {
await api.testEncodeArrayOfMapsOfObjectsPost([
{
key1: {
requiredProperty: "first",
requiredNullableProperty: null,
},
key2: {
requiredProperty: "second",
requiredNullableProperty: null,
optionalNullableProperty: null,
},
},
{
key3: {
requiredProperty: "third",
requiredNullableProperty: "foo",
optionalProperty: "bar",
optionalNullableProperty: "baz",
}
}
]);
expect(mockServer.lastRequestBody).to.deep.equal([
{
key1: {
required_property: "first",
required_nullable_property: null,
},
key2: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
},
{
key3: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
}
]);
});
it("serializes arrays of nullable objects", async () => {
await api.testEncodeArrayOfNullableObjectsPost([
{
requiredProperty: "first",
requiredNullableProperty: null,
},
null,
{
requiredProperty: "third",
requiredNullableProperty: "foo",
}
]);
expect(mockServer.lastRequestBody).to.deep.equal([
{
required_property: "first",
required_nullable_property: null,
},
null,
{
required_property: "third",
required_nullable_property: "foo",
}
]);
});
it("serializes composite objects", async () => {
await api.testEncodeCompositeObjectsPost({
optionalNullableInnerObject: {
requiredProperty: "required",
requiredNullableProperty: null,
},
});
expect(mockServer.lastRequestBody).to.deep.equal({
optional_nullable_inner_object: {
required_property: "required",
required_nullable_property: null,
},
});
});
});

View File

@ -0,0 +1,174 @@
import {
createConfiguration,
PromiseHttpLibrary,
RequestContext,
ResponseBody,
ResponseContext,
ServerConfiguration,
wrapHttpLibrary,
} from '@openapitools/typescript-encode-decode';
const BASE_URL = 'http://localhost:1234';
class TestServerStub implements PromiseHttpLibrary {
public lastRequestBody: any = null;
async send(request: RequestContext): Promise<ResponseContext> {
const url = request.getUrl();
if (!url.startsWith(BASE_URL)) {
throw new Error(`unexpected url: ${url}`);
}
const path = url.substring(BASE_URL.length);
if (path.startsWith('/test/decode')) {
const value = this.valueForPath(path);
const body: ResponseBody = {
binary: async () => { throw new Error('not implemented') },
text: async () => JSON.stringify(value),
};
const headers = { 'content-type': 'application/json' };
return new ResponseContext(200, headers, body);
} else if (path.startsWith('/test/encode/')) {
const rawBody = request.getBody().toString();
this.lastRequestBody = JSON.parse(rawBody);
const body: ResponseBody = {
binary: async () => { throw new Error('not implemented') },
text: async () => "",
};
return new ResponseContext(200, {}, body);
} else {
throw new Error(`unexpected path: ${path}`);
}
}
private valueForPath(path: string): any {
if (path.startsWith('/test/encode')) {
return "";
}
switch (path) {
case '/test/decode/primitive/boolean':
return true;
case '/test/decode/primitive/integer':
return 42;
case '/test/decode/primitive/number':
return 42.42;
case '/test/decode/primitive/string':
return 'some string value';
case '/test/decode/nullable':
return null;
case '/test/decode/array-of':
return ["first", "second", "third"];
case '/test/decode/array-of/nullable':
return ["first", null, "third"];
case '/test/decode/nullable-array':
return null;
case '/test/decode/array-of-arrays':
return [["first", "second"], ["third"]];
case '/test/decode/object':
return {
required_property: "required",
required_nullable_property: null,
optional_nullable_property: null,
};
case '/test/decode/map-of/primitive':
return {
key1: "value1",
key2: "value2",
};
case '/test/decode/map-of/objects':
return {
barebones: {
required_property: "first",
required_nullable_property: null,
},
nulls: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
values: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
};
case '/test/decode/map-of/maps-of/objects':
return {
key1: {
key1: {
required_property: "first",
required_nullable_property: null,
},
key2: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
},
key2: {
key3: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
}
};
case '/test/decode/array-of/maps-of/objects':
return [
{
key1: {
required_property: "first",
required_nullable_property: null,
},
key2: {
required_property: "second",
required_nullable_property: null,
optional_nullable_property: null,
},
},
{
key3: {
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
}
];
case '/test/decode/composite-objects':
return {
optional_nullable_inner_object: {
required_property: "required",
required_nullable_property: null,
},
};
case '/test/decode/array-of/nullable-objects':
return [
{
required_property: "first",
required_nullable_property: null,
},
null,
{
required_property: "third",
required_nullable_property: "foo",
optional_property: "bar",
optional_nullable_property: "baz",
}
];
default:
throw new Error(`unexpected path: ${path}`);
}
}
}
export const mockServer = new TestServerStub();
export const apiConfiguration = createConfiguration({
baseServer: new ServerConfiguration(BASE_URL, {}),
httpApi: wrapHttpLibrary(mockServer),
});

View File

@ -0,0 +1,20 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "CommonJS",
"target": "ES5",
"noImplicitAny": true,
"sourceMap": false,
"outDir": "dist",
"types": [
"mocha"
],
"lib": [
"es6",
"dom"
]
},
"exclude": [
"node_modules"
]
}

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es6",
"module": "es6",
"moduleResolution": "node",

View File

@ -3,7 +3,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es6",
"module": "es6",
"moduleResolution": "node",

View File

@ -2,7 +2,6 @@
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "ES5",
"moduleResolution": "node",
"removeComments": true,

View File

@ -53,6 +53,23 @@ let typeMap: {[index: string]: any} = {
"User": User,
}
// Check if a string starts with another string without using es6 features
function startsWith(str: string, match: string): boolean {
return str.substring(0, match.length) === match;
}
// Check if a string ends with another string without using es6 features
function endsWith(str: string, match: string): boolean {
return str.length >= match.length && str.substring(str.length - match.length) === match;
}
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -89,20 +106,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string) {
public static serialize(data: any, type: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (endsWith(type, nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType);
} else if (endsWith(type, optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType);
} else if (startsWith(type, arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.serialize(datum, subType));
}
return transformedData;
} else if (startsWith(type, mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
);
}
return transformedData;
} else if (type === "Date") {
return data.toISOString();
} else {
@ -127,22 +159,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string) {
public static deserialize(data: any, type: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (endsWith(type, nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType);
} else if (endsWith(type, optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType);
} else if (startsWith(type, arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.deserialize(datum, subType));
}
return transformedData;
} else if (startsWith(type, mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -53,6 +53,23 @@ let typeMap: {[index: string]: any} = {
"User": User,
}
// Check if a string starts with another string without using es6 features
function startsWith(str: string, match: string): boolean {
return str.substring(0, match.length) === match;
}
// Check if a string ends with another string without using es6 features
function endsWith(str: string, match: string): boolean {
return str.length >= match.length && str.substring(str.length - match.length) === match;
}
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -89,20 +106,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string) {
public static serialize(data: any, type: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (endsWith(type, nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType);
} else if (endsWith(type, optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType);
} else if (startsWith(type, arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.serialize(datum, subType));
}
return transformedData;
} else if (startsWith(type, mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
);
}
return transformedData;
} else if (type === "Date") {
return data.toISOString();
} else {
@ -127,22 +159,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string) {
public static deserialize(data: any, type: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (endsWith(type, nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType);
} else if (endsWith(type, optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType);
} else if (startsWith(type, arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.deserialize(datum, subType));
}
return transformedData;
} else if (startsWith(type, mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -2,7 +2,6 @@
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "ES5",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,

View File

@ -90,6 +90,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -129,19 +136,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -174,21 +197,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -95,6 +95,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -134,19 +141,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -179,21 +202,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -90,6 +90,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -129,19 +136,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -174,21 +197,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -90,6 +90,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -129,19 +136,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -174,21 +197,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -90,6 +90,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -129,19 +136,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -174,21 +197,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -220,6 +220,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -259,19 +266,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -304,21 +327,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -90,6 +90,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -129,19 +136,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -174,21 +197,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -90,6 +90,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -129,19 +136,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -174,21 +197,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -74,6 +74,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -113,19 +120,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -158,21 +181,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {

View File

@ -90,6 +90,13 @@ const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
export class ObjectSerializer {
public static findCorrectType(data: any, expectedType: string) {
if (data == undefined) {
@ -129,19 +136,35 @@ export class ObjectSerializer {
}
}
public static serialize(data: any, type: string, format: string) {
public static serialize(data: any, type: string, format: string): any {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth()+1
@ -174,21 +197,37 @@ export class ObjectSerializer {
}
}
public static deserialize(data: any, type: string, format: string) {
public static deserialize(data: any, type: string, format: string): any {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
} else if (type.endsWith(nullableSuffix)) {
let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData: any[] = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData: { [key: string]: any } = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(
data[key],
subType,
format,
);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {