@devlearning/swagger-generator 0.0.32 → 0.0.34

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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ Add task on package.json
2
+
3
+ "swgen": "swgen http://localhost:5208/swagger/v1/swagger.json src/app/core/autogenerated"
4
+
5
+ specify url of your swagger.json and path destination of generated files (in this example you must create path core/autogenerated)
package/dist/generator.js CHANGED
@@ -19,9 +19,6 @@ export class Generator {
19
19
  const method = Object.getOwnPropertyNames(swaggerMethod)[0];
20
20
  const swaggerMethodInfo = swaggerMethod[method];
21
21
  console.debug(`\tAPI - ${apiName} - ${method}`);
22
- if (apiName == '/api/v{version}/TransportOrder/ListByServiceRequest') {
23
- console.debug('');
24
- }
25
22
  let parametersString = this.retrieveParameters(swaggerMethodInfo, apiName);
26
23
  let queryParametersDeclaration = this.retrieveQueryParametersDeclaration(swaggerMethodInfo);
27
24
  let queryParameters = this.retrieveQueryParameters(swaggerMethodInfo);
@@ -67,16 +64,18 @@ ${API_POST}`, { flag: 'w' });
67
64
  if (apiName == "/api/v{version}/TicketFile/Create") {
68
65
  debugger;
69
66
  }
70
- let parametersRefType = swaggerMethodInfo.parameters.filter(x => x.in == 'query' && x.schema?.$ref != null).map(x => x.schema.$ref.replace('#/components/schemas/', ''));
71
- usedTypes = usedTypes.concat(parametersRefType);
72
- if (swaggerMethodInfo.responses[200].content[contentTypeApplicationJson]?.schema.$ref != null) {
73
- usedTypes.push(swaggerMethodInfo.responses[200].content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', ''));
74
- }
75
- if (swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref) {
76
- usedTypes.push(swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref.replace('#/components/schemas/', ''));
77
- }
78
- if (swaggerMethodInfo.requestBody?.content[contentTypeMultipartFormData]?.schema != null) {
79
- usedMultiPart.push(apiName);
67
+ let parametersRefType = swaggerMethodInfo.parameters?.filter(x => x.in == 'query' && x.schema?.$ref != null).map(x => x.schema.$ref.replace('#/components/schemas/', ''));
68
+ if (parametersRefType) {
69
+ usedTypes = usedTypes.concat(parametersRefType);
70
+ if (swaggerMethodInfo.responses[200].content[contentTypeApplicationJson]?.schema.$ref != null) {
71
+ usedTypes.push(swaggerMethodInfo.responses[200].content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', ''));
72
+ }
73
+ if (swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref) {
74
+ usedTypes.push(swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref.replace('#/components/schemas/', ''));
75
+ }
76
+ if (swaggerMethodInfo.requestBody?.content[contentTypeMultipartFormData]?.schema != null) {
77
+ usedMultiPart.push(apiName);
78
+ }
80
79
  }
81
80
  }
82
81
  this.retrieveNestedObjects(usedTypes);
@@ -136,7 +135,7 @@ ${MODEL_POST}`, { flag: 'w' });
136
135
  return `request: Models.${swaggerMethodInfo.requestBody.content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', '')}`;
137
136
  }
138
137
  let parameters = ``;
139
- swaggerMethodInfo.parameters.filter(x => x.in == 'query').forEach(parameter => {
138
+ swaggerMethodInfo.parameters?.filter(x => x.in == 'query').forEach(parameter => {
140
139
  if (parameter.schema.$ref != null) {
141
140
  parameters += `${this.toFirstLetterLowercase(parameter.name)}: Models.${parameter.schema.$ref.replace('#/components/schemas/', '')}, `;
142
141
  }
@@ -154,7 +153,7 @@ ${MODEL_POST}`, { flag: 'w' });
154
153
  retrieveQueryParametersDeclaration(swaggerMethodInfo) {
155
154
  if (swaggerMethodInfo.requestBody != null)
156
155
  return ``;
157
- let filteredParameters = swaggerMethodInfo.parameters.filter(x => x.in == 'query');
156
+ let filteredParameters = swaggerMethodInfo.parameters?.filter(x => x.in == 'query');
158
157
  if (filteredParameters.length == 0)
159
158
  return ``;
160
159
  let parameters = ``;
@@ -201,7 +200,7 @@ ${MODEL_POST}`, { flag: 'w' });
201
200
  retrieveQueryParameters(swaggerMethodInfo) {
202
201
  if (swaggerMethodInfo.requestBody != null)
203
202
  return ``;
204
- let filteredParameters = swaggerMethodInfo.parameters.filter(x => x.in == 'query');
203
+ let filteredParameters = swaggerMethodInfo.parameters?.filter(x => x.in == 'query');
205
204
  if (filteredParameters.length == 0)
206
205
  return ``;
207
206
  let parameters = `?`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devlearning/swagger-generator",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -14,9 +14,12 @@
14
14
  "keywords": [],
15
15
  "author": "",
16
16
  "license": "ISC",
17
+ "dependencies": {
18
+ "node-fetch": "^3.3.2"
19
+ },
20
+ "node-fetch": "^3.3.2",
17
21
  "devDependencies": {
18
22
  "@types/node": "^18.15.0",
19
- "node-fetch": "^3.3.2",
20
23
  "ts-node": "^10.9.1",
21
24
  "tsconfig-paths": "^4.2.0",
22
25
  "typescript": "^5.1.6"
package/src/generator.ts CHANGED
@@ -30,10 +30,6 @@ export class Generator {
30
30
  const swaggerMethodInfo = swaggerMethod[method];
31
31
  console.debug(`\tAPI - ${apiName} - ${method}`);
32
32
 
33
- if (apiName == '/api/v{version}/TransportOrder/ListByServiceRequest') {
34
- console.debug('');
35
- }
36
-
37
33
  let parametersString = this.retrieveParameters(swaggerMethodInfo, apiName);
38
34
  let queryParametersDeclaration = this.retrieveQueryParametersDeclaration(swaggerMethodInfo);
39
35
  let queryParameters = this.retrieveQueryParameters(swaggerMethodInfo);
@@ -82,22 +78,25 @@ ${API_POST}`,
82
78
  const method = Object.getOwnPropertyNames(swaggerMethod)[0];
83
79
  const swaggerMethodInfo = swaggerMethod[method];
84
80
 
85
- if(apiName == "/api/v{version}/TicketFile/Create"){
86
- debugger
81
+ if (apiName == "/api/v{version}/TicketFile/Create") {
82
+ debugger
87
83
  }
88
- let parametersRefType = swaggerMethodInfo.parameters.filter(x => x.in == 'query' && x.schema?.$ref != null).map(x => x.schema.$ref.replace('#/components/schemas/', ''))
89
- usedTypes = usedTypes.concat(parametersRefType);
90
84
 
91
- if (swaggerMethodInfo.responses[200].content[contentTypeApplicationJson]?.schema.$ref != null) {
92
- usedTypes.push(swaggerMethodInfo.responses[200].content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', ''));
93
- }
85
+ let parametersRefType = swaggerMethodInfo.parameters?.filter(x => x.in == 'query' && x.schema?.$ref != null).map(x => x.schema.$ref.replace('#/components/schemas/', ''))
86
+ if (parametersRefType) {
87
+ usedTypes = usedTypes.concat(parametersRefType);
94
88
 
95
- if (swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref) {
96
- usedTypes.push(swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref.replace('#/components/schemas/', ''));
97
- }
89
+ if (swaggerMethodInfo.responses[200].content[contentTypeApplicationJson]?.schema.$ref != null) {
90
+ usedTypes.push(swaggerMethodInfo.responses[200].content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', ''));
91
+ }
92
+
93
+ if (swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref) {
94
+ usedTypes.push(swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref.replace('#/components/schemas/', ''));
95
+ }
98
96
 
99
- if (swaggerMethodInfo.requestBody?.content[contentTypeMultipartFormData]?.schema != null) {
100
- usedMultiPart.push(apiName);
97
+ if (swaggerMethodInfo.requestBody?.content[contentTypeMultipartFormData]?.schema != null) {
98
+ usedMultiPart.push(apiName);
99
+ }
101
100
  }
102
101
  }
103
102
 
@@ -172,7 +171,7 @@ ${MODEL_POST}`,
172
171
  }
173
172
 
174
173
  let parameters = ``;
175
- swaggerMethodInfo.parameters.filter(x => x.in == 'query').forEach(parameter => {
174
+ swaggerMethodInfo.parameters?.filter(x => x.in == 'query').forEach(parameter => {
176
175
  if (parameter.schema.$ref != null) {
177
176
  parameters += `${this.toFirstLetterLowercase(parameter.name)}: Models.${parameter.schema.$ref.replace('#/components/schemas/', '')}, `;
178
177
  } else {
@@ -192,7 +191,7 @@ ${MODEL_POST}`,
192
191
  retrieveQueryParametersDeclaration(swaggerMethodInfo: SwaggerMethod) {
193
192
  if (swaggerMethodInfo.requestBody != null) return ``;
194
193
 
195
- let filteredParameters = swaggerMethodInfo.parameters.filter(x => x.in == 'query');
194
+ let filteredParameters = swaggerMethodInfo.parameters?.filter(x => x.in == 'query');
196
195
  if (filteredParameters.length == 0) return ``;
197
196
 
198
197
  let parameters = ``;
@@ -238,7 +237,7 @@ ${MODEL_POST}`,
238
237
  retrieveQueryParameters(swaggerMethodInfo: SwaggerMethod) {
239
238
  if (swaggerMethodInfo.requestBody != null) return ``;
240
239
 
241
- let filteredParameters = swaggerMethodInfo.parameters.filter(x => x.in == 'query');
240
+ let filteredParameters = swaggerMethodInfo.parameters?.filter(x => x.in == 'query');
242
241
  if (filteredParameters.length == 0) return ``;
243
242
 
244
243
  let parameters = `?`;