@penkov/swagger-code-gen 1.9.0 → 1.9.2
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 +19 -5
- package/dist/method.js +7 -7
- package/dist/parameter.js +1 -1
- package/dist/property.js +15 -4
- package/dist/schemas.js +6 -6
- package/package.json +1 -1
package/dist/components-parse.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { Collection, mutable, option } from 'scats';
|
|
1
|
+
import { Collection, mutable, Nil, option } from 'scats';
|
|
2
2
|
import { SchemaFactory, SchemaObject } from './schemas.js';
|
|
3
3
|
import { SCHEMA_PREFIX } from './property.js';
|
|
4
4
|
import { Method, supportedBodyMimeTypes } from './method.js';
|
|
5
5
|
export function resolveSchemasTypes(json) {
|
|
6
6
|
const jsonSchemas = json.components.schemas;
|
|
7
7
|
const schemasNames = Collection.from(Object.keys(jsonSchemas));
|
|
8
|
-
const sharedBodies =
|
|
8
|
+
const sharedBodies = option(json?.components?.requestBodies)
|
|
9
|
+
.map(x => Collection.from(Object.keys(x)))
|
|
10
|
+
.getOrElseValue(Nil)
|
|
9
11
|
.toMap(name => {
|
|
10
12
|
const sharedBodyDef = json.components.requestBodies[name];
|
|
11
13
|
const mimeTypes = Collection.from(Object.keys(sharedBodyDef['content']));
|
|
@@ -23,7 +25,9 @@ export function resolveSchemasTypes(json) {
|
|
|
23
25
|
export function resolveSchemas(json, schemasTypes, options) {
|
|
24
26
|
const schemas = Collection.from(Object.keys(json.components.schemas))
|
|
25
27
|
.toMap(schemaName => [schemaName, json.components.schemas[schemaName]])
|
|
26
|
-
.appendedAll(
|
|
28
|
+
.appendedAll(option(json?.components?.requestBodies)
|
|
29
|
+
.map(x => Collection.from(Object.keys(x)))
|
|
30
|
+
.getOrElseValue(Nil)
|
|
27
31
|
.filter(rb => option(json.components.requestBodies[rb]['content']).isDefined)
|
|
28
32
|
.toMap(rb => {
|
|
29
33
|
const sharedBodyDef = json.components.requestBodies[rb];
|
|
@@ -85,7 +89,8 @@ export function resolvePaths(json, schemasTypes, options, pool) {
|
|
|
85
89
|
});
|
|
86
90
|
}
|
|
87
91
|
export function generateInPlace(paths, schemasTypes, options, pool) {
|
|
88
|
-
|
|
92
|
+
const res = new mutable.ArrayBuffer();
|
|
93
|
+
res.appendAll(paths.filter(m => option(m.response.inPlace).isDefined)
|
|
89
94
|
.map(m => {
|
|
90
95
|
return SchemaObject.fromDefinition(m.response.responseType, m.response.inPlace, schemasTypes, options, pool);
|
|
91
96
|
}).appendedAll(paths.flatMap(m => m.body)
|
|
@@ -93,5 +98,14 @@ export function generateInPlace(paths, schemasTypes, options, pool) {
|
|
|
93
98
|
.map(m => {
|
|
94
99
|
console.log(`Generating inplace body: ${m.inPlaceClassname}`);
|
|
95
100
|
return SchemaObject.fromDefinition(m.inPlaceClassname, m.inPlace, schemasTypes, options, pool);
|
|
96
|
-
}));
|
|
101
|
+
})));
|
|
102
|
+
let pending = res.toCollection.flatMap(s => s.properties).filter(p => p.inPlace.isDefined);
|
|
103
|
+
while (pending.nonEmpty) {
|
|
104
|
+
const pass2 = pending.map(p => {
|
|
105
|
+
return SchemaObject.fromDefinition(p.type, p.inPlace.get, schemasTypes, options, pool);
|
|
106
|
+
});
|
|
107
|
+
res.appendAll(pass2);
|
|
108
|
+
pending = pass2.flatMap(s => s.properties).filter(p => p.inPlace.isDefined);
|
|
109
|
+
}
|
|
110
|
+
return res.reverse;
|
|
97
111
|
}
|
package/dist/method.js
CHANGED
|
@@ -76,7 +76,7 @@ export class Method {
|
|
|
76
76
|
let res;
|
|
77
77
|
let inPlaceClassname = null;
|
|
78
78
|
if (SchemaFactory.isEmptyObjectOrArray(bodySchemaDef)) {
|
|
79
|
-
res = Property.fromDefinition('body', {
|
|
79
|
+
res = Property.fromDefinition('', 'body', {
|
|
80
80
|
...bodySchemaDef,
|
|
81
81
|
required: bodyRequired,
|
|
82
82
|
type: 'object'
|
|
@@ -84,21 +84,21 @@ export class Method {
|
|
|
84
84
|
}
|
|
85
85
|
else if (bodySchemaDef['$ref']) {
|
|
86
86
|
const ref = bodySchemaDef['$ref'].toString();
|
|
87
|
-
res = Property.fromDefinition('body', {
|
|
87
|
+
res = Property.fromDefinition('', 'body', {
|
|
88
88
|
...bodySchemaDef,
|
|
89
89
|
$ref: ref.startsWith(SHARED_BODIES_PREFIX) ? SCHEMA_PREFIX + ref.substring(SHARED_BODIES_PREFIX.length, ref.length) : ref,
|
|
90
90
|
required: bodyRequired
|
|
91
91
|
}, schemasTypes, options);
|
|
92
92
|
}
|
|
93
93
|
else if (bodySchemaDef['type']) {
|
|
94
|
-
res = Property.fromDefinition('body', {
|
|
94
|
+
res = Property.fromDefinition('', 'body', {
|
|
95
95
|
type: bodySchemaDef['type'],
|
|
96
96
|
required: bodyRequired
|
|
97
97
|
}, schemasTypes, options);
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
100
|
inPlaceClassname = NameUtils.normaliseClassname(def.operationId + 'Body$' + method);
|
|
101
|
-
res = Property.fromDefinition('body', {
|
|
101
|
+
res = Property.fromDefinition(inPlaceClassname, 'body', {
|
|
102
102
|
...bodySchemaDef,
|
|
103
103
|
$ref: SCHEMA_PREFIX + inPlaceClassname
|
|
104
104
|
}, schemasTypes.appended(inPlaceClassname, 'object'), options);
|
|
@@ -138,7 +138,7 @@ export class Method {
|
|
|
138
138
|
.map(p => {
|
|
139
139
|
if (p.schema.type === 'object' && p.schema['properties'] && Object.keys(p.schema['properties']).length > 0) {
|
|
140
140
|
const inPlaceObject = NameUtils.normaliseClassname(def.operationId + 'Response$' + method);
|
|
141
|
-
const r = Property.fromDefinition('', {
|
|
141
|
+
const r = Property.fromDefinition(inPlaceObject, '', {
|
|
142
142
|
...p.schema,
|
|
143
143
|
$ref: SCHEMA_PREFIX + inPlaceObject
|
|
144
144
|
}, schemasTypes.appended(inPlaceObject, 'object'), options).copy({
|
|
@@ -153,7 +153,7 @@ export class Method {
|
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
|
-
const r = Property.fromDefinition('', p.schema, schemasTypes, options).copy({
|
|
156
|
+
const r = Property.fromDefinition('', '', p.schema, schemasTypes, options).copy({
|
|
157
157
|
nullable: false,
|
|
158
158
|
required: true,
|
|
159
159
|
});
|
|
@@ -165,7 +165,7 @@ export class Method {
|
|
|
165
165
|
}
|
|
166
166
|
})
|
|
167
167
|
.getOrElseValue(({
|
|
168
|
-
asProperty: Property.fromDefinition('UNKNOWN', { type: 'any' }, schemasTypes, options),
|
|
168
|
+
asProperty: Property.fromDefinition('', 'UNKNOWN', { type: 'any' }, schemasTypes, options),
|
|
169
169
|
responseType: 'any',
|
|
170
170
|
}));
|
|
171
171
|
this.wrapParamsInObject = this.parameters.size > 2 || (this.body.nonEmpty) && this.parameters.nonEmpty;
|
package/dist/parameter.js
CHANGED
|
@@ -23,7 +23,7 @@ export class Parameter {
|
|
|
23
23
|
let defaultValue = none;
|
|
24
24
|
const schema = def.schema ?
|
|
25
25
|
SchemaFactory.build(def.name, def.schema, schemas, options) :
|
|
26
|
-
Property.fromDefinition(name, {
|
|
26
|
+
Property.fromDefinition('', name, {
|
|
27
27
|
...def,
|
|
28
28
|
type: def['type'],
|
|
29
29
|
required: option(def.required).filter(x => typeof x === 'boolean')
|
package/dist/property.js
CHANGED
|
@@ -3,7 +3,7 @@ import { SchemaFactory } from './schemas.js';
|
|
|
3
3
|
import { NameUtils } from './name.utils.js';
|
|
4
4
|
export const SCHEMA_PREFIX = '#/components/schemas/';
|
|
5
5
|
export class Property {
|
|
6
|
-
constructor(name, type, format, description, defaultValue, nullable, required, items, referencesObject, itemReferencesObject, enumValues) {
|
|
6
|
+
constructor(name, type, format, description, defaultValue, nullable, required, items, referencesObject, itemReferencesObject, enumValues, inPlace) {
|
|
7
7
|
this.name = name;
|
|
8
8
|
this.type = type;
|
|
9
9
|
this.format = format;
|
|
@@ -15,12 +15,13 @@ export class Property {
|
|
|
15
15
|
this.referencesObject = referencesObject;
|
|
16
16
|
this.itemReferencesObject = itemReferencesObject;
|
|
17
17
|
this.enumValues = enumValues;
|
|
18
|
+
this.inPlace = inPlace;
|
|
18
19
|
this.schemaType = 'property';
|
|
19
20
|
}
|
|
20
21
|
copy(p) {
|
|
21
|
-
return new Property(option(p.name).getOrElseValue(this.name), option(p.type).getOrElseValue(this.type), option(p.format).getOrElseValue(this.format), option(p.description).getOrElseValue(this.description), option(p.defaultValue).getOrElseValue(this.defaultValue), option(p.nullable).getOrElseValue(this.nullable), option(p.required).getOrElseValue(this.required), option(p.items).getOrElseValue(this.items), option(p.referencesObject).getOrElseValue(this.referencesObject), option(p.itemReferencesObject).getOrElseValue(this.itemReferencesObject), option(p.enumValues).getOrElseValue(this.enumValues));
|
|
22
|
+
return new Property(option(p.name).getOrElseValue(this.name), option(p.type).getOrElseValue(this.type), option(p.format).getOrElseValue(this.format), option(p.description).getOrElseValue(this.description), option(p.defaultValue).getOrElseValue(this.defaultValue), option(p.nullable).getOrElseValue(this.nullable), option(p.required).getOrElseValue(this.required), option(p.items).getOrElseValue(this.items), option(p.referencesObject).getOrElseValue(this.referencesObject), option(p.itemReferencesObject).getOrElseValue(this.itemReferencesObject), option(p.enumValues).getOrElseValue(this.enumValues), option(p.inPlace).getOrElseValue(this.inPlace));
|
|
22
23
|
}
|
|
23
|
-
static fromDefinition(name, definition, schemaTypes, options) {
|
|
24
|
+
static fromDefinition(parentClassname, name, definition, schemaTypes, options) {
|
|
24
25
|
const referencesObject = option(definition.$ref)
|
|
25
26
|
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object')) ||
|
|
26
27
|
option(definition.allOf)
|
|
@@ -31,7 +32,17 @@ export class Property {
|
|
|
31
32
|
const itemReferencesObject = option(definition.items)
|
|
32
33
|
.flatMap(i => option(i.$ref))
|
|
33
34
|
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
|
|
35
|
+
let inplace = none;
|
|
34
36
|
const type = option(definition.$ref).map(ref => ref.substring(SCHEMA_PREFIX.length))
|
|
37
|
+
.orElse(() => {
|
|
38
|
+
if (definition.type === 'object' && option(definition.properties).map(p => Object.keys(p).length).getOrElseValue(0) > 0) {
|
|
39
|
+
inplace = some(definition);
|
|
40
|
+
return some(parentClassname + '$' + name);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return none;
|
|
44
|
+
}
|
|
45
|
+
})
|
|
35
46
|
.orElse(() => option(definition.allOf)
|
|
36
47
|
.map(x => Collection.from(x))
|
|
37
48
|
.filter(x => x.nonEmpty)
|
|
@@ -85,7 +96,7 @@ export class Property {
|
|
|
85
96
|
.orElseValue(option(oneOfItem.type))).mkString(' | ')))
|
|
86
97
|
.getOrElseValue('any');
|
|
87
98
|
const enumValues = option(definition.enum).map(x => Collection.from(x));
|
|
88
|
-
return new Property(name, type, option(definition.format), description, null, nullable, required, items, referencesObject, itemReferencesObject, enumValues);
|
|
99
|
+
return new Property(name, type, option(definition.format), description, null, nullable, required, items, referencesObject, itemReferencesObject, enumValues, inplace);
|
|
89
100
|
}
|
|
90
101
|
get jsType() {
|
|
91
102
|
let res = Property.toJsType(this.type, this.items, this.format);
|
package/dist/schemas.js
CHANGED
|
@@ -33,35 +33,35 @@ export class SchemaFactory {
|
|
|
33
33
|
return SchemaEnum.fromDefinition(name, def);
|
|
34
34
|
}
|
|
35
35
|
else if (def.type === 'string') {
|
|
36
|
-
return Property.fromDefinition(name, {
|
|
36
|
+
return Property.fromDefinition('', name, {
|
|
37
37
|
...def,
|
|
38
38
|
required: option(def.required).filter(x => typeof x === 'boolean')
|
|
39
39
|
.map(x => x).orUndefined
|
|
40
40
|
}, schemasTypes, options);
|
|
41
41
|
}
|
|
42
42
|
else if (def.type === 'boolean') {
|
|
43
|
-
return Property.fromDefinition(name, {
|
|
43
|
+
return Property.fromDefinition('', name, {
|
|
44
44
|
...def,
|
|
45
45
|
required: option(def.required).filter(x => typeof x === 'boolean')
|
|
46
46
|
.map(x => x).orUndefined
|
|
47
47
|
}, schemasTypes, options);
|
|
48
48
|
}
|
|
49
49
|
else if (def.type === 'integer') {
|
|
50
|
-
return Property.fromDefinition(name, {
|
|
50
|
+
return Property.fromDefinition('', name, {
|
|
51
51
|
...def,
|
|
52
52
|
required: option(def.required).filter(x => typeof x === 'boolean')
|
|
53
53
|
.map(x => x).orUndefined
|
|
54
54
|
}, schemasTypes, options);
|
|
55
55
|
}
|
|
56
56
|
else if (def.type === 'array') {
|
|
57
|
-
return Property.fromDefinition(name, {
|
|
57
|
+
return Property.fromDefinition('', name, {
|
|
58
58
|
...def,
|
|
59
59
|
required: option(def.required).filter(x => typeof x === 'boolean')
|
|
60
60
|
.map(x => x).orUndefined
|
|
61
61
|
}, schemasTypes, options);
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
64
|
-
return Property.fromDefinition(name, {
|
|
64
|
+
return Property.fromDefinition('', name, {
|
|
65
65
|
...def,
|
|
66
66
|
required: option(def.required).filter(x => typeof x === 'boolean')
|
|
67
67
|
.map(x => x).orUndefined
|
|
@@ -141,7 +141,7 @@ export class SchemaObject {
|
|
|
141
141
|
.map(props => Collection.from(Object.keys(props)))
|
|
142
142
|
.getOrElseValue(Nil)
|
|
143
143
|
.map(propName => {
|
|
144
|
-
const property = Property.fromDefinition(propName, subSchema['properties'][propName], schemasTypes, options);
|
|
144
|
+
const property = Property.fromDefinition(name, propName, subSchema['properties'][propName], schemasTypes, options);
|
|
145
145
|
return property.copy({
|
|
146
146
|
required: explicitlyRequired.contains(propName) ? true : property.required
|
|
147
147
|
});
|