@penkov/swagger-code-gen 1.8.2 → 1.8.4

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.
@@ -22,7 +22,7 @@ export class NameUtils {
22
22
  return `$${n}`;
23
23
  }
24
24
  else {
25
- return n;
25
+ return n.replace(/\./g, '_');
26
26
  }
27
27
  }
28
28
  }
package/dist/parameter.js CHANGED
@@ -3,8 +3,9 @@ import { Collection, identity, none, option } from 'scats';
3
3
  import { Method } from './method.js';
4
4
  import { Property } from './property.js';
5
5
  export class Parameter {
6
- constructor(name, uniqueName, inValue, jsType, required, isArray, defaultValue, description) {
6
+ constructor(name, rawName, uniqueName, inValue, jsType, required, isArray, defaultValue, description) {
7
7
  this.name = name;
8
+ this.rawName = rawName;
8
9
  this.uniqueName = uniqueName;
9
10
  this.inValue = inValue;
10
11
  this.jsType = jsType;
@@ -16,10 +17,18 @@ export class Parameter {
16
17
  }
17
18
  static fromDefinition(def, schemas, options) {
18
19
  const name = Parameter.toJSName(def.name);
20
+ const rawName = def.name;
19
21
  const inValue = def.in;
20
22
  const desc = option(def.description);
21
23
  let defaultValue = none;
22
- const schema = SchemaFactory.build(def.name, def.schema, schemas, options);
24
+ const schema = def.schema ?
25
+ SchemaFactory.build(def.name, def.schema, schemas, options) :
26
+ Property.fromDefinition(name, {
27
+ ...def,
28
+ type: def['type'],
29
+ required: option(def.required).filter(x => typeof x === 'boolean')
30
+ .map(x => x).orUndefined
31
+ }, schemas, options);
23
32
  let jsType;
24
33
  if (schema instanceof SchemaObject) {
25
34
  jsType = schema.type;
@@ -53,8 +62,8 @@ export class Parameter {
53
62
  throw new Error('Unknown schema type');
54
63
  }
55
64
  const required = option(def.required).exists(identity) || defaultValue.nonEmpty;
56
- const isArray = def.schema.type === 'array';
57
- return new Parameter(name, name, inValue, jsType, required, isArray, defaultValue, desc);
65
+ const isArray = def?.schema?.type === 'array';
66
+ return new Parameter(name, rawName, name, inValue, jsType, required, isArray, defaultValue, desc);
58
67
  }
59
68
  static toJSName(path) {
60
69
  const tokens = Collection.from(path.split(/\W/)).filter(t => t.length > 0);
@@ -63,6 +72,6 @@ export class Parameter {
63
72
  }).mkString();
64
73
  }
65
74
  copy(p) {
66
- return new Parameter(option(p.name).getOrElseValue(this.name), option(p.uniqueName).getOrElseValue(this.uniqueName), option(p.in).getOrElseValue(this.in), option(p.jsType).getOrElseValue(this.jsType), option(p.required).getOrElseValue(this.required), option(p.isArray).getOrElseValue(this.isArray), option(p.defaultValue).getOrElseValue(this.defaultValue), option(p.description).getOrElseValue(this.description));
75
+ return new Parameter(option(p.name).getOrElseValue(this.name), option(p.rawName).getOrElseValue(this.rawName), option(p.uniqueName).getOrElseValue(this.uniqueName), option(p.in).getOrElseValue(this.in), option(p.jsType).getOrElseValue(this.jsType), option(p.required).getOrElseValue(this.required), option(p.isArray).getOrElseValue(this.isArray), option(p.defaultValue).getOrElseValue(this.defaultValue), option(p.description).getOrElseValue(this.description));
67
76
  }
68
77
  }
@@ -82,7 +82,7 @@ export async function <%= method.endpointName %><%= body.map(b => b.suffix).getO
82
82
  <%_ } -%>
83
83
  <%_ if (method.parameters.filter(x => x.in === 'header').nonEmpty) { -%>
84
84
  <%_ method.parameters.filter(x => x.in === 'header').foreach(p => { -%>
85
- <%= p.name %>: <%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %>,
85
+ '<%= p.rawName %>': <%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %>,
86
86
  <%_ }) -%>
87
87
  <%_ } -%>
88
88
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.8.2",
3
+ "version": "1.8.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "./dist/cli.mjs"