@penkov/swagger-code-gen 1.9.4 → 1.10.0
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/components-parse.js +15 -2
- package/dist/name.utils.js +8 -5
- package/dist/property.js +18 -2
- package/dist/templates/scats-schema.ejs +11 -11
- package/dist/templates/schema.ejs +1 -1
- package/package.json +1 -1
package/dist/components-parse.js
CHANGED
|
@@ -89,16 +89,29 @@ export function resolvePaths(json, schemasTypes, options, pool) {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
export function generateInPlace(paths, schemasTypes, options, pool) {
|
|
92
|
+
const collectInplaceFromProperty = (p) => {
|
|
93
|
+
if (p.inPlace.isDefined) {
|
|
94
|
+
return Collection.of(SchemaObject.fromDefinition(p.items, p.inPlace.get, schemasTypes, options, pool));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return Nil;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
92
100
|
const res = new mutable.ArrayBuffer();
|
|
93
101
|
res.appendAll(paths.filter(m => option(m.response.inPlace).isDefined)
|
|
94
102
|
.map(m => {
|
|
95
103
|
return SchemaObject.fromDefinition(m.response.responseType, m.response.inPlace, schemasTypes, options, pool);
|
|
96
|
-
})
|
|
104
|
+
})
|
|
105
|
+
.appendedAll(paths.flatMap(m => m.body)
|
|
97
106
|
.filter(b => option(b.inPlace).isDefined)
|
|
98
107
|
.map(m => {
|
|
99
108
|
console.log(`Generating inplace body: ${m.inPlaceClassname}`);
|
|
100
109
|
return SchemaObject.fromDefinition(m.inPlaceClassname, m.inPlace, schemasTypes, options, pool);
|
|
101
|
-
}))
|
|
110
|
+
}))
|
|
111
|
+
.appendedAll(pool.values.filter(s => s.schemaType === 'object')
|
|
112
|
+
.map(s => s)
|
|
113
|
+
.flatMap(s => s.properties)
|
|
114
|
+
.flatMap(p => collectInplaceFromProperty(p))));
|
|
102
115
|
let pending = res.toCollection.flatMap(s => s.properties).filter(p => p.inPlace.isDefined);
|
|
103
116
|
while (pending.nonEmpty) {
|
|
104
117
|
const pass2 = pending.map(p => {
|
package/dist/name.utils.js
CHANGED
|
@@ -6,16 +6,16 @@ export class NameUtils {
|
|
|
6
6
|
let needUpperCase = true;
|
|
7
7
|
for (let i = 0; i < n.length; i++) {
|
|
8
8
|
const c = n[i];
|
|
9
|
-
|
|
9
|
+
let toAppend = c;
|
|
10
|
+
if (c === '.' || c === '-' || c === '/') {
|
|
10
11
|
needUpperCase = true;
|
|
12
|
+
toAppend = '';
|
|
11
13
|
}
|
|
12
14
|
else if (needUpperCase) {
|
|
13
|
-
|
|
15
|
+
toAppend = c.toUpperCase();
|
|
14
16
|
needUpperCase = false;
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
res += c;
|
|
18
|
-
}
|
|
18
|
+
res += toAppend;
|
|
19
19
|
}
|
|
20
20
|
return res;
|
|
21
21
|
}
|
|
@@ -27,4 +27,7 @@ export class NameUtils {
|
|
|
27
27
|
return n.replace(/[./]/g, '_');
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
static normalisePropertyName(n) {
|
|
31
|
+
return n.replace(/[.-]/g, '_');
|
|
32
|
+
}
|
|
30
33
|
}
|
package/dist/property.js
CHANGED
|
@@ -31,7 +31,9 @@ export class Property {
|
|
|
31
31
|
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
|
|
32
32
|
const itemReferencesObject = option(definition.items)
|
|
33
33
|
.flatMap(i => option(i.$ref))
|
|
34
|
-
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'))
|
|
34
|
+
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object')) ||
|
|
35
|
+
option(definition.items).exists(i => option(i.type).contains('object') &&
|
|
36
|
+
option(i.properties).map(p => Object.keys(p).length).getOrElseValue(0) > 0);
|
|
35
37
|
let inplace = none;
|
|
36
38
|
const type = option(definition.$ref).map(ref => ref.substring(SCHEMA_PREFIX.length))
|
|
37
39
|
.orElse(() => {
|
|
@@ -87,6 +89,15 @@ export class Property {
|
|
|
87
89
|
const required = option(definition.required).contains(true);
|
|
88
90
|
const items = option(definition.items?.$ref)
|
|
89
91
|
.map(ref => ref.substring(SCHEMA_PREFIX.length))
|
|
92
|
+
.orElse(() => {
|
|
93
|
+
if (definition.type === 'array' && option(definition.items).exists(i => i.type === 'object')) {
|
|
94
|
+
inplace = some(definition.items);
|
|
95
|
+
return some(parentClassname + '$' + name);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return none;
|
|
99
|
+
}
|
|
100
|
+
})
|
|
90
101
|
.orElseValue(option(definition.items?.type))
|
|
91
102
|
.orElse(() => option(definition.items?.oneOf)
|
|
92
103
|
.map(x => Collection.from(x))
|
|
@@ -122,7 +133,7 @@ export class Property {
|
|
|
122
133
|
}
|
|
123
134
|
static toJsType(tpe, itemTpe = 'any', format = none) {
|
|
124
135
|
return option(tpe)
|
|
125
|
-
.map(x => Collection.from(x.split('|')))
|
|
136
|
+
.map(x => Array.isArray(x) ? Collection.from(x) : Collection.from(x.split('|')))
|
|
126
137
|
.getOrElseValue(Nil)
|
|
127
138
|
.map(x => x.trim())
|
|
128
139
|
.map(t => {
|
|
@@ -141,6 +152,8 @@ export class Property {
|
|
|
141
152
|
return 'File';
|
|
142
153
|
case 'any':
|
|
143
154
|
return 'any';
|
|
155
|
+
case 'null':
|
|
156
|
+
return 'null';
|
|
144
157
|
case 'String':
|
|
145
158
|
case 'string':
|
|
146
159
|
if (format.contains('binary')) {
|
|
@@ -160,6 +173,9 @@ export class Property {
|
|
|
160
173
|
get normalType() {
|
|
161
174
|
return NameUtils.normaliseClassname(this.type);
|
|
162
175
|
}
|
|
176
|
+
get normalisedName() {
|
|
177
|
+
return NameUtils.normalisePropertyName(this.name);
|
|
178
|
+
}
|
|
163
179
|
get itemScatsWrapperType() {
|
|
164
180
|
if (this.isArray) {
|
|
165
181
|
if (this.itemReferencesObject) {
|
|
@@ -8,7 +8,7 @@ export class <%= schema.normalName %>Dto {
|
|
|
8
8
|
*/
|
|
9
9
|
constructor(
|
|
10
10
|
<%_ schema.properties.foreach(p => { -%>
|
|
11
|
-
readonly <%= p.
|
|
11
|
+
readonly <%= p.normalisedName %>: <%- p.scatsWrapperType %>,
|
|
12
12
|
<%_ }); -%>
|
|
13
13
|
) {}
|
|
14
14
|
|
|
@@ -18,17 +18,17 @@ export class <%= schema.normalName %>Dto {
|
|
|
18
18
|
<%_ schema.properties.foreach(p => { _%>
|
|
19
19
|
<%_ if (p.referencesObject) { _%>
|
|
20
20
|
<%_ if (p.required && !p.nullable) { _%>
|
|
21
|
-
<%- p.scatsWrapperType %>.fromJson(json
|
|
21
|
+
<%- p.scatsWrapperType %>.fromJson(json['<%= p.name %>']),
|
|
22
22
|
<%_ } else { _%>
|
|
23
|
-
option(json
|
|
23
|
+
option(json['<%= p.name %>']).map(_ => <%- p.normalType %>Dto.fromJson(_)),
|
|
24
24
|
<%_ } _%>
|
|
25
25
|
<%_ } else if (p.isArray) { _%>
|
|
26
|
-
Collection.from(option(json
|
|
26
|
+
Collection.from(option(json['<%= p.name %>']).getOrElseValue([]))
|
|
27
27
|
<% if (p.itemReferencesObject) { _%>.map(i => <%- p.itemScatsWrapperType %>.fromJson(i))<%_ } _%>,
|
|
28
28
|
<%_ } else if (p.required && !p.nullable) { _%>
|
|
29
29
|
json.<%= p.name %>,
|
|
30
30
|
<%_ } else { _%>
|
|
31
|
-
option(json
|
|
31
|
+
option(json['<%= p.name %>']),
|
|
32
32
|
<%_ } _%>
|
|
33
33
|
<%_ }); _%>
|
|
34
34
|
);
|
|
@@ -37,7 +37,7 @@ export class <%= schema.normalName %>Dto {
|
|
|
37
37
|
copy(fields: Partial<<%= schema.normalName %>Dto>): <%= schema.normalName %>Dto {
|
|
38
38
|
return new <%= schema.normalName %>Dto(
|
|
39
39
|
<%_ schema.properties.foreach(p => { -%>
|
|
40
|
-
option(fields.<%= p.
|
|
40
|
+
option(fields.<%= p.normalisedName %>).getOrElseValue(this.<%= p.normalisedName %>),
|
|
41
41
|
<%_ }); -%>
|
|
42
42
|
);
|
|
43
43
|
}
|
|
@@ -47,18 +47,18 @@ export class <%= schema.normalName %>Dto {
|
|
|
47
47
|
<%_ schema.properties.foreach(p => { _%>
|
|
48
48
|
<%_ if (p.referencesObject) { _%>
|
|
49
49
|
<%_ if (p.required && !p.nullable) { _%>
|
|
50
|
-
<%= p.name
|
|
50
|
+
'<%= p.name %>': this.<%= p.normalisedName %>.toJson,
|
|
51
51
|
<%_ } else { _%>
|
|
52
|
-
<%= p.name
|
|
52
|
+
'<%= p.name %>': this.<%= p.normalisedName %>.map(_ => _.toJson).orUndefined,
|
|
53
53
|
<%_ } _%>
|
|
54
54
|
<%_ } else if (p.isArray) { _%>
|
|
55
|
-
<%= p.name
|
|
55
|
+
'<%= p.name %>': this.<%= p.normalisedName %>
|
|
56
56
|
<% if (p.itemReferencesObject) { _%>.map(_ => _.toJson)<%_ } _%>
|
|
57
57
|
.toArray,
|
|
58
58
|
<%_ } else if (p.required && !p.nullable) { _%>
|
|
59
|
-
<%= p.name
|
|
59
|
+
'<%= p.name %>': this.<%= p.normalisedName %>,
|
|
60
60
|
<%_ } else { _%>
|
|
61
|
-
<%= p.name
|
|
61
|
+
'<%= p.name %>': this.<%= p.normalisedName %>.orUndefined,
|
|
62
62
|
<%_ } _%>
|
|
63
63
|
<%_ }); _%>
|
|
64
64
|
};
|
|
@@ -6,7 +6,7 @@ export interface <%= schema.normalName %><%= schema.parentsString%> {
|
|
|
6
6
|
* <%= d %>
|
|
7
7
|
*/
|
|
8
8
|
<%_ }); -%>
|
|
9
|
-
readonly <%= p.name
|
|
9
|
+
readonly '<%= p.name %>'<%= !p.required ? '?' : '' %>: <%- p.jsType %>;
|
|
10
10
|
<%_ }); -%>
|
|
11
11
|
}
|
|
12
12
|
<%_ } if (schema.schemaType === 'enum') { -%>
|