Archived
1
0
Fork 0

expose fields of schemas to XXX.fields

This commit is contained in:
supmiku39 2020-04-15 07:15:54 +09:00
parent bee45e6e4b
commit c482e91cbc
4 changed files with 15 additions and 5 deletions

View file

@ -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

10
dist/codegen.js vendored
View file

@ -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<keyof " + typeName + "> = [", 1);
cp.writeln(propTypes.map(function (e) { return "'" + e[0] + "',"; }).join(' '));
cp.writeln(']', -1);
// end of class
cp.writeln('}', -1);
}

View file

@ -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<keyof ${typeName}> = [`, 1);
cp.writeln(propTypes.map(e => `'${e[0]}',`).join(' '));
cp.writeln(']', -1);
// end of class
cp.writeln('}', -1);
} else {

View file

@ -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",