From 934f226098352a4ac69d337d3157b74cd7ecb2d0 Mon Sep 17 00:00:00 2001 From: Tino Fuhrmann Date: Mon, 4 May 2020 23:58:38 +0200 Subject: [PATCH] [TS-Refactor] Top-level exports for fetch & jquery (#6138) * Added top-level exports * Updated generator README * Updated typescript generator docs --- docs/generators.md | 2 +- docs/generators/typescript.md | 240 +++++++++++++++++- .../typescript/generators/fetch-api.mustache | 26 +- .../typescript/generators/jquery.mustache | 26 +- .../typescript/builds/default/index.ts | 26 +- .../typescript/builds/jquery/index.ts | 26 +- .../tests/default/test/api/PetApi.test.ts | 16 +- .../tests/default/test/auth/auth.test.ts | 16 +- .../test/http/isomorphic-fetch.test.ts | 16 +- .../test/models/ObjectSerializer.test.ts | 22 +- .../tests/jquery/test/api/PetApi.test.ts | 18 +- .../tests/jquery/test/http/jquery.test.ts | 16 +- 12 files changed, 314 insertions(+), 136 deletions(-) diff --git a/docs/generators.md b/docs/generators.md index 04de34b9155..9c184321349 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -62,7 +62,7 @@ The following generators are available: * [swift3-deprecated (deprecated)](generators/swift3-deprecated.md) * [swift4](generators/swift4.md) * [swift5 (beta)](generators/swift5.md) -* [typescript](generators/typescript.md) +* [typescript (experimental)](generators/typescript.md) * [typescript-angular](generators/typescript-angular.md) * [typescript-angularjs](generators/typescript-angularjs.md) * [typescript-aurelia](generators/typescript-aurelia.md) diff --git a/docs/generators/typescript.md b/docs/generators/typescript.md index c1599ef5021..68028c6230a 100644 --- a/docs/generators/typescript.md +++ b/docs/generators/typescript.md @@ -5,13 +5,239 @@ sidebar_label: typescript | 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| -|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| -|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| +|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |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.|
**fetch-api**
fetch-api
**jquery**
jquery
|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| -|framework|Specify the framework which should be used in the client code.|
**fetch-api**
fetch-api
**jquery**
jquery
|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 + +
    +
  • Array
  • +
  • Boolean
  • +
  • Date
  • +
  • Double
  • +
  • Error
  • +
  • File
  • +
  • Float
  • +
  • Integer
  • +
  • Long
  • +
  • Map
  • +
  • Object
  • +
  • String
  • +
  • any
  • +
  • boolean
  • +
  • number
  • +
  • string
  • +
+ +## RESERVED WORDS + +
    +
  • abstract
  • +
  • await
  • +
  • boolean
  • +
  • break
  • +
  • byte
  • +
  • case
  • +
  • catch
  • +
  • char
  • +
  • class
  • +
  • const
  • +
  • continue
  • +
  • debugger
  • +
  • default
  • +
  • delete
  • +
  • do
  • +
  • double
  • +
  • else
  • +
  • enum
  • +
  • export
  • +
  • extends
  • +
  • false
  • +
  • final
  • +
  • finally
  • +
  • float
  • +
  • for
  • +
  • formParams
  • +
  • function
  • +
  • goto
  • +
  • headerParams
  • +
  • if
  • +
  • implements
  • +
  • import
  • +
  • in
  • +
  • instanceof
  • +
  • int
  • +
  • interface
  • +
  • let
  • +
  • long
  • +
  • native
  • +
  • new
  • +
  • null
  • +
  • package
  • +
  • private
  • +
  • protected
  • +
  • public
  • +
  • queryParameters
  • +
  • requestOptions
  • +
  • return
  • +
  • short
  • +
  • static
  • +
  • super
  • +
  • switch
  • +
  • synchronized
  • +
  • this
  • +
  • throw
  • +
  • transient
  • +
  • true
  • +
  • try
  • +
  • typeof
  • +
  • useFormData
  • +
  • var
  • +
  • varLocalDeferred
  • +
  • varLocalPath
  • +
  • void
  • +
  • volatile
  • +
  • while
  • +
  • with
  • +
  • yield
  • +
+ +## 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 diff --git a/modules/openapi-generator/src/main/resources/typescript/generators/fetch-api.mustache b/modules/openapi-generator/src/main/resources/typescript/generators/fetch-api.mustache index ca1c5ff976f..44c085d2dd0 100644 --- a/modules/openapi-generator/src/main/resources/typescript/generators/fetch-api.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/generators/fetch-api.mustache @@ -1,19 +1,7 @@ -import * as http from './http/http'; -import * as auth from './auth/auth'; -import {Middleware, PromiseMiddleware} from './middleware'; -import * as models from './models/all'; -import { Configuration} from './configuration' -import * as apis from './types/PromiseAPI'; -import * as exceptions from './apis/exception'; - -export { - http, - - auth, - Middleware, - PromiseMiddleware, - models, - Configuration, - apis, - exceptions -}; \ No newline at end of file +export * from './http/http'; +export * from './auth/auth'; +export {Middleware, PromiseMiddleware} from './middleware'; +export * from './models/all'; +export { Configuration} from './configuration' +export * from './types/PromiseAPI'; +export * from './apis/exception'; \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript/generators/jquery.mustache b/modules/openapi-generator/src/main/resources/typescript/generators/jquery.mustache index ca1c5ff976f..44c085d2dd0 100644 --- a/modules/openapi-generator/src/main/resources/typescript/generators/jquery.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/generators/jquery.mustache @@ -1,19 +1,7 @@ -import * as http from './http/http'; -import * as auth from './auth/auth'; -import {Middleware, PromiseMiddleware} from './middleware'; -import * as models from './models/all'; -import { Configuration} from './configuration' -import * as apis from './types/PromiseAPI'; -import * as exceptions from './apis/exception'; - -export { - http, - - auth, - Middleware, - PromiseMiddleware, - models, - Configuration, - apis, - exceptions -}; \ No newline at end of file +export * from './http/http'; +export * from './auth/auth'; +export {Middleware, PromiseMiddleware} from './middleware'; +export * from './models/all'; +export { Configuration} from './configuration' +export * from './types/PromiseAPI'; +export * from './apis/exception'; \ No newline at end of file diff --git a/samples/client/petstore/typescript/builds/default/index.ts b/samples/client/petstore/typescript/builds/default/index.ts index ca1c5ff976f..44c085d2dd0 100644 --- a/samples/client/petstore/typescript/builds/default/index.ts +++ b/samples/client/petstore/typescript/builds/default/index.ts @@ -1,19 +1,7 @@ -import * as http from './http/http'; -import * as auth from './auth/auth'; -import {Middleware, PromiseMiddleware} from './middleware'; -import * as models from './models/all'; -import { Configuration} from './configuration' -import * as apis from './types/PromiseAPI'; -import * as exceptions from './apis/exception'; - -export { - http, - - auth, - Middleware, - PromiseMiddleware, - models, - Configuration, - apis, - exceptions -}; \ No newline at end of file +export * from './http/http'; +export * from './auth/auth'; +export {Middleware, PromiseMiddleware} from './middleware'; +export * from './models/all'; +export { Configuration} from './configuration' +export * from './types/PromiseAPI'; +export * from './apis/exception'; \ No newline at end of file diff --git a/samples/client/petstore/typescript/builds/jquery/index.ts b/samples/client/petstore/typescript/builds/jquery/index.ts index ca1c5ff976f..44c085d2dd0 100644 --- a/samples/client/petstore/typescript/builds/jquery/index.ts +++ b/samples/client/petstore/typescript/builds/jquery/index.ts @@ -1,19 +1,7 @@ -import * as http from './http/http'; -import * as auth from './auth/auth'; -import {Middleware, PromiseMiddleware} from './middleware'; -import * as models from './models/all'; -import { Configuration} from './configuration' -import * as apis from './types/PromiseAPI'; -import * as exceptions from './apis/exception'; - -export { - http, - - auth, - Middleware, - PromiseMiddleware, - models, - Configuration, - apis, - exceptions -}; \ No newline at end of file +export * from './http/http'; +export * from './auth/auth'; +export {Middleware, PromiseMiddleware} from './middleware'; +export * from './models/all'; +export { Configuration} from './configuration' +export * from './types/PromiseAPI'; +export * from './apis/exception'; \ No newline at end of file diff --git a/samples/client/petstore/typescript/tests/default/test/api/PetApi.test.ts b/samples/client/petstore/typescript/tests/default/test/api/PetApi.test.ts index 813e5321eaa..fe9df6c6770 100644 --- a/samples/client/petstore/typescript/tests/default/test/api/PetApi.test.ts +++ b/samples/client/petstore/typescript/tests/default/test/api/PetApi.test.ts @@ -4,13 +4,13 @@ import { expect, assert } from "chai"; import * as fs from 'fs'; 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.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.name = "PetName" pet.photoUrls = [] @@ -22,7 +22,7 @@ describe("PetApi", () =>{ it("addPet", (done) => { petApi.addPet(pet).then(() => { return petApi.getPetById(pet.id) - }).then((createdPet: petstore.models.Pet) => { + }).then((createdPet: petstore.Pet) => { expect(createdPet).to.deep.equal(pet); done() }).catch((err) => { @@ -35,7 +35,7 @@ describe("PetApi", () =>{ return petApi.deletePet(pet.id) }).then(() => { return petApi.getPetById(pet.id) - }).then((pet: petstore.models.Pet) => { + }).then((pet: petstore.Pet) => { done("Pet with id " + pet.id + " was not deleted!"); }).catch((err: any) => { if (err.code && err.code == 404) { @@ -49,7 +49,7 @@ describe("PetApi", () =>{ it("findPetsByStatus", (done) => { petApi.addPet(pet).then(() => { return petApi.findPetsByStatus(["available"]) - }).then((pets: petstore.models.Pet[]) => { + }).then((pets: petstore.Pet[]) => { expect(pets.length).to.be.at.least(1); done(); }).catch((err) => { @@ -72,7 +72,7 @@ describe("PetApi", () =>{ it("getPetById", (done) => { petApi.addPet(pet).then(() => { return petApi.getPetById(pet.id) - }).then((returnedPet: petstore.models.Pet) => { + }).then((returnedPet: petstore.Pet) => { expect(returnedPet).to.deep.equal(pet); done(); }).catch((err) => { @@ -93,7 +93,7 @@ describe("PetApi", () =>{ }); }).then(() => { return petApi.getPetById(pet.id); - }).then((returnedPet: petstore.models.Pet) => { + }).then((returnedPet: petstore.Pet) => { expect(returnedPet.id).to.equal(pet.id) expect(returnedPet.name).to.equal(updatedName); done(); diff --git a/samples/client/petstore/typescript/tests/default/test/auth/auth.test.ts b/samples/client/petstore/typescript/tests/default/test/auth/auth.test.ts index 5993b740439..0a7dafc9696 100644 --- a/samples/client/petstore/typescript/tests/default/test/auth/auth.test.ts +++ b/samples/client/petstore/typescript/tests/default/test/auth/auth.test.ts @@ -6,8 +6,8 @@ import { expect} from "chai"; describe("Security Authentication", () => { describe("No Authentication", () => { it("No Authentication", () => { - let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); - let noAuth = new petstore.auth.NoAuthentication(); + let ctx = new petstore.RequestContext("http://google.com", petstore.HttpMethod.GET); + let noAuth = new petstore.NoAuthentication(); noAuth.applySecurityAuthentication(ctx); expect(ctx.getUrl()).to.equal("http://google.com"); @@ -19,8 +19,8 @@ describe("Security Authentication", () => { describe("API Key Authentication", () => { // TODO: make all params const variables it("Header API Key", () => { - let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); - let auth = new petstore.auth.APIKeyAuthentication("my_name", "paramName", "header", "apiKey"); + let ctx = new petstore.RequestContext("http://google.com", petstore.HttpMethod.GET); + let auth = new petstore.APIKeyAuthentication("my_name", "paramName", "header", "apiKey"); auth.applySecurityAuthentication(ctx); expect(ctx.getUrl()).to.equal("http://google.com"); @@ -30,8 +30,8 @@ describe("Security Authentication", () => { }); it("Query API Key", () => { - let ctx = new petstore.http.RequestContext("http://google.com?a=b", petstore.http.HttpMethod.GET); - let auth = new petstore.auth.APIKeyAuthentication("my_name", "paramName", "query", "apiKey",); + let ctx = new petstore.RequestContext("http://google.com?a=b", petstore.HttpMethod.GET); + let auth = new petstore.APIKeyAuthentication("my_name", "paramName", "query", "apiKey",); auth.applySecurityAuthentication(ctx); expect(ctx.getUrl()).to.contain("paramName=apiKey"); @@ -40,8 +40,8 @@ describe("Security Authentication", () => { }); it("Cookie API Key", () => { - let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); - let auth = new petstore.auth.APIKeyAuthentication("my_name", "paramName", "cookie", "apiKey",); + let ctx = new petstore.RequestContext("http://google.com", petstore.HttpMethod.GET); + let auth = new petstore.APIKeyAuthentication("my_name", "paramName", "cookie", "apiKey",); auth.applySecurityAuthentication(ctx); expect(ctx.getUrl()).to.equal("http://google.com"); diff --git a/samples/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts b/samples/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts index 1cbc0f11b67..974ebd2d134 100644 --- a/samples/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts +++ b/samples/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts @@ -3,8 +3,8 @@ import * as petstore from "ts-petstore-client"; import { expect} from "chai"; import * as FormData from "form-data"; -let libs: { [key: string]: petstore.http.HttpLibrary } = { - "isomorphic-fetch": new petstore.http.IsomorphicFetchHttpLibrary() +let libs: { [key: string]: petstore.HttpLibrary } = { + "isomorphic-fetch": new petstore.IsomorphicFetchHttpLibrary() } @@ -13,10 +13,10 @@ for (let libName in libs) { describe("Isomorphic Fetch", () => { 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.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); let body = JSON.parse(resp.body); expect(body["headers"]).to.exist; @@ -31,7 +31,7 @@ for (let libName in libs) { }) 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.addCookie("test-cookie", "cookie-value"); let formData: FormData = new FormData() @@ -40,7 +40,7 @@ for (let libName in libs) { requestContext.setBody(formData); lib.send(requestContext).toPromise().then( - (resp: petstore.http.ResponseContext) => { + (resp: petstore.ResponseContext) => { expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); let body = JSON.parse(resp.body); expect(body["headers"]).to.exist; @@ -56,11 +56,11 @@ for (let libName in libs) { }); 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"); lib.send(requestContext).toPromise().then( - (resp: petstore.http.ResponseContext) => { + (resp: petstore.ResponseContext) => { expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); let body = JSON.parse(resp.body); expect(body["cookies"]["test-cookie"]).to.equal("cookie-value"); diff --git a/samples/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts b/samples/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts index e111dfe49e6..babc4681fb4 100644 --- a/samples/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts +++ b/samples/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts @@ -47,7 +47,7 @@ describe("ObjectSerializer", () => { }) it("Class", () => { - const input = new petstore.models.Category() + const input = new petstore.Category() input.id = 4 input.name = "Test" expect(ObjectSerializer.serialize(input, "Category", "")).to.deep.equal({ "id": input.id, "name": input.name}) @@ -62,7 +62,7 @@ describe("ObjectSerializer", () => { const tags = [] const tagResult = [] for (let i = 0; i < 2; i++) { - const tag = new petstore.models.Tag() + const tag = new petstore.Tag() tag.id = i tag.name = "Tag" + i tags.push(tag) @@ -72,10 +72,10 @@ describe("ObjectSerializer", () => { }) } - const category = new petstore.models.Category() + const category = new petstore.Category() category.id = 4 category.name = "TestCat" - const pet = new petstore.models.Pet() + const pet = new petstore.Pet() pet.id = 145 pet.category = category pet.name = "PetName" @@ -99,7 +99,7 @@ describe("ObjectSerializer", () => { const categories = [] const result = [] for (let i = 0; i < 2; i++) { - const category = new petstore.models.Category() + const category = new petstore.Category() category.id = i category.name = "Cat" + i categories.push(category) @@ -151,7 +151,7 @@ describe("ObjectSerializer", () => { }) it("Class", () => { - const input = new petstore.models.Category() + const input = new petstore.Category() input.id = 4 input.name = "Test" const deserialized = ObjectSerializer.deserialize({ "id": 4, "name": "Test"}, "Category") @@ -169,7 +169,7 @@ describe("ObjectSerializer", () => { const tags = [] const tagResult = [] for (let i = 0; i < 2; i++) { - const tag = new petstore.models.Tag() + const tag = new petstore.Tag() tag.id = i tag.name = "Tag" + i tags.push(tag) @@ -179,10 +179,10 @@ describe("ObjectSerializer", () => { }) } - const category = new petstore.models.Category() + const category = new petstore.Category() category.id = 4 category.name = "TestCat" - const pet = new petstore.models.Pet() + const pet = new petstore.Pet() pet.id = 145 pet.category = category pet.name = "PetName" @@ -200,7 +200,7 @@ describe("ObjectSerializer", () => { "photoUrls": [ "url", "other url"], "status": "available", "tags": tagResult - }, "Pet", "") as petstore.models.Pet + }, "Pet", "") as petstore.Pet expect(deserialized.constructor.name).to.equal("Pet") expect(deserialized.category.constructor.name).to.equal("Category") @@ -214,7 +214,7 @@ describe("ObjectSerializer", () => { const categories = [] const result = [] for (let i = 0; i < 2; i++) { - const category = new petstore.models.Category() + const category = new petstore.Category() category.id = i category.name = "Cat" + i categories.push(category) diff --git a/samples/client/petstore/typescript/tests/jquery/test/api/PetApi.test.ts b/samples/client/petstore/typescript/tests/jquery/test/api/PetApi.test.ts index 89cf2b8275d..17b0b6f4d88 100644 --- a/samples/client/petstore/typescript/tests/jquery/test/api/PetApi.test.ts +++ b/samples/client/petstore/typescript/tests/jquery/test/api/PetApi.test.ts @@ -3,13 +3,13 @@ declare var QUnit: any; import * as petstore from 'ts-petstore-client' 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.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.name = "PetName" pet.photoUrls = [] @@ -22,7 +22,7 @@ QUnit.module("PetApi") QUnit.test("addPet", (assert: any) => { return petApi.addPet(pet).then(() => { return petApi.getPetById(pet.id) - }).then((createdPet: petstore.models.Pet) => { + }).then((createdPet: petstore.Pet) => { assert.deepEqual(createdPet, pet); }) }) @@ -32,7 +32,7 @@ QUnit.test("deletePet", (assert: any) => { return petApi.deletePet(pet.id) }).then(() => { 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!"); }).catch((err: any) => { // pet does not exist @@ -48,7 +48,7 @@ QUnit.test("deletePet", (assert: any) => { QUnit.test("findPetsByStatus", (assert: any) => { return petApi.addPet(pet).then(() => { return petApi.findPetsByStatus(["available"]) - }).then((pets: petstore.models.Pet[]) => { + }).then((pets: petstore.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) => { return petApi.addPet(pet).then(() => { return petApi.getPetById(pet.id) - }).then((returnedPet: petstore.models.Pet) => { + }).then((returnedPet: petstore.Pet) => { assert.deepEqual(returnedPet, pet); }) }) @@ -80,13 +80,13 @@ QUnit.test("updatePet", (assert: any) => { pet.name = updatedName return petApi.updatePet(pet).then(() => { pet.name = oldName; - }).catch((err) => { + }).catch((err: any) => { pet.name = oldName throw err; }); }).then(() => { return petApi.getPetById(pet.id); - }).then((returnedPet: petstore.models.Pet) => { + }).then((returnedPet: petstore.Pet) => { assert.equal(returnedPet.id, pet.id) assert.equal(returnedPet.name, updatedName); }) diff --git a/samples/client/petstore/typescript/tests/jquery/test/http/jquery.test.ts b/samples/client/petstore/typescript/tests/jquery/test/http/jquery.test.ts index 1290d544cf0..c8715e14a27 100644 --- a/samples/client/petstore/typescript/tests/jquery/test/http/jquery.test.ts +++ b/samples/client/petstore/typescript/tests/jquery/test/http/jquery.test.ts @@ -2,8 +2,8 @@ declare var QUnit: any; import * as petstore from "ts-petstore-client"; -let libs: { [key: string]: petstore.http.HttpLibrary } = { - "jquery": new petstore.http.JQueryHttpLibrary() +let libs: { [key: string]: petstore.HttpLibrary } = { + "jquery": new petstore.JQueryHttpLibrary() } @@ -12,10 +12,10 @@ for (let libName in libs) { QUnit.module(libName); 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"); 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"); let body = JSON.parse(resp.body); assert.ok(body["headers"]); @@ -31,7 +31,7 @@ for (let libName in libs) { }) 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"); let formData: FormData = new FormData() formData.append("test", "test2"); @@ -42,7 +42,7 @@ for (let libName in libs) { requestContext.setBody(formData); return new Promise((resolve, reject) => { lib.send(requestContext).toPromise().then( - (resp: petstore.http.ResponseContext) => { + (resp: petstore.ResponseContext) => { assert.ok(resp.httpStatusCode, 200, "Expected status code to be 200"); let body = JSON.parse(resp.body); assert.ok(body["headers"]); @@ -60,12 +60,12 @@ for (let libName in libs) { }); 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"); return new Promise((resolve, reject) => { try { lib.send(requestContext).toPromise().then( - (resp: petstore.http.ResponseContext) => { + (resp: petstore.ResponseContext) => { assert.ok(false, "Expected this request to fail!") reject("Successful request with Cookie Header!") },