@penkov/swagger-code-gen 1.6.6 → 1.6.8

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
@@ -30,9 +30,23 @@ export class Property {
30
30
  .map(x => x.flatMapOption(oneOfItem => option(oneOfItem.$ref)
31
31
  .map(ref => ref.substring(SCHEMA_PREFIX.length))
32
32
  .orElseValue(option(oneOfItem.type))).mkString(' & ')))
33
+ .orElse(() => option(definition.anyOf)
34
+ .map(x => Collection.from(x))
35
+ .filter(x => x.nonEmpty)
36
+ .map(x => {
37
+ return x
38
+ .filter(t => t.type !== 'null')
39
+ .flatMapOption(oneOfItem => option(oneOfItem.$ref)
40
+ .map(ref => ref.substring(SCHEMA_PREFIX.length))
41
+ .orElseValue(option(oneOfItem.type))).mkString(' | ');
42
+ }))
33
43
  .getOrElseValue(definition.type);
34
44
  const nullable = option(definition.nullable).contains(true) ||
35
- (referencesObject && options.referencedObjectsNullableByDefault && !option(definition.nullable).contains(false));
45
+ (referencesObject && options.referencedObjectsNullableByDefault && !option(definition.nullable).contains(false)) ||
46
+ option(definition.anyOf)
47
+ .map(x => Collection.from(x))
48
+ .filter(x => x.nonEmpty)
49
+ .exists(anyOf => anyOf.exists(t => t.type === 'null'));
36
50
  const description = option(definition.description);
37
51
  const required = option(definition.required).contains(true);
38
52
  const items = option(definition.items?.$ref)
@@ -50,7 +64,7 @@ export class Property {
50
64
  get jsType() {
51
65
  let res = Property.toJsType(this.type, this.items);
52
66
  if (this.nullable) {
53
- res = res + '| null';
67
+ res = res + ' | null';
54
68
  }
55
69
  return res;
56
70
  }
@@ -90,7 +104,8 @@ export class Property {
90
104
  }
91
105
  }
92
106
  else {
93
- return !this.nullable && this.required ? this.jsType : `Option<${this.jsType}>`;
107
+ const jsType = Property.toJsType(this.type, this.items);
108
+ return !this.nullable && this.required ? this.jsType : `Option<${jsType}>`;
94
109
  }
95
110
  }
96
111
  }
package/dist/schemas.js CHANGED
@@ -20,19 +20,39 @@ export class SchemaFactory {
20
20
  return SchemaEnum.fromDefinition(name, def);
21
21
  }
22
22
  else if (def.type === 'string') {
23
- return Property.fromDefinition(name, def, schemasTypes, options);
23
+ return Property.fromDefinition(name, {
24
+ ...def,
25
+ required: option(def.required).filter(x => typeof x === 'boolean')
26
+ .map(x => x).orUndefined
27
+ }, schemasTypes, options);
24
28
  }
25
29
  else if (def.type === 'boolean') {
26
- return Property.fromDefinition(name, def, schemasTypes, options);
30
+ return Property.fromDefinition(name, {
31
+ ...def,
32
+ required: option(def.required).filter(x => typeof x === 'boolean')
33
+ .map(x => x).orUndefined
34
+ }, schemasTypes, options);
27
35
  }
28
36
  else if (def.type === 'integer') {
29
- return Property.fromDefinition(name, def, schemasTypes, options);
37
+ return Property.fromDefinition(name, {
38
+ ...def,
39
+ required: option(def.required).filter(x => typeof x === 'boolean')
40
+ .map(x => x).orUndefined
41
+ }, schemasTypes, options);
30
42
  }
31
43
  else if (def.type === 'array') {
32
- return Property.fromDefinition(name, def, schemasTypes, options);
44
+ return Property.fromDefinition(name, {
45
+ ...def,
46
+ required: option(def.required).filter(x => typeof x === 'boolean')
47
+ .map(x => x).orUndefined
48
+ }, schemasTypes, options);
33
49
  }
34
50
  else {
35
- return Property.fromDefinition(name, def, schemasTypes, options);
51
+ return Property.fromDefinition(name, {
52
+ ...def,
53
+ required: option(def.required).filter(x => typeof x === 'boolean')
54
+ .map(x => x).orUndefined
55
+ }, schemasTypes, options);
36
56
  }
37
57
  }
38
58
  }
@@ -58,7 +78,14 @@ export class SchemaObject {
58
78
  this.schemaType = 'object';
59
79
  }
60
80
  static fromDefinition(name, def, schemasTypes, options) {
61
- const properties = Collection.from(Object.keys(def.properties)).map(p => Property.fromDefinition(p, def.properties[p], schemasTypes, options));
81
+ const explicitlyRequired = option(def.required)
82
+ .map(arr => typeof arr === 'boolean' ? Nil : Collection.from(arr));
83
+ const properties = Collection.from(Object.keys(def.properties)).map(propName => {
84
+ const property = Property.fromDefinition(propName, def.properties[propName], schemasTypes, options);
85
+ return property.copy({
86
+ required: explicitlyRequired.exists(c => c.contains(propName)) ? true : property.required
87
+ });
88
+ });
62
89
  return new SchemaObject(name, def.title, def.type, properties);
63
90
  }
64
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.6.6",
3
+ "version": "1.6.8",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "./dist/cli.mjs"