Skip to content

Commit

Permalink
Merge pull request #13 from stoplightio/fix/style-exist
Browse files Browse the repository at this point in the history
fix: check array includes only if style is defined
  • Loading branch information
Phil Sturgeon authored Jul 31, 2019
2 parents 0c2db6e + 337cc9c commit cff0310
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/oas3/transformers/__tests__/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ describe('translateMediaTypeObject', () => {
};
expect(testedFunction).toThrowErrorMatchingSnapshot();
});

test('given encoding with no style it should not throw an error', () => {
const testedFunction = () => {
translateMediaTypeObject(
{
schema: {},
examples: { example: { summary: 'multi example' } },
encoding: {
enc1: {
contentType: 'text/plain',
},
},
},
'mediaType',
);
};
expect(() => testedFunction()).not.toThrow();
});
});

describe('translateHeaderObject', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/oas3/transformers/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function translateEncodingPropertyObject(
HttpParamStyles.DeepObject,
];

if (!acceptableStyles.includes(encodingPropertyObject.style)) {
if (encodingPropertyObject.style && !acceptableStyles.includes(encodingPropertyObject.style)) {
throw new Error(
`Encoding property style: '${encodingPropertyObject.style}' is incorrect, must be one of: ${acceptableStyles}`,
);
Expand Down

0 comments on commit cff0310

Please sign in to comment.