@penkov/swagger-code-gen 1.9.1 → 1.9.3

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.
@@ -89,7 +89,8 @@ export function resolvePaths(json, schemasTypes, options, pool) {
89
89
  });
90
90
  }
91
91
  export function generateInPlace(paths, schemasTypes, options, pool) {
92
- return paths.filter(m => option(m.response.inPlace).isDefined)
92
+ const res = new mutable.ArrayBuffer();
93
+ res.appendAll(paths.filter(m => option(m.response.inPlace).isDefined)
93
94
  .map(m => {
94
95
  return SchemaObject.fromDefinition(m.response.responseType, m.response.inPlace, schemasTypes, options, pool);
95
96
  }).appendedAll(paths.flatMap(m => m.body)
@@ -97,5 +98,14 @@ export function generateInPlace(paths, schemasTypes, options, pool) {
97
98
  .map(m => {
98
99
  console.log(`Generating inplace body: ${m.inPlaceClassname}`);
99
100
  return SchemaObject.fromDefinition(m.inPlaceClassname, m.inPlace, schemasTypes, options, pool);
100
- }));
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;
101
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
@@ -82,6 +82,9 @@ export class SchemaEnum {
82
82
  static fromDefinition(name, def) {
83
83
  return new SchemaEnum(name, def.title, option(def.description), def.type, option(def.default), option(def.enum).map(Collection.from).getOrElseValue(Nil));
84
84
  }
85
+ get normalName() {
86
+ return NameUtils.normaliseClassname(this.name);
87
+ }
85
88
  }
86
89
  export class SchemaObject {
87
90
  constructor(name, title, type, properties, parents, explicitlyRequiredProperties) {
@@ -141,7 +144,7 @@ export class SchemaObject {
141
144
  .map(props => Collection.from(Object.keys(props)))
142
145
  .getOrElseValue(Nil)
143
146
  .map(propName => {
144
- const property = Property.fromDefinition(propName, subSchema['properties'][propName], schemasTypes, options);
147
+ const property = Property.fromDefinition(name, propName, subSchema['properties'][propName], schemasTypes, options);
145
148
  return property.copy({
146
149
  required: explicitlyRequired.contains(propName) ? true : property.required
147
150
  });
@@ -15,7 +15,7 @@ export interface <%= schema.normalName %><%= schema.parentsString%> {
15
15
  * <%= d %>
16
16
  */
17
17
  <%_ }); -%>
18
- export enum <%= schema.name %> {
18
+ export enum <%= schema.normalName %> {
19
19
  <%_ schema.values.foreach(p => { -%>
20
20
  <%= p %> = '<%= p %>',
21
21
  <%_ }); -%>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "./dist/cli.mjs"