diff --git a/modules/openapi-generator/src/main/resources/typescript/generators/fetch/index.mustache b/modules/openapi-generator/src/main/resources/typescript/generators/fetch/index.mustache index e7c7bd4e5a9..f244e4733a8 100644 --- a/modules/openapi-generator/src/main/resources/typescript/generators/fetch/index.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/generators/fetch/index.mustache @@ -1,8 +1,18 @@ -export * from './http/http'; -export { IsomorphicFetchHttpLibrary } from './http/isomorphic-fetch'; -export * from './auth/auth'; -export * from './middleware'; -export * from './models/all'; -export { Configuration} from './configuration' -export * from './PromiseAPI'; -export * from './apis/exception'; \ No newline at end of file +import * as http from './http/http'; +import * as auth from './auth/auth'; +import {Middleware} from './middleware'; +import * as models from './models/all'; +import { Configuration} from './configuration' +import * as apis from './PromiseAPI'; +import * as exceptions from './apis/exception'; + +export { + http, + + auth, + Middleware, + models, + Configuration, + apis, + exceptions +}; \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript/http/http.mustache b/modules/openapi-generator/src/main/resources/typescript/http/http.mustache index 8e11238e3c7..692cac75146 100644 --- a/modules/openapi-generator/src/main/resources/typescript/http/http.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/http/http.mustache @@ -4,6 +4,8 @@ import * as FormData from "form-data"; // @ts-ignore import * as URLParse from "url-parse"; +export * from './isomorphic-fetch'; + export enum HttpMethod { GET = "GET", HEAD = "HEAD", diff --git a/samples/client/petstore/typescript/builds/default/http/http.ts b/samples/client/petstore/typescript/builds/default/http/http.ts index 8e11238e3c7..34bffd7a8e4 100644 --- a/samples/client/petstore/typescript/builds/default/http/http.ts +++ b/samples/client/petstore/typescript/builds/default/http/http.ts @@ -4,6 +4,8 @@ import * as FormData from "form-data"; // @ts-ignore import * as URLParse from "url-parse"; +export * from './isomorphic-fetch'; + export enum HttpMethod { GET = "GET", HEAD = "HEAD", @@ -103,4 +105,4 @@ export class ResponseContext { export interface HttpLibrary { send(request: RequestContext): Promise; -} \ 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 e7c7bd4e5a9..5de2901009a 100644 --- a/samples/client/petstore/typescript/builds/default/index.ts +++ b/samples/client/petstore/typescript/builds/default/index.ts @@ -1,8 +1,19 @@ -export * from './http/http'; -export { IsomorphicFetchHttpLibrary } from './http/isomorphic-fetch'; -export * from './auth/auth'; -export * from './middleware'; -export * from './models/all'; -export { Configuration} from './configuration' -export * from './PromiseAPI'; -export * from './apis/exception'; \ No newline at end of file +import * as http from './http/http'; +import * as auth from './auth/auth'; +import {Middleware} from './middleware'; +import * as models from './models/all'; +import { Configuration} from './configuration' +import * as apis from './PromiseAPI'; +import * as exceptions from './apis/exception'; + + +export { + http, + + auth, + Middleware, + models, + Configuration, + apis, + exceptions +}; \ No newline at end of file diff --git a/samples/client/petstore/typescript/tests/default/test.ts b/samples/client/petstore/typescript/tests/default/test.ts deleted file mode 100644 index 763d9ea8db0..00000000000 --- a/samples/client/petstore/typescript/tests/default/test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {PetApi, Configuration, Middleware, RequestContext, ResponseContext} from 'ts-petstore-client'; - -class MiddlewareA implements Middleware { - - public pre(request: RequestContext) { - console.log(request); - return Promise.resolve(request); - } - - public post(response: ResponseContext) { - console.log(response) - return Promise.resolve(response); - } -} - -const config = new Configuration({ - middleware: [ - new MiddlewareA() - ] -}); -const api = new PetApi(config); - -api.getPetById(3).then((pet) => { - console.log(pet) -}).catch((err) => { - console.log(err); -}); 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 53bdb215ea3..98c478995ce 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 @@ -1,15 +1,16 @@ -import {PetApi, Configuration, Pet, ApiException, Tag, HttpFile} from 'ts-petstore-client' +import * as petstore from 'ts-petstore-client' + import { expect, assert } from "chai"; import * as fs from 'fs'; -const configuration = new Configuration() -const petApi = new PetApi(configuration) +const configuration = new petstore.Configuration() +const petApi = new petstore.apis.PetApi(configuration) -const tag = new Tag(); +const tag = new petstore.models.Tag(); tag.name = "tag1" tag.id = Math.floor(Math.random() * 100000) -const pet = new Pet() +const pet = new petstore.models.Pet() pet.id = Math.floor(Math.random() * 100000) pet.name = "PetName" pet.photoUrls = [] @@ -34,7 +35,7 @@ describe("PetApi", () =>{ return petApi.deletePet(pet.id) }).then(() => { return petApi.getPetById(pet.id) - }).then((pet: Pet) => { + }).then((pet: petstore.models.Pet) => { done("Pet with id " + pet.id + " was not deleted!"); }).catch((err: any) => { if (err.code && err.code == 404) { @@ -48,7 +49,7 @@ describe("PetApi", () =>{ it("findPetsByStatus", (done) => { petApi.addPet(pet).then(() => { return petApi.findPetsByStatus(["available"]) - }).then((pets: Pet[]) => { + }).then((pets: petstore.models.Pet[]) => { expect(pets.length).to.be.at.least(1); done(); }).catch((err) => { @@ -71,7 +72,7 @@ describe("PetApi", () =>{ it("getPetById", (done) => { petApi.addPet(pet).then(() => { return petApi.getPetById(pet.id) - }).then((returnedPet: Pet) => { + }).then((returnedPet: petstore.models.Pet) => { expect(returnedPet).to.deep.equal(pet); done(); }).catch((err) => { @@ -92,7 +93,7 @@ describe("PetApi", () =>{ }); }).then(() => { return petApi.getPetById(pet.id); - }).then((returnedPet: Pet) => { + }).then((returnedPet: petstore.models.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 790d34caaa8..5993b740439 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 @@ -1,5 +1,4 @@ -import {NoAuthentication, APIKeyAuthentication} from "ts-petstore-client"; -import {RequestContext, HttpMethod} from 'ts-petstore-client'; +import * as petstore from 'ts-petstore-client'; import { expect} from "chai"; @@ -7,8 +6,8 @@ import { expect} from "chai"; describe("Security Authentication", () => { describe("No Authentication", () => { it("No Authentication", () => { - let ctx = new RequestContext("http://google.com", HttpMethod.GET); - let noAuth = new NoAuthentication(); + let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); + let noAuth = new petstore.auth.NoAuthentication(); noAuth.applySecurityAuthentication(ctx); expect(ctx.getUrl()).to.equal("http://google.com"); @@ -20,8 +19,8 @@ describe("Security Authentication", () => { describe("API Key Authentication", () => { // TODO: make all params const variables it("Header API Key", () => { - let ctx = new RequestContext("http://google.com", HttpMethod.GET); - let auth = new APIKeyAuthentication("my_name", "paramName", "header", "apiKey"); + let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); + let auth = new petstore.auth.APIKeyAuthentication("my_name", "paramName", "header", "apiKey"); auth.applySecurityAuthentication(ctx); expect(ctx.getUrl()).to.equal("http://google.com"); @@ -31,8 +30,8 @@ describe("Security Authentication", () => { }); it("Query API Key", () => { - let ctx = new RequestContext("http://google.com?a=b", HttpMethod.GET); - let auth = new APIKeyAuthentication("my_name", "paramName", "query", "apiKey",); + 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",); auth.applySecurityAuthentication(ctx); expect(ctx.getUrl()).to.contain("paramName=apiKey"); @@ -41,8 +40,8 @@ describe("Security Authentication", () => { }); it("Cookie API Key", () => { - let ctx = new RequestContext("http://google.com", HttpMethod.GET); - let auth = new APIKeyAuthentication("my_name", "paramName", "cookie", "apiKey",); + let ctx = new petstore.http.RequestContext("http://google.com", petstore.http.HttpMethod.GET); + let auth = new petstore.auth.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 181477a408c..3fa0113d37b 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 @@ -1,9 +1,11 @@ -import {RequestContext, HttpMethod, ResponseContext, HttpLibrary, IsomorphicFetchHttpLibrary } from "ts-petstore-client"; +import * as petstore from "ts-petstore-client"; + + import { expect} from "chai"; import * as FormData from "form-data"; -let libs: { [key: string]: HttpLibrary } = { - "isomorphic-fetch": new IsomorphicFetchHttpLibrary() +let libs: { [key: string]: petstore.http.HttpLibrary } = { + "isomorphic-fetch": new petstore.http.IsomorphicFetchHttpLibrary() } @@ -12,10 +14,10 @@ for (let libName in libs) { describe("Isomorphic Fetch", () => { it("GET-Request", (done) => { - let requestContext = new RequestContext("http://httpbin.org/get", HttpMethod.GET); + let requestContext = new petstore.http.RequestContext("http://httpbin.org/get", petstore.http.HttpMethod.GET); requestContext.setHeaderParam("X-Test-Token", "Test-Token"); requestContext.addCookie("test-cookie", "cookie-value"); - lib.send(requestContext).then((resp: ResponseContext) => { + lib.send(requestContext).then((resp: petstore.http.ResponseContext) => { expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); let body = JSON.parse(resp.body); expect(body["headers"]).to.exist; @@ -28,7 +30,7 @@ for (let libName in libs) { }) it("POST-Request", (done) => { - let requestContext = new RequestContext("http://httpbin.org/post", HttpMethod.POST); + let requestContext = new petstore.http.RequestContext("http://httpbin.org/post", petstore.http.HttpMethod.POST); requestContext.setHeaderParam("X-Test-Token", "Test-Token"); requestContext.addCookie("test-cookie", "cookie-value"); let formData: FormData = new FormData() @@ -36,7 +38,7 @@ for (let libName in libs) { formData.append("testFile", Buffer.from("abc"), "fileName.json"); requestContext.setBody(formData); - lib.send(requestContext).then((resp: ResponseContext) => { + lib.send(requestContext).then((resp: petstore.http.ResponseContext) => { expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); let body = JSON.parse(resp.body); expect(body["headers"]).to.exist; @@ -51,10 +53,10 @@ for (let libName in libs) { }); it("Cookies-Request", (done) => { - let requestContext = new RequestContext("http://httpbin.org/cookies", HttpMethod.GET); + let requestContext = new petstore.http.RequestContext("http://httpbin.org/cookies", petstore.http.HttpMethod.GET); requestContext.addCookie("test-cookie", "cookie-value"); - lib.send(requestContext).then((resp: ResponseContext) => { + lib.send(requestContext).then((resp: petstore.http.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 a6cb1bcc994..d35020f3209 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 @@ -1,6 +1,6 @@ const rewire = require("rewire") import { expect} from "chai"; -import {Pet, Category, Tag} from "ts-petstore-client" +import * as petstore from "ts-petstore-client" const objectSerializerFile = rewire(__dirname + "/../../node_modules/ts-petstore-client/models/ObjectSerializer.ts") @@ -41,7 +41,7 @@ describe("ObjectSerializer", () => { }) it("Class", () => { - const input = new Category() + const input = new petstore.models.Category() input.id = 4 input.name = "Test" expect(ObjectSerializer.serialize(input, "Category")).to.deep.equal({ "id": input.id, "name": input.name}) @@ -56,7 +56,7 @@ describe("ObjectSerializer", () => { const tags = [] const tagResult = [] for (let i = 0; i < 2; i++) { - const tag = new Tag() + const tag = new petstore.models.Tag() tag.id = i tag.name = "Tag" + i tags.push(tag) @@ -66,10 +66,10 @@ describe("ObjectSerializer", () => { }) } - const category = new Category() + const category = new petstore.models.Category() category.id = 4 category.name = "TestCat" - const pet = new Pet() + const pet = new petstore.models.Pet() pet.id = 145 pet.category = category pet.name = "PetName" @@ -93,7 +93,7 @@ describe("ObjectSerializer", () => { const categories = [] const result = [] for (let i = 0; i < 2; i++) { - const category = new Category() + const category = new petstore.models.Category() category.id = i category.name = "Cat" + i categories.push(category) @@ -139,7 +139,7 @@ describe("ObjectSerializer", () => { }) it("Class", () => { - const input = new Category() + const input = new petstore.models.Category() input.id = 4 input.name = "Test" const deserialized = ObjectSerializer.deserialize({ "id": 4, "name": "Test"}, "Category") @@ -157,7 +157,7 @@ describe("ObjectSerializer", () => { const tags = [] const tagResult = [] for (let i = 0; i < 2; i++) { - const tag = new Tag() + const tag = new petstore.models.Tag() tag.id = i tag.name = "Tag" + i tags.push(tag) @@ -167,10 +167,10 @@ describe("ObjectSerializer", () => { }) } - const category = new Category() + const category = new petstore.models.Category() category.id = 4 category.name = "TestCat" - const pet = new Pet() + const pet = new petstore.models.Pet() pet.id = 145 pet.category = category pet.name = "PetName" @@ -188,7 +188,7 @@ describe("ObjectSerializer", () => { "photoUrls": [ "url", "other url"], "status": "available", "tags": tagResult - }, "Pet") as Pet + }, "Pet") as petstore.models.Pet expect(deserialized.constructor.name).to.equal("Pet") expect(deserialized.category.constructor.name).to.equal("Category") @@ -202,7 +202,7 @@ describe("ObjectSerializer", () => { const categories = [] const result = [] for (let i = 0; i < 2; i++) { - const category = new Category() + const category = new petstore.models.Category() category.id = i category.name = "Cat" + i categories.push(category)