@penkov/swagger-code-gen 1.8.0 → 1.8.1
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/property.js +12 -6
- package/dist/schemas.js +1 -1
- package/dist/templates/scats-schema.ejs +1 -1
- package/package.json +1 -1
package/dist/property.js
CHANGED
|
@@ -19,12 +19,12 @@ export class Property {
|
|
|
19
19
|
copy(p) {
|
|
20
20
|
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));
|
|
21
21
|
}
|
|
22
|
-
static fromDefinition(name, definition,
|
|
22
|
+
static fromDefinition(name, definition, schemaTypes, options) {
|
|
23
23
|
const referencesObject = option(definition.$ref)
|
|
24
|
-
.exists(ref =>
|
|
24
|
+
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
|
|
25
25
|
const itemReferencesObject = option(definition.items)
|
|
26
26
|
.flatMap(i => option(i.$ref))
|
|
27
|
-
.exists(ref =>
|
|
27
|
+
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
|
|
28
28
|
const type = option(definition.$ref)
|
|
29
29
|
.map(ref => ref.substring(SCHEMA_PREFIX.length))
|
|
30
30
|
.orElse(() => option(definition.allOf)
|
|
@@ -109,10 +109,14 @@ export class Property {
|
|
|
109
109
|
default: return NameUtils.normaliseClassname(tpe);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
+
get normalType() {
|
|
113
|
+
return NameUtils.normaliseClassname(this.type);
|
|
114
|
+
}
|
|
112
115
|
get itemScatsWrapperType() {
|
|
113
116
|
if (this.isArray) {
|
|
114
117
|
if (this.itemReferencesObject) {
|
|
115
|
-
|
|
118
|
+
const cls = NameUtils.normaliseClassname(this.items);
|
|
119
|
+
return `${cls}Dto`;
|
|
116
120
|
}
|
|
117
121
|
else {
|
|
118
122
|
return Property.toJsType(this.items);
|
|
@@ -124,11 +128,13 @@ export class Property {
|
|
|
124
128
|
}
|
|
125
129
|
get scatsWrapperType() {
|
|
126
130
|
if (this.referencesObject) {
|
|
127
|
-
|
|
131
|
+
const cls = NameUtils.normaliseClassname(this.type);
|
|
132
|
+
return !this.nullable && this.required ? `${cls}Dto` : `Option<${cls}Dto>`;
|
|
128
133
|
}
|
|
129
134
|
else if (this.isArray) {
|
|
130
135
|
if (this.itemReferencesObject) {
|
|
131
|
-
|
|
136
|
+
const cls = NameUtils.normaliseClassname(this.items);
|
|
137
|
+
return `Collection<${cls}Dto>`;
|
|
132
138
|
}
|
|
133
139
|
else {
|
|
134
140
|
return `Collection<${Property.toJsType(this.items)}>`;
|
package/dist/schemas.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Property } from './property.js';
|
|
|
3
3
|
import { NameUtils } from './name.utils.js';
|
|
4
4
|
export class SchemaFactory {
|
|
5
5
|
static resolveSchemaType(def) {
|
|
6
|
-
if (def.type === 'object') {
|
|
6
|
+
if (def.type === 'object' || option(def.properties).exists(p => Object.keys(p).length > 0)) {
|
|
7
7
|
return 'object';
|
|
8
8
|
}
|
|
9
9
|
else if (def.enum) {
|
|
@@ -15,7 +15,7 @@ export class <%= schema.normalName %>Dto {
|
|
|
15
15
|
<%_ if (p.required && !p.nullable) { _%>
|
|
16
16
|
<%- p.scatsWrapperType %>.fromJson(json.<%= p.name %>),
|
|
17
17
|
<%_ } else { _%>
|
|
18
|
-
option(json.<%= p.name %>).map(_ => <%- p.
|
|
18
|
+
option(json.<%= p.name %>).map(_ => <%- p.normalType %>Dto.fromJson(_)),
|
|
19
19
|
<%_ } _%>
|
|
20
20
|
<%_ } else if (p.isArray) { _%>
|
|
21
21
|
Collection.from(option(json.<%= p.name %>).getOrElseValue([]))
|