forked from loafle/openapi-generator-original
Restructured module layout
This commit is contained in:
parent
8068315f79
commit
aeef285190
@ -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';
|
||||
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
|
||||
};
|
@ -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",
|
||||
|
@ -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<ResponseContext>;
|
||||
}
|
||||
}
|
||||
|
@ -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';
|
||||
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
|
||||
};
|
@ -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);
|
||||
});
|
@ -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();
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user