From c482e91cbc51d6d90474ff1d1023a6546a0b2cb6 Mon Sep 17 00:00:00 2001 From: supmiku39 Date: Wed, 15 Apr 2020 07:15:54 +0900 Subject: [PATCH] expose fields of schemas to XXX.fields --- README.md | 2 ++ dist/codegen.js | 10 +++++++--- lib/codegen.ts | 6 +++++- package.json | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dce7d66..35811c7 100644 --- a/README.md +++ b/README.md @@ -477,6 +477,8 @@ This tool only supports `application/json` type for request and response body. A Other $ref like requestBody, responseBody are not supported currently. ## Versions +#### 1.1.3 +- expose fields of schemas to XXX.fields(static variable) #### 1.1.2 - publish to npmjs and change the package name in generated code - specify constructor argument type of FullDate diff --git a/dist/codegen.js b/dist/codegen.js index f002c3a..6352346 100644 --- a/dist/codegen.js +++ b/dist/codegen.js @@ -264,9 +264,9 @@ function codegenClientAPI(funcs, config, cp) { 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 (var _i = 0, _a = Object.entries(funcs); _i < _a.length; _i++) { var _b = _a[_i], funcName = _b[0], func = _b[1]; @@ -330,7 +330,7 @@ function codegenSchemas(schemas, config, cp) { propTypes.push([propName, propType]); cp.writeln(propType.forProp(propName) + ';'); } - // method + // constructor cp.writeln('constructor(o: {[_: string]: any}){', 1); for (var _f = 0, propTypes_1 = propTypes; _f < propTypes_1.length; _f++) { var _g = propTypes_1[_f], n = _g[0], t = _g[1]; @@ -347,6 +347,10 @@ function codegenSchemas(schemas, config, cp) { } cp.writeln('return r;'); cp.writeln('}', -1); + // fields + cp.writeln("static fields: Array = [", 1); + cp.writeln(propTypes.map(function (e) { return "'" + e[0] + "',"; }).join(' ')); + cp.writeln(']', -1); // end of class cp.writeln('}', -1); } diff --git a/lib/codegen.ts b/lib/codegen.ts index 696000d..75da415 100644 --- a/lib/codegen.ts +++ b/lib/codegen.ts @@ -325,7 +325,7 @@ function codegenSchemas(schemas: Schemas, config: Config, cp: CodePrinter) { propTypes.push([propName, propType]); cp.writeln(propType.forProp(propName)+';'); } - // method + // constructor cp.writeln('constructor(o: {[_: string]: any}){', 1); for (const [n, t] of propTypes) { cp.writeln(`this.${n} = ${t.stp(`o.${n}`, typeName+'.'+n)};`); @@ -342,6 +342,10 @@ function codegenSchemas(schemas: Schemas, config: Config, cp: CodePrinter) { } cp.writeln('return r;'); cp.writeln('}', -1); + // fields + cp.writeln(`static fields: Array = [`, 1); + cp.writeln(propTypes.map(e => `'${e[0]}',`).join(' ')); + cp.writeln(']', -1); // end of class cp.writeln('}', -1); } else { diff --git a/package.json b/package.json index 9ad2ec3..d8ef7a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@supmiku39/api-ts-gen", - "version": "1.1.2-a", + "version": "1.1.3", "description": "OpenAPI code generator for TypeScript", "main": "dist/index.js", "types": "dist/index.d.ts",