Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit de1747d

Browse files
author
Dom Harrington
committed
Prettier
1 parent ad6cda5 commit de1747d

File tree

5 files changed

+83
-57
lines changed

5 files changed

+83
-57
lines changed

packages/api-explorer/__tests__/lib/get-schema.test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ test('should return if theres a $ref on the top level', () => {
4848

4949
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#requestBodyObject
5050
test('should look up the schema if it looks like the first $ref is a request body object', () => {
51-
const $ref = '#/components/schemas/schema'
51+
const $ref = '#/components/schemas/schema';
5252
expect(
5353
getSchema(
5454
{
5555
requestBody: { $ref: '#/components/requestBodies/schema' },
5656
},
57-
{ components: { requestBodies: { schema: { content: { 'application/json': { schema: { $ref } } } } } } },
57+
{
58+
components: {
59+
requestBodies: { schema: { content: { 'application/json': { schema: { $ref } } } } },
60+
},
61+
},
5862
).schema.$ref,
5963
).toEqual($ref);
6064
});
@@ -65,7 +69,9 @@ test('should return the inline schema from request body object', () => {
6569
{
6670
requestBody: { $ref: '#/components/requestBodies/schema' },
6771
},
68-
{ components: { requestBodies: { schema: { content: { 'application/json': { schema } } } } } },
72+
{
73+
components: { requestBodies: { schema: { content: { 'application/json': { schema } } } } },
74+
},
6975
).schema,
7076
).toEqual(schema);
7177
});

packages/api-explorer/__tests__/lib/parameters-to-json-schema.test.js

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,22 @@ test('it should return with a json schema for each parameter type', () => {
7676

7777
test('it should work for request body inline (json)', () => {
7878
expect(
79-
parametersToJsonSchema({
80-
requestBody: {
81-
description: 'Body description',
82-
content: {
83-
'application/json': {
84-
schema: {
85-
type: 'object',
86-
properties: { a: { type: 'string' } },
79+
parametersToJsonSchema(
80+
{
81+
requestBody: {
82+
description: 'Body description',
83+
content: {
84+
'application/json': {
85+
schema: {
86+
type: 'object',
87+
properties: { a: { type: 'string' } },
88+
},
8789
},
8890
},
8991
},
9092
},
91-
}, {}),
93+
{},
94+
),
9295
).toEqual([
9396
{
9497
label: 'Body Params',
@@ -105,19 +108,22 @@ test('it should work for request body inline (json)', () => {
105108

106109
test('it should work for request body inline (formData)', () => {
107110
expect(
108-
parametersToJsonSchema({
109-
requestBody: {
110-
description: 'Form data description',
111-
content: {
112-
'application/x-www-form-urlencoded': {
113-
schema: {
114-
type: 'object',
115-
properties: { a: { type: 'string' } },
111+
parametersToJsonSchema(
112+
{
113+
requestBody: {
114+
description: 'Form data description',
115+
content: {
116+
'application/x-www-form-urlencoded': {
117+
schema: {
118+
type: 'object',
119+
properties: { a: { type: 'string' } },
120+
},
116121
},
117122
},
118123
},
119124
},
120-
}, {}),
125+
{},
126+
),
121127
).toEqual([
122128
{
123129
label: 'Form Data',
@@ -280,22 +286,24 @@ test('it should work for top-level request body $ref', () => {
280286
},
281287
},
282288
),
283-
).toEqual([{
284-
type: 'body',
285-
label: 'Body Params',
286-
schema: {
287-
$ref: '#/components/schemas/Pet',
288-
definitions: {
289-
components: {
290-
schemas: {
291-
Pet: {
292-
type: 'string',
289+
).toEqual([
290+
{
291+
type: 'body',
292+
label: 'Body Params',
293+
schema: {
294+
$ref: '#/components/schemas/Pet',
295+
definitions: {
296+
components: {
297+
schemas: {
298+
Pet: {
299+
type: 'string',
300+
},
293301
},
294302
},
295303
},
296304
},
297-
}
298-
}]);
305+
},
306+
]);
299307
});
300308

301309
test('it should pull out schemas from `components/requestBodies`', () => {
@@ -306,35 +314,40 @@ test('it should pull out schemas from `components/requestBodies`', () => {
306314
content: {
307315
'application/json': {
308316
schema: {
309-
$ref: '#/components/schemas/Pet'
310-
}
311-
}
312-
}
317+
$ref: '#/components/schemas/Pet',
318+
},
319+
},
320+
},
313321
},
314322
},
315323
schemas: {
316324
Pet: {
317325
type: 'string',
318-
}
319-
}
326+
},
327+
},
320328
},
321329
};
322330
expect(
323-
parametersToJsonSchema({
324-
requestBody: {
325-
$ref: '#/components/requestBodies/Pet',
331+
parametersToJsonSchema(
332+
{
333+
requestBody: {
334+
$ref: '#/components/requestBodies/Pet',
335+
},
326336
},
327-
}, oas),
328-
).toEqual([{
329-
type: 'body',
330-
label: 'Body Params',
331-
schema: {
332-
$ref: '#/components/schemas/Pet',
333-
definitions: {
334-
components: oas.components,
337+
oas,
338+
),
339+
).toEqual([
340+
{
341+
type: 'body',
342+
label: 'Body Params',
343+
schema: {
344+
$ref: '#/components/schemas/Pet',
345+
definitions: {
346+
components: oas.components,
347+
},
335348
},
336-
}
337-
}]);
349+
},
350+
]);
338351
});
339352

340353
test('it should make things required correctly');

packages/api-explorer/src/lib/find-schema-definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function findSchemaDefinition($ref, definitions = {}) {
1313
// Extract and use the referenced definition if we have it.
1414
const match = /^#\/(.*)$/.exec($ref);
1515
if (match && match[0]) {
16-
const parts = match[1].split("/");
16+
const parts = match[1].split('/');
1717
let current = definitions;
1818

1919
parts.forEach(part => {

packages/api-explorer/src/lib/get-schema.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ module.exports = function getSchema(pathOperation, oas) {
1111
return { type, schema: pathOperation.requestBody.content[type].schema };
1212
}
1313

14-
if (pathOperation.requestBody && pathOperation.requestBody.$ref.match(/^#\/components\/requestBodies\/.*$/)) {
14+
if (
15+
pathOperation.requestBody &&
16+
pathOperation.requestBody.$ref.match(/^#\/components\/requestBodies\/.*$/)
17+
) {
1518
return getSchema({ requestBody: findSchemaDefinition(pathOperation.requestBody.$ref, oas) });
1619
}
1720

18-
return { type: 'application/json', schema: pathOperation.requestBody }
21+
return { type: 'application/json', schema: pathOperation.requestBody };
1922
} catch (e) {} // eslint-disable-line no-empty
2023

2124
return undefined;

packages/api-explorer/src/lib/parameters-to-json-schema.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ function getBodyParam(pathOperation, oas) {
2020
return {
2121
type,
2222
label: types[type],
23-
schema: oas.components ? { definitions: { components: oas.components }, ...schema.schema } : schema.schema,
23+
schema: oas.components
24+
? { definitions: { components: oas.components }, ...schema.schema }
25+
: schema.schema,
2426
};
2527
}
2628

@@ -74,7 +76,9 @@ module.exports = (pathOperation, oas) => {
7476

7577
if (!hasParameters && !hasRequestBody) return null;
7678

77-
return [getBodyParam(pathOperation, oas)].concat(...getOtherParams(pathOperation)).filter(Boolean);
79+
return [getBodyParam(pathOperation, oas)]
80+
.concat(...getOtherParams(pathOperation))
81+
.filter(Boolean);
7882
};
7983

8084
// Exported for use in oas-to-har for default values object

0 commit comments

Comments
 (0)