From 9b668f0b2f6b2f3d8dd8dd33348b899d597f773f Mon Sep 17 00:00:00 2001 From: supmiku39 Date: Sat, 11 Apr 2020 02:22:47 +0900 Subject: [PATCH] fix README.md APIPromise#on fix codegen indent bug --- README.md | 16 ++++++++-------- lib/codegen.ts | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1fae878..dce7d66 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # OpenAPI codegen for TypeScript ## What is this? -It is a TypeScript code generator which generates TypeScript classes and interfaces base on your [OpenAPI document](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md), including +This is a TypeScript code generator which generates TypeScript classes and interfaces base on your [OpenAPI document](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md), including - `schemas` - `IHandler`, type-defined interfaces for both server and client api - `IServerAPI`, interface for server api @@ -11,8 +11,8 @@ It is a TypeScript code generator which generates TypeScript classes and interfa This tool assumes you use **koa router** for server and **axios** for client. -## How to use it? -### 0. Install this tool +## How to use this tool? +### 0. Install it ``` yarn add -D @supmiku39/api-ts-gen ``` @@ -25,7 +25,7 @@ yarn add -D @types/koa @types/koa__router axios ### 1. Write your OpenAPI document You can use [Swagger Editor](https://swagger.io/tools/swagger-editor/) to edit your api document. Make sure to follow the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md). -This code generator generates code from `paths` and `components/schemas`. +This tool generates code from `paths` and `components/schemas`. :warning: only `get`, `post`, `update`, `delete`, `patch` are supported in `paths` ### 2. Set path alias @@ -223,16 +223,16 @@ If there is only one `2xx` in the status code and error handling is not required ``` const a: SchemaA = await api.getA(...); ``` -However, if you want to handle several kinds of response, you can use `.onXXX(responseBody => handler)` where `XXX` is the status code. +However, if you want to handle several kinds of response, you can use `.on(statusCode, responseBody => handler)` where `XXX` is the status code. ``` api.getA(...) - .on200(a => { // the compiler knows that type of `a` is `SchemaA` + .on(200, a => { // the compiler knows that type of `a` is `SchemaA` console.log('Get a successfully', a); }) - .on404(msg => { + .on(404, msg => { console.log('Not found with msg', msg); }) - .on403(() => { + .on(403, () => { console.log('Forbidden with no msg'); }); ``` diff --git a/lib/codegen.ts b/lib/codegen.ts index 55e1d92..696000d 100644 --- a/lib/codegen.ts +++ b/lib/codegen.ts @@ -265,9 +265,9 @@ function codegenClientAPI(funcs: APIFuncs, config: Config, cp: CodePrinter) { cp.writeln('set $baseURL(url: string) {', 1); cp.writeln('$http.interceptors.request.use(async config => {', 1); cp.writeln('config.baseURL = url;'); - cp.writeln('return config;', -1); + cp.writeln('return config;'); cp.writeln('}, err => Promise.reject(err));', -1); - cp.writeln('},'); + cp.writeln('},', -1); // functions for (const [funcName, func] of Object.entries(funcs)) { const ncHandler = `IHandler.${funcName}`;