oas 20.10.0 → 20.10.1

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.
@@ -169,28 +169,12 @@ function getParametersAsJSONSchema(operation, api, opts) {
169
169
  if (!('components' in api)) {
170
170
  return false;
171
171
  }
172
- var components = {
173
- /**
174
- * Initializing an empty `components[componentType] = {}` object within the `forEach` below
175
- * is incredibly slow because each of these component types has a wide variety of shapes. So
176
- * in order to not have TS compilation times that takes literally **seconds** because of a
177
- * single line we're instead opting to prefill this object with some empty placeholders that
178
- * we'll later remove if they didn't get used.
179
- *
180
- * Obviously not ideal but I'd rather have a couple lines of boilerplate nonsense than having
181
- * to wait a noticeably frustrating amount of time for TS Intellisense to reload itself after
182
- * you save a line in any file.
183
- */
184
- examples: {},
185
- schemas: {},
186
- responses: {},
187
- parameters: {},
188
- requestBodies: {},
189
- headers: {},
190
- securitySchemes: {},
191
- links: {},
192
- callbacks: {},
193
- };
172
+ var components = __assign({}, Object.keys(api.components)
173
+ .map(function (componentType) {
174
+ var _a;
175
+ return (_a = {}, _a[componentType] = {}, _a);
176
+ })
177
+ .reduce(function (prev, next) { return Object.assign(prev, next); }, {}));
194
178
  Object.keys(api.components).forEach(function (componentType) {
195
179
  if (typeof api.components[componentType] === 'object' && !Array.isArray(api.components[componentType])) {
196
180
  Object.keys(api.components[componentType]).forEach(function (schemaName) {
@@ -206,17 +190,7 @@ function getParametersAsJSONSchema(operation, api, opts) {
206
190
  }
207
191
  });
208
192
  // If none of our above component type placeholders got used let's clean them up.
209
- [
210
- 'examples',
211
- 'schemas',
212
- 'responses',
213
- 'parameters',
214
- 'requestBodies',
215
- 'headers',
216
- 'securitySchemes',
217
- 'links',
218
- 'callbacks',
219
- ].forEach(function (componentType) {
193
+ Object.keys(components).forEach(function (componentType) {
220
194
  if (!Object.keys(components[componentType]).length) {
221
195
  delete components[componentType];
222
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "20.10.0",
3
+ "version": "20.10.1",
4
4
  "description": "Comprehensive tooling for working with OpenAPI definitions",
5
5
  "license": "MIT",
6
6
  "author": "ReadMe <support@readme.io> (https://readme.com)",
@@ -220,26 +220,9 @@ export default function getParametersAsJSONSchema(
220
220
  }
221
221
 
222
222
  const components: Partial<ComponentsObject> = {
223
- /**
224
- * Initializing an empty `components[componentType] = {}` object within the `forEach` below
225
- * is incredibly slow because each of these component types has a wide variety of shapes. So
226
- * in order to not have TS compilation times that takes literally **seconds** because of a
227
- * single line we're instead opting to prefill this object with some empty placeholders that
228
- * we'll later remove if they didn't get used.
229
- *
230
- * Obviously not ideal but I'd rather have a couple lines of boilerplate nonsense than having
231
- * to wait a noticeably frustrating amount of time for TS Intellisense to reload itself after
232
- * you save a line in any file.
233
- */
234
- examples: {},
235
- schemas: {},
236
- responses: {},
237
- parameters: {},
238
- requestBodies: {},
239
- headers: {},
240
- securitySchemes: {},
241
- links: {},
242
- callbacks: {},
223
+ ...Object.keys(api.components)
224
+ .map(componentType => ({ [componentType]: {} }))
225
+ .reduce((prev, next) => Object.assign(prev, next), {}),
243
226
  };
244
227
 
245
228
  Object.keys(api.components).forEach((componentType: keyof ComponentsObject) => {
@@ -258,17 +241,7 @@ export default function getParametersAsJSONSchema(
258
241
  });
259
242
 
260
243
  // If none of our above component type placeholders got used let's clean them up.
261
- [
262
- 'examples',
263
- 'schemas',
264
- 'responses',
265
- 'parameters',
266
- 'requestBodies',
267
- 'headers',
268
- 'securitySchemes',
269
- 'links',
270
- 'callbacks',
271
- ].forEach((componentType: keyof ComponentsObject) => {
244
+ Object.keys(components).forEach((componentType: keyof ComponentsObject) => {
272
245
  if (!Object.keys(components[componentType]).length) {
273
246
  delete components[componentType];
274
247
  }