[TS-Refactor] Top-level exports for fetch & jquery (#6138)

* Added top-level exports
* Updated generator README
* Updated typescript generator docs
This commit is contained in:
Tino Fuhrmann 2020-05-04 23:58:38 +02:00 committed by GitHub
parent 07dd1efb7a
commit 934f226098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 314 additions and 136 deletions

View File

@ -62,7 +62,7 @@ The following generators are available:
* [swift3-deprecated (deprecated)](generators/swift3-deprecated.md) * [swift3-deprecated (deprecated)](generators/swift3-deprecated.md)
* [swift4](generators/swift4.md) * [swift4](generators/swift4.md)
* [swift5 (beta)](generators/swift5.md) * [swift5 (beta)](generators/swift5.md)
* [typescript](generators/typescript.md) * [typescript (experimental)](generators/typescript.md)
* [typescript-angular](generators/typescript-angular.md) * [typescript-angular](generators/typescript-angular.md)
* [typescript-angularjs](generators/typescript-angularjs.md) * [typescript-angularjs](generators/typescript-angularjs.md)
* [typescript-aurelia](generators/typescript-aurelia.md) * [typescript-aurelia](generators/typescript-aurelia.md)

View File

@ -5,13 +5,239 @@ sidebar_label: typescript
| Option | Description | Values | Default | | Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- | | ------ | ----------- | ------ | ------- |
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| |allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
|supportsES6|Generate code that conforms to ES6.| |false|
|fileContentDataType|Specifies the type to use for the content of a file - i.e. Blob (Browser) / Buffer (node)| |Buffer| |fileContentDataType|Specifies the type to use for the content of a file - i.e. Blob (Browser) / Buffer (node)| |Buffer|
|useRxJS|Enable this to internally use rxjs observables. If disabled, a stub is used instead. This is required for the 'angular' framework.| |false| |framework|Specify the framework which should be used in the client code.|<dl><dt>**fetch-api**</dt><dd>fetch-api</dd><dt>**jquery**</dt><dd>jquery</dd></dl>|fetch-api|
|legacyDiscriminatorBehavior|This flag is used by OpenAPITools codegen to influence the processing of the discriminator attribute in OpenAPI documents. This flag has no impact if the OAS document does not use the discriminator attribute. The default value of this flag is set in each language-specific code generator (e.g. Python, Java, go...)using the method toModelName.
When this flag is set to false:
- The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document.
- Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
When this flag is set to true:
- The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
Note to developers supporting a language generator in OpenAPITools: to fully support the discriminator attribute as defined in the OAS specification 3.x, language generators should set this flag to true by default; however this requires updating the mustache templates to generate a language-specific discriminator lookup function that iterates over {{#mappedModels}} and does not iterate over {{children}}, {{#anyOf}}, or {{#oneOf}}.| |true|
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
|platform|Specifies the platform the code should run on. The default is 'node' for the 'request' framework and 'browser' otherwise.| |null| |platform|Specifies the platform the code should run on. The default is 'node' for the 'request' framework and 'browser' otherwise.| |null|
|framework|Specify the framework which should be used in the client code.|<dl><dt>**fetch-api**</dt><dd>fetch-api</dd><dt>**jquery**</dt><dd>jquery</dd><dl>|fetch-api| |prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|supportsES6|Generate code that conforms to ES6.| |false|
|useRxJS|Enable this to internally use rxjs observables. If disabled, a stub is used instead. This is required for the 'angular' framework.| |false|
## IMPORT MAPPING
| Type/Alias | Imports |
| ---------- | ------- |
## INSTANTIATION TYPES
| Type/Alias | Instantiated By |
| ---------- | --------------- |
|array|Array|
## LANGUAGE PRIMITIVES
<ul class="column-ul">
<li>Array</li>
<li>Boolean</li>
<li>Date</li>
<li>Double</li>
<li>Error</li>
<li>File</li>
<li>Float</li>
<li>Integer</li>
<li>Long</li>
<li>Map</li>
<li>Object</li>
<li>String</li>
<li>any</li>
<li>boolean</li>
<li>number</li>
<li>string</li>
</ul>
## RESERVED WORDS
<ul class="column-ul">
<li>abstract</li>
<li>await</li>
<li>boolean</li>
<li>break</li>
<li>byte</li>
<li>case</li>
<li>catch</li>
<li>char</li>
<li>class</li>
<li>const</li>
<li>continue</li>
<li>debugger</li>
<li>default</li>
<li>delete</li>
<li>do</li>
<li>double</li>
<li>else</li>
<li>enum</li>
<li>export</li>
<li>extends</li>
<li>false</li>
<li>final</li>
<li>finally</li>
<li>float</li>
<li>for</li>
<li>formParams</li>
<li>function</li>
<li>goto</li>
<li>headerParams</li>
<li>if</li>
<li>implements</li>
<li>import</li>
<li>in</li>
<li>instanceof</li>
<li>int</li>
<li>interface</li>
<li>let</li>
<li>long</li>
<li>native</li>
<li>new</li>
<li>null</li>
<li>package</li>
<li>private</li>
<li>protected</li>
<li>public</li>
<li>queryParameters</li>
<li>requestOptions</li>
<li>return</li>
<li>short</li>
<li>static</li>
<li>super</li>
<li>switch</li>
<li>synchronized</li>
<li>this</li>
<li>throw</li>
<li>transient</li>
<li>true</li>
<li>try</li>
<li>typeof</li>
<li>useFormData</li>
<li>var</li>
<li>varLocalDeferred</li>
<li>varLocalPath</li>
<li>void</li>
<li>volatile</li>
<li>while</li>
<li>with</li>
<li>yield</li>
</ul>
## FEATURE SET
### Client Modification Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasePath|✗|ToolingExtension
|Authorizations|✗|ToolingExtension
|UserAgent|✗|ToolingExtension
### Data Type Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Custom|✗|OAS2,OAS3
|Int32|✓|OAS2,OAS3
|Int64|✓|OAS2,OAS3
|Float|✓|OAS2,OAS3
|Double|✓|OAS2,OAS3
|Decimal|✓|ToolingExtension
|String|✓|OAS2,OAS3
|Byte|✓|OAS2,OAS3
|Binary|✓|OAS2,OAS3
|Boolean|✓|OAS2,OAS3
|Date|✓|OAS2,OAS3
|DateTime|✓|OAS2,OAS3
|Password|✓|OAS2,OAS3
|File|✓|OAS2
|Array|✓|OAS2,OAS3
|Maps|✓|ToolingExtension
|CollectionFormat|✓|OAS2
|CollectionFormatMulti|✓|OAS2
|Enum|✓|OAS2,OAS3
|ArrayOfEnum|✓|ToolingExtension
|ArrayOfModel|✓|ToolingExtension
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|ArrayOfCollectionOfModel|✓|ToolingExtension
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|MapOfEnum|✓|ToolingExtension
|MapOfModel|✓|ToolingExtension
|MapOfCollectionOfPrimitives|✓|ToolingExtension
|MapOfCollectionOfModel|✓|ToolingExtension
|MapOfCollectionOfEnum|✓|ToolingExtension
### Documentation Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Readme|✗|ToolingExtension
|Model|✓|ToolingExtension
|Api|✓|ToolingExtension
### Global Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Host|✓|OAS2,OAS3
|BasePath|✓|OAS2,OAS3
|Info|✓|OAS2,OAS3
|Schemes|✗|OAS2,OAS3
|PartialSchemes|✓|OAS2,OAS3
|Consumes|✓|OAS2
|Produces|✓|OAS2
|ExternalDocumentation|✓|OAS2,OAS3
|Examples|✓|OAS2,OAS3
|XMLStructureDefinitions|✗|OAS2,OAS3
|MultiServer|✗|OAS3
|ParameterizedServer|✗|OAS3
|ParameterStyling|✗|OAS3
|Callbacks|✓|OAS3
|LinkObjects|✗|OAS3
### Parameter Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Path|✓|OAS2,OAS3
|Query|✓|OAS2,OAS3
|Header|✓|OAS2,OAS3
|Body|✓|OAS2
|FormUnencoded|✓|OAS2
|FormMultipart|✓|OAS2
|Cookie|✓|OAS3
### Schema Support Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Simple|✓|OAS2,OAS3
|Composite|✓|OAS2,OAS3
|Polymorphism|✓|OAS2,OAS3
|Union|✗|OAS3
### Security Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasicAuth|✓|OAS2,OAS3
|ApiKey|✓|OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken|✓|OAS3
|OAuth2_Implicit|✓|OAS2,OAS3
|OAuth2_Password|✓|OAS2,OAS3
|OAuth2_ClientCredentials|✓|OAS2,OAS3
|OAuth2_AuthorizationCode|✓|OAS2,OAS3
### Wire Format Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|JSON|✓|OAS2,OAS3
|XML|✓|OAS2,OAS3
|PROTOBUF|✗|ToolingExtension
|Custom|✗|OAS2,OAS3

View File

@ -1,19 +1,7 @@
import * as http from './http/http'; export * from './http/http';
import * as auth from './auth/auth'; export * from './auth/auth';
import {Middleware, PromiseMiddleware} from './middleware'; export {Middleware, PromiseMiddleware} from './middleware';
import * as models from './models/all'; export * from './models/all';
import { Configuration} from './configuration' export { Configuration} from './configuration'
import * as apis from './types/PromiseAPI'; export * from './types/PromiseAPI';
import * as exceptions from './apis/exception'; export * from './apis/exception';
export {
http,
auth,
Middleware,
PromiseMiddleware,
models,
Configuration,
apis,
exceptions
};

View File

@ -1,19 +1,7 @@
import * as http from './http/http'; export * from './http/http';
import * as auth from './auth/auth'; export * from './auth/auth';
import {Middleware, PromiseMiddleware} from './middleware'; export {Middleware, PromiseMiddleware} from './middleware';
import * as models from './models/all'; export * from './models/all';
import { Configuration} from './configuration' export { Configuration} from './configuration'
import * as apis from './types/PromiseAPI'; export * from './types/PromiseAPI';
import * as exceptions from './apis/exception'; export * from './apis/exception';
export {
http,
auth,
Middleware,
PromiseMiddleware,
models,
Configuration,
apis,
exceptions
};

View File

@ -1,19 +1,7 @@
import * as http from './http/http'; export * from './http/http';
import * as auth from './auth/auth'; export * from './auth/auth';
import {Middleware, PromiseMiddleware} from './middleware'; export {Middleware, PromiseMiddleware} from './middleware';
import * as models from './models/all'; export * from './models/all';
import { Configuration} from './configuration' export { Configuration} from './configuration'
import * as apis from './types/PromiseAPI'; export * from './types/PromiseAPI';
import * as exceptions from './apis/exception'; export * from './apis/exception';
export {
http,
auth,
Middleware,
PromiseMiddleware,
models,
Configuration,
apis,
exceptions
};

View File

@ -1,19 +1,7 @@
import * as http from './http/http'; export * from './http/http';
import * as auth from './auth/auth'; export * from './auth/auth';
import {Middleware, PromiseMiddleware} from './middleware'; export {Middleware, PromiseMiddleware} from './middleware';
import * as models from './models/all'; export * from './models/all';
import { Configuration} from './configuration' export { Configuration} from './configuration'
import * as apis from './types/PromiseAPI'; export * from './types/PromiseAPI';
import * as exceptions from './apis/exception'; export * from './apis/exception';
export {
http,
auth,
Middleware,
PromiseMiddleware,
models,
Configuration,
apis,
exceptions
};

View File

@ -4,13 +4,13 @@ import { expect, assert } from "chai";
import * as fs from 'fs'; import * as fs from 'fs';
const configuration = new petstore.Configuration() const configuration = new petstore.Configuration()
const petApi = new petstore.apis.PromisePetApi(configuration) const petApi = new petstore.PromisePetApi(configuration)
const tag = new petstore.models.Tag(); const tag = new petstore.Tag();
tag.name = "tag1" tag.name = "tag1"
tag.id = Math.floor(Math.random() * 100000) tag.id = Math.floor(Math.random() * 100000)
const pet = new petstore.models.Pet() const pet = new petstore.Pet()
pet.id = Math.floor(Math.random() * 100000) pet.id = Math.floor(Math.random() * 100000)
pet.name = "PetName" pet.name = "PetName"
pet.photoUrls = [] pet.photoUrls = []
@ -22,7 +22,7 @@ describe("PetApi", () =>{
it("addPet", (done) => { it("addPet", (done) => {
petApi.addPet(pet).then(() => { petApi.addPet(pet).then(() => {
return petApi.getPetById(pet.id) return petApi.getPetById(pet.id)
}).then((createdPet: petstore.models.Pet) => { }).then((createdPet: petstore.Pet) => {
expect(createdPet).to.deep.equal(pet); expect(createdPet).to.deep.equal(pet);
done() done()
}).catch((err) => { }).catch((err) => {
@ -35,7 +35,7 @@ describe("PetApi", () =>{
return petApi.deletePet(pet.id) return petApi.deletePet(pet.id)
}).then(() => { }).then(() => {
return petApi.getPetById(pet.id) return petApi.getPetById(pet.id)
}).then((pet: petstore.models.Pet) => { }).then((pet: petstore.Pet) => {
done("Pet with id " + pet.id + " was not deleted!"); done("Pet with id " + pet.id + " was not deleted!");
}).catch((err: any) => { }).catch((err: any) => {
if (err.code && err.code == 404) { if (err.code && err.code == 404) {
@ -49,7 +49,7 @@ describe("PetApi", () =>{
it("findPetsByStatus", (done) => { it("findPetsByStatus", (done) => {
petApi.addPet(pet).then(() => { petApi.addPet(pet).then(() => {
return petApi.findPetsByStatus(["available"]) return petApi.findPetsByStatus(["available"])
}).then((pets: petstore.models.Pet[]) => { }).then((pets: petstore.Pet[]) => {
expect(pets.length).to.be.at.least(1); expect(pets.length).to.be.at.least(1);
done(); done();
}).catch((err) => { }).catch((err) => {
@ -72,7 +72,7 @@ describe("PetApi", () =>{
it("getPetById", (done) => { it("getPetById", (done) => {
petApi.addPet(pet).then(() => { petApi.addPet(pet).then(() => {
return petApi.getPetById(pet.id) return petApi.getPetById(pet.id)
}).then((returnedPet: petstore.models.Pet) => { }).then((returnedPet: petstore.Pet) => {
expect(returnedPet).to.deep.equal(pet); expect(returnedPet).to.deep.equal(pet);
done(); done();
}).catch((err) => { }).catch((err) => {
@ -93,7 +93,7 @@ describe("PetApi", () =>{
}); });
}).then(() => { }).then(() => {
return petApi.getPetById(pet.id); return petApi.getPetById(pet.id);
}).then((returnedPet: petstore.models.Pet) => { }).then((returnedPet: petstore.Pet) => {
expect(returnedPet.id).to.equal(pet.id) expect(returnedPet.id).to.equal(pet.id)
expect(returnedPet.name).to.equal(updatedName); expect(returnedPet.name).to.equal(updatedName);
done(); done();

View File

@ -6,8 +6,8 @@ import { expect} from "chai";
describe("Security Authentication", () => { describe("Security Authentication", () => {
describe("No Authentication", () => { describe("No Authentication", () => {
it("No Authentication", () => { it("No Authentication", () => {
let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); let ctx = new petstore.RequestContext("http://google.com", petstore.HttpMethod.GET);
let noAuth = new petstore.auth.NoAuthentication(); let noAuth = new petstore.NoAuthentication();
noAuth.applySecurityAuthentication(ctx); noAuth.applySecurityAuthentication(ctx);
expect(ctx.getUrl()).to.equal("http://google.com"); expect(ctx.getUrl()).to.equal("http://google.com");
@ -19,8 +19,8 @@ describe("Security Authentication", () => {
describe("API Key Authentication", () => { describe("API Key Authentication", () => {
// TODO: make all params const variables // TODO: make all params const variables
it("Header API Key", () => { it("Header API Key", () => {
let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); let ctx = new petstore.RequestContext("http://google.com", petstore.HttpMethod.GET);
let auth = new petstore.auth.APIKeyAuthentication("my_name", "paramName", "header", "apiKey"); let auth = new petstore.APIKeyAuthentication("my_name", "paramName", "header", "apiKey");
auth.applySecurityAuthentication(ctx); auth.applySecurityAuthentication(ctx);
expect(ctx.getUrl()).to.equal("http://google.com"); expect(ctx.getUrl()).to.equal("http://google.com");
@ -30,8 +30,8 @@ describe("Security Authentication", () => {
}); });
it("Query API Key", () => { it("Query API Key", () => {
let ctx = new petstore.http.RequestContext("http://google.com?a=b", petstore.http.HttpMethod.GET); let ctx = new petstore.RequestContext("http://google.com?a=b", petstore.HttpMethod.GET);
let auth = new petstore.auth.APIKeyAuthentication("my_name", "paramName", "query", "apiKey",); let auth = new petstore.APIKeyAuthentication("my_name", "paramName", "query", "apiKey",);
auth.applySecurityAuthentication(ctx); auth.applySecurityAuthentication(ctx);
expect(ctx.getUrl()).to.contain("paramName=apiKey"); expect(ctx.getUrl()).to.contain("paramName=apiKey");
@ -40,8 +40,8 @@ describe("Security Authentication", () => {
}); });
it("Cookie API Key", () => { it("Cookie API Key", () => {
let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); let ctx = new petstore.RequestContext("http://google.com", petstore.HttpMethod.GET);
let auth = new petstore.auth.APIKeyAuthentication("my_name", "paramName", "cookie", "apiKey",); let auth = new petstore.APIKeyAuthentication("my_name", "paramName", "cookie", "apiKey",);
auth.applySecurityAuthentication(ctx); auth.applySecurityAuthentication(ctx);
expect(ctx.getUrl()).to.equal("http://google.com"); expect(ctx.getUrl()).to.equal("http://google.com");

View File

@ -3,8 +3,8 @@ import * as petstore from "ts-petstore-client";
import { expect} from "chai"; import { expect} from "chai";
import * as FormData from "form-data"; import * as FormData from "form-data";
let libs: { [key: string]: petstore.http.HttpLibrary } = { let libs: { [key: string]: petstore.HttpLibrary } = {
"isomorphic-fetch": new petstore.http.IsomorphicFetchHttpLibrary() "isomorphic-fetch": new petstore.IsomorphicFetchHttpLibrary()
} }
@ -13,10 +13,10 @@ for (let libName in libs) {
describe("Isomorphic Fetch", () => { describe("Isomorphic Fetch", () => {
it("GET-Request", (done) => { it("GET-Request", (done) => {
let requestContext = new petstore.http.RequestContext("http://httpbin.org/get", petstore.http.HttpMethod.GET); let requestContext = new petstore.RequestContext("http://httpbin.org/get", petstore.HttpMethod.GET);
requestContext.setHeaderParam("X-Test-Token", "Test-Token"); requestContext.setHeaderParam("X-Test-Token", "Test-Token");
requestContext.addCookie("test-cookie", "cookie-value"); requestContext.addCookie("test-cookie", "cookie-value");
lib.send(requestContext).toPromise().then((resp: petstore.http.ResponseContext) => { lib.send(requestContext).toPromise().then((resp: petstore.ResponseContext) => {
expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
let body = JSON.parse(resp.body); let body = JSON.parse(resp.body);
expect(body["headers"]).to.exist; expect(body["headers"]).to.exist;
@ -31,7 +31,7 @@ for (let libName in libs) {
}) })
it("POST-Request", (done) => { it("POST-Request", (done) => {
let requestContext = new petstore.http.RequestContext("http://httpbin.org/post", petstore.http.HttpMethod.POST); let requestContext = new petstore.RequestContext("http://httpbin.org/post", petstore.HttpMethod.POST);
requestContext.setHeaderParam("X-Test-Token", "Test-Token"); requestContext.setHeaderParam("X-Test-Token", "Test-Token");
requestContext.addCookie("test-cookie", "cookie-value"); requestContext.addCookie("test-cookie", "cookie-value");
let formData: FormData = new FormData() let formData: FormData = new FormData()
@ -40,7 +40,7 @@ for (let libName in libs) {
requestContext.setBody(formData); requestContext.setBody(formData);
lib.send(requestContext).toPromise().then( lib.send(requestContext).toPromise().then(
(resp: petstore.http.ResponseContext) => { (resp: petstore.ResponseContext) => {
expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
let body = JSON.parse(resp.body); let body = JSON.parse(resp.body);
expect(body["headers"]).to.exist; expect(body["headers"]).to.exist;
@ -56,11 +56,11 @@ for (let libName in libs) {
}); });
it("Cookies-Request", (done) => { it("Cookies-Request", (done) => {
let requestContext = new petstore.http.RequestContext("http://httpbin.org/cookies", petstore.http.HttpMethod.GET); let requestContext = new petstore.RequestContext("http://httpbin.org/cookies", petstore.HttpMethod.GET);
requestContext.addCookie("test-cookie", "cookie-value"); requestContext.addCookie("test-cookie", "cookie-value");
lib.send(requestContext).toPromise().then( lib.send(requestContext).toPromise().then(
(resp: petstore.http.ResponseContext) => { (resp: petstore.ResponseContext) => {
expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
let body = JSON.parse(resp.body); let body = JSON.parse(resp.body);
expect(body["cookies"]["test-cookie"]).to.equal("cookie-value"); expect(body["cookies"]["test-cookie"]).to.equal("cookie-value");

View File

@ -47,7 +47,7 @@ describe("ObjectSerializer", () => {
}) })
it("Class", () => { it("Class", () => {
const input = new petstore.models.Category() const input = new petstore.Category()
input.id = 4 input.id = 4
input.name = "Test" input.name = "Test"
expect(ObjectSerializer.serialize(input, "Category", "")).to.deep.equal({ "id": input.id, "name": input.name}) expect(ObjectSerializer.serialize(input, "Category", "")).to.deep.equal({ "id": input.id, "name": input.name})
@ -62,7 +62,7 @@ describe("ObjectSerializer", () => {
const tags = [] const tags = []
const tagResult = [] const tagResult = []
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
const tag = new petstore.models.Tag() const tag = new petstore.Tag()
tag.id = i tag.id = i
tag.name = "Tag" + i tag.name = "Tag" + i
tags.push(tag) tags.push(tag)
@ -72,10 +72,10 @@ describe("ObjectSerializer", () => {
}) })
} }
const category = new petstore.models.Category() const category = new petstore.Category()
category.id = 4 category.id = 4
category.name = "TestCat" category.name = "TestCat"
const pet = new petstore.models.Pet() const pet = new petstore.Pet()
pet.id = 145 pet.id = 145
pet.category = category pet.category = category
pet.name = "PetName" pet.name = "PetName"
@ -99,7 +99,7 @@ describe("ObjectSerializer", () => {
const categories = [] const categories = []
const result = [] const result = []
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
const category = new petstore.models.Category() const category = new petstore.Category()
category.id = i category.id = i
category.name = "Cat" + i category.name = "Cat" + i
categories.push(category) categories.push(category)
@ -151,7 +151,7 @@ describe("ObjectSerializer", () => {
}) })
it("Class", () => { it("Class", () => {
const input = new petstore.models.Category() const input = new petstore.Category()
input.id = 4 input.id = 4
input.name = "Test" input.name = "Test"
const deserialized = ObjectSerializer.deserialize({ "id": 4, "name": "Test"}, "Category") const deserialized = ObjectSerializer.deserialize({ "id": 4, "name": "Test"}, "Category")
@ -169,7 +169,7 @@ describe("ObjectSerializer", () => {
const tags = [] const tags = []
const tagResult = [] const tagResult = []
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
const tag = new petstore.models.Tag() const tag = new petstore.Tag()
tag.id = i tag.id = i
tag.name = "Tag" + i tag.name = "Tag" + i
tags.push(tag) tags.push(tag)
@ -179,10 +179,10 @@ describe("ObjectSerializer", () => {
}) })
} }
const category = new petstore.models.Category() const category = new petstore.Category()
category.id = 4 category.id = 4
category.name = "TestCat" category.name = "TestCat"
const pet = new petstore.models.Pet() const pet = new petstore.Pet()
pet.id = 145 pet.id = 145
pet.category = category pet.category = category
pet.name = "PetName" pet.name = "PetName"
@ -200,7 +200,7 @@ describe("ObjectSerializer", () => {
"photoUrls": [ "url", "other url"], "photoUrls": [ "url", "other url"],
"status": "available", "status": "available",
"tags": tagResult "tags": tagResult
}, "Pet", "") as petstore.models.Pet }, "Pet", "") as petstore.Pet
expect(deserialized.constructor.name).to.equal("Pet") expect(deserialized.constructor.name).to.equal("Pet")
expect(deserialized.category.constructor.name).to.equal("Category") expect(deserialized.category.constructor.name).to.equal("Category")
@ -214,7 +214,7 @@ describe("ObjectSerializer", () => {
const categories = [] const categories = []
const result = [] const result = []
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
const category = new petstore.models.Category() const category = new petstore.Category()
category.id = i category.id = i
category.name = "Cat" + i category.name = "Cat" + i
categories.push(category) categories.push(category)

View File

@ -3,13 +3,13 @@ declare var QUnit: any;
import * as petstore from 'ts-petstore-client' import * as petstore from 'ts-petstore-client'
const configuration = new petstore.Configuration() const configuration = new petstore.Configuration()
const petApi = new petstore.apis.PromisePetApi(configuration) const petApi = new petstore.PromisePetApi(configuration)
const tag = new petstore.models.Tag(); const tag = new petstore.Tag();
tag.name = "tag1" tag.name = "tag1"
tag.id = Math.floor(Math.random() * 100000) tag.id = Math.floor(Math.random() * 100000)
const pet = new petstore.models.Pet() const pet = new petstore.Pet()
pet.id = Math.floor(Math.random() * 100000) pet.id = Math.floor(Math.random() * 100000)
pet.name = "PetName" pet.name = "PetName"
pet.photoUrls = [] pet.photoUrls = []
@ -22,7 +22,7 @@ QUnit.module("PetApi")
QUnit.test("addPet", (assert: any) => { QUnit.test("addPet", (assert: any) => {
return petApi.addPet(pet).then(() => { return petApi.addPet(pet).then(() => {
return petApi.getPetById(pet.id) return petApi.getPetById(pet.id)
}).then((createdPet: petstore.models.Pet) => { }).then((createdPet: petstore.Pet) => {
assert.deepEqual(createdPet, pet); assert.deepEqual(createdPet, pet);
}) })
}) })
@ -32,7 +32,7 @@ QUnit.test("deletePet", (assert: any) => {
return petApi.deletePet(pet.id) return petApi.deletePet(pet.id)
}).then(() => { }).then(() => {
return petApi.getPetById(pet.id) return petApi.getPetById(pet.id)
}).then((pet: petstore.models.Pet) => { }).then((pet: petstore.Pet) => {
throw new Error("Pet with id " + pet.id + " was not deleted!"); throw new Error("Pet with id " + pet.id + " was not deleted!");
}).catch((err: any) => { }).catch((err: any) => {
// pet does not exist // pet does not exist
@ -48,7 +48,7 @@ QUnit.test("deletePet", (assert: any) => {
QUnit.test("findPetsByStatus", (assert: any) => { QUnit.test("findPetsByStatus", (assert: any) => {
return petApi.addPet(pet).then(() => { return petApi.addPet(pet).then(() => {
return petApi.findPetsByStatus(["available"]) return petApi.findPetsByStatus(["available"])
}).then((pets: petstore.models.Pet[]) => { }).then((pets: petstore.Pet[]) => {
assert.ok(pets.length >= 1, "Found at least one pet."); assert.ok(pets.length >= 1, "Found at least one pet.");
}) })
}) })
@ -68,7 +68,7 @@ QUnit.test("findPetsByStatus", (assert: any) => {
QUnit.test("getPetById", (assert: any) => { QUnit.test("getPetById", (assert: any) => {
return petApi.addPet(pet).then(() => { return petApi.addPet(pet).then(() => {
return petApi.getPetById(pet.id) return petApi.getPetById(pet.id)
}).then((returnedPet: petstore.models.Pet) => { }).then((returnedPet: petstore.Pet) => {
assert.deepEqual(returnedPet, pet); assert.deepEqual(returnedPet, pet);
}) })
}) })
@ -80,13 +80,13 @@ QUnit.test("updatePet", (assert: any) => {
pet.name = updatedName pet.name = updatedName
return petApi.updatePet(pet).then(() => { return petApi.updatePet(pet).then(() => {
pet.name = oldName; pet.name = oldName;
}).catch((err) => { }).catch((err: any) => {
pet.name = oldName pet.name = oldName
throw err; throw err;
}); });
}).then(() => { }).then(() => {
return petApi.getPetById(pet.id); return petApi.getPetById(pet.id);
}).then((returnedPet: petstore.models.Pet) => { }).then((returnedPet: petstore.Pet) => {
assert.equal(returnedPet.id, pet.id) assert.equal(returnedPet.id, pet.id)
assert.equal(returnedPet.name, updatedName); assert.equal(returnedPet.name, updatedName);
}) })

View File

@ -2,8 +2,8 @@ declare var QUnit: any;
import * as petstore from "ts-petstore-client"; import * as petstore from "ts-petstore-client";
let libs: { [key: string]: petstore.http.HttpLibrary } = { let libs: { [key: string]: petstore.HttpLibrary } = {
"jquery": new petstore.http.JQueryHttpLibrary() "jquery": new petstore.JQueryHttpLibrary()
} }
@ -12,10 +12,10 @@ for (let libName in libs) {
QUnit.module(libName); QUnit.module(libName);
QUnit.test("GET-Request", (assert: any) => { QUnit.test("GET-Request", (assert: any) => {
let requestContext = new petstore.http.RequestContext("http://httpbin.org/get", petstore.http.HttpMethod.GET); let requestContext = new petstore.RequestContext("http://httpbin.org/get", petstore.HttpMethod.GET);
requestContext.setHeaderParam("X-Test-Token", "Test-Token"); requestContext.setHeaderParam("X-Test-Token", "Test-Token");
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lib.send(requestContext).toPromise().then((resp: petstore.http.ResponseContext) => { lib.send(requestContext).toPromise().then((resp: petstore.ResponseContext) => {
assert.ok(resp.httpStatusCode, 200, "Expected status code to be 200"); assert.ok(resp.httpStatusCode, 200, "Expected status code to be 200");
let body = JSON.parse(resp.body); let body = JSON.parse(resp.body);
assert.ok(body["headers"]); assert.ok(body["headers"]);
@ -31,7 +31,7 @@ for (let libName in libs) {
}) })
QUnit.test("POST-Request", (assert: any) => { QUnit.test("POST-Request", (assert: any) => {
let requestContext = new petstore.http.RequestContext("http://httpbin.org/post", petstore.http.HttpMethod.POST); let requestContext = new petstore.RequestContext("http://httpbin.org/post", petstore.HttpMethod.POST);
requestContext.setHeaderParam("X-Test-Token", "Test-Token"); requestContext.setHeaderParam("X-Test-Token", "Test-Token");
let formData: FormData = new FormData() let formData: FormData = new FormData()
formData.append("test", "test2"); formData.append("test", "test2");
@ -42,7 +42,7 @@ for (let libName in libs) {
requestContext.setBody(formData); requestContext.setBody(formData);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lib.send(requestContext).toPromise().then( lib.send(requestContext).toPromise().then(
(resp: petstore.http.ResponseContext) => { (resp: petstore.ResponseContext) => {
assert.ok(resp.httpStatusCode, 200, "Expected status code to be 200"); assert.ok(resp.httpStatusCode, 200, "Expected status code to be 200");
let body = JSON.parse(resp.body); let body = JSON.parse(resp.body);
assert.ok(body["headers"]); assert.ok(body["headers"]);
@ -60,12 +60,12 @@ for (let libName in libs) {
}); });
QUnit.test("Cookie-Test", (assert: any) => { QUnit.test("Cookie-Test", (assert: any) => {
let requestContext = new petstore.http.RequestContext("http://httpbin.org/post", petstore.http.HttpMethod.POST); let requestContext = new petstore.RequestContext("http://httpbin.org/post", petstore.HttpMethod.POST);
requestContext.addCookie("test", "test2"); requestContext.addCookie("test", "test2");
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
lib.send(requestContext).toPromise().then( lib.send(requestContext).toPromise().then(
(resp: petstore.http.ResponseContext) => { (resp: petstore.ResponseContext) => {
assert.ok(false, "Expected this request to fail!") assert.ok(false, "Expected this request to fail!")
reject("Successful request with Cookie Header!") reject("Successful request with Cookie Header!")
}, },