@penkov/swagger-code-gen 1.8.2 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/name.utils.js +1 -1
- package/dist/parameter.js +14 -5
- package/dist/templates/method.ejs +1 -1
- package/package.json +1 -1
package/dist/name.utils.js
CHANGED
package/dist/parameter.js
CHANGED
|
@@ -3,8 +3,9 @@ import { Collection, identity, none, option } from 'scats';
|
|
|
3
3
|
import { Method } from './method.js';
|
|
4
4
|
import { Property } from './property.js';
|
|
5
5
|
export class Parameter {
|
|
6
|
-
constructor(name, uniqueName, inValue, jsType, required, isArray, defaultValue, description) {
|
|
6
|
+
constructor(name, rawName, uniqueName, inValue, jsType, required, isArray, defaultValue, description) {
|
|
7
7
|
this.name = name;
|
|
8
|
+
this.rawName = rawName;
|
|
8
9
|
this.uniqueName = uniqueName;
|
|
9
10
|
this.inValue = inValue;
|
|
10
11
|
this.jsType = jsType;
|
|
@@ -16,10 +17,18 @@ export class Parameter {
|
|
|
16
17
|
}
|
|
17
18
|
static fromDefinition(def, schemas, options) {
|
|
18
19
|
const name = Parameter.toJSName(def.name);
|
|
20
|
+
const rawName = def.name;
|
|
19
21
|
const inValue = def.in;
|
|
20
22
|
const desc = option(def.description);
|
|
21
23
|
let defaultValue = none;
|
|
22
|
-
const schema =
|
|
24
|
+
const schema = def.schema ?
|
|
25
|
+
SchemaFactory.build(def.name, def.schema, schemas, options) :
|
|
26
|
+
Property.fromDefinition(name, {
|
|
27
|
+
...def,
|
|
28
|
+
type: def['type'],
|
|
29
|
+
required: option(def.required).filter(x => typeof x === 'boolean')
|
|
30
|
+
.map(x => x).orUndefined
|
|
31
|
+
}, schemas, options);
|
|
23
32
|
let jsType;
|
|
24
33
|
if (schema instanceof SchemaObject) {
|
|
25
34
|
jsType = schema.type;
|
|
@@ -53,8 +62,8 @@ export class Parameter {
|
|
|
53
62
|
throw new Error('Unknown schema type');
|
|
54
63
|
}
|
|
55
64
|
const required = option(def.required).exists(identity) || defaultValue.nonEmpty;
|
|
56
|
-
const isArray = def
|
|
57
|
-
return new Parameter(name, name, inValue, jsType, required, isArray, defaultValue, desc);
|
|
65
|
+
const isArray = def?.schema?.type === 'array';
|
|
66
|
+
return new Parameter(name, rawName, name, inValue, jsType, required, isArray, defaultValue, desc);
|
|
58
67
|
}
|
|
59
68
|
static toJSName(path) {
|
|
60
69
|
const tokens = Collection.from(path.split(/\W/)).filter(t => t.length > 0);
|
|
@@ -63,6 +72,6 @@ export class Parameter {
|
|
|
63
72
|
}).mkString();
|
|
64
73
|
}
|
|
65
74
|
copy(p) {
|
|
66
|
-
return new Parameter(option(p.name).getOrElseValue(this.name), option(p.uniqueName).getOrElseValue(this.uniqueName), option(p.in).getOrElseValue(this.in), option(p.jsType).getOrElseValue(this.jsType), option(p.required).getOrElseValue(this.required), option(p.isArray).getOrElseValue(this.isArray), option(p.defaultValue).getOrElseValue(this.defaultValue), option(p.description).getOrElseValue(this.description));
|
|
75
|
+
return new Parameter(option(p.name).getOrElseValue(this.name), option(p.rawName).getOrElseValue(this.rawName), option(p.uniqueName).getOrElseValue(this.uniqueName), option(p.in).getOrElseValue(this.in), option(p.jsType).getOrElseValue(this.jsType), option(p.required).getOrElseValue(this.required), option(p.isArray).getOrElseValue(this.isArray), option(p.defaultValue).getOrElseValue(this.defaultValue), option(p.description).getOrElseValue(this.description));
|
|
67
76
|
}
|
|
68
77
|
}
|
|
@@ -82,7 +82,7 @@ export async function <%= method.endpointName %><%= body.map(b => b.suffix).getO
|
|
|
82
82
|
<%_ } -%>
|
|
83
83
|
<%_ if (method.parameters.filter(x => x.in === 'header').nonEmpty) { -%>
|
|
84
84
|
<%_ method.parameters.filter(x => x.in === 'header').foreach(p => { -%>
|
|
85
|
-
<%= p.
|
|
85
|
+
'<%= p.rawName %>': <%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %>,
|
|
86
86
|
<%_ }) -%>
|
|
87
87
|
<%_ } -%>
|
|
88
88
|
};
|