@penkov/swagger-code-gen 1.8.0 → 1.8.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/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, schemas, options) {
22
+ static fromDefinition(name, definition, schemaTypes, options) {
23
23
  const referencesObject = option(definition.$ref)
24
- .exists(ref => schemas.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
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 => schemas.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
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)
@@ -95,6 +95,8 @@ export class Property {
95
95
  }
96
96
  static toJsType(tpe, itemTpe = 'any', format = none) {
97
97
  switch (tpe) {
98
+ case 'boolean': return 'boolean';
99
+ case 'number': return 'number';
98
100
  case 'integer': return 'number';
99
101
  case 'file': return 'File';
100
102
  case 'any': return 'any';
@@ -109,10 +111,14 @@ export class Property {
109
111
  default: return NameUtils.normaliseClassname(tpe);
110
112
  }
111
113
  }
114
+ get normalType() {
115
+ return NameUtils.normaliseClassname(this.type);
116
+ }
112
117
  get itemScatsWrapperType() {
113
118
  if (this.isArray) {
114
119
  if (this.itemReferencesObject) {
115
- return `${this.items}Dto`;
120
+ const cls = NameUtils.normaliseClassname(this.items);
121
+ return `${cls}Dto`;
116
122
  }
117
123
  else {
118
124
  return Property.toJsType(this.items);
@@ -124,11 +130,13 @@ export class Property {
124
130
  }
125
131
  get scatsWrapperType() {
126
132
  if (this.referencesObject) {
127
- return !this.nullable && this.required ? `${this.type}Dto` : `Option<${this.type}Dto>`;
133
+ const cls = NameUtils.normaliseClassname(this.type);
134
+ return !this.nullable && this.required ? `${cls}Dto` : `Option<${cls}Dto>`;
128
135
  }
129
136
  else if (this.isArray) {
130
137
  if (this.itemReferencesObject) {
131
- return `Collection<${this.items}Dto>`;
138
+ const cls = NameUtils.normaliseClassname(this.items);
139
+ return `Collection<${cls}Dto>`;
132
140
  }
133
141
  else {
134
142
  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.type %>Dto.fromJson(_)),
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([]))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "./dist/cli.mjs"