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

Commit

Permalink
fix: allow to pass non-undefined values(#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolodya committed Oct 18, 2018
1 parent d2df77e commit b70fb90
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/api-explorer/__tests__/lib/oas-to-har.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ describe('path values', () => {
).log.entries[0].request.url,
).toBe('https://example.com/param-path/456');
});

test('should add non-undefined values to the url', () => {
expect(
oasToHar(
{},
{
path: '/param-path/{id}',
method: 'get',
parameters: [
{
name: 'id',
in: 'path',
required: true,
},
],
},
{ path: { id: 0 } },
).log.entries[0].request.url,
).toBe('https://example.com/param-path/0');
});
});

describe('query values', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,20 @@ test('it should pull out schemas from `components/requestBodies`', () => {
});

test.skip('it should make things required correctly', () => {});

test('it should pass false value as default parameter', () => {
expect(
parametersToJsonSchema({
parameters: [
{
in: 'query',
name: 'check',
schema: {
type: 'boolean',
default: false,
},
},
],
})[0].schema.properties.check,
).toEqual({ default: false, type: 'boolean' });
});
2 changes: 1 addition & 1 deletion packages/api-explorer/src/lib/oas-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const format = {
};

function formatter(values, param, type, onlyIfExists) {
if (values[type][param.name]) {
if (typeof values[type][param.name] !== 'undefined') {
return format.value(values[type][param.name]);
}
if (onlyIfExists && !param.required) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/src/lib/parameters-to-json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getOtherParams(pathOperation) {
schema.items = current.schema.items;
}

if (current.schema.default) schema.default = current.schema.default;
if (typeof current.schema.default !== 'undefined') schema.default = current.schema.default;
if (current.schema.enum) schema.enum = current.schema.enum;
if (current.schema.type) schema.type = current.schema.type;
if (current.schema.format) schema.format = current.schema.format;
Expand Down

0 comments on commit b70fb90

Please sign in to comment.