Skip to content

Commit

Permalink
fix: handle incorrect schemas gracefully (#29)
Browse files Browse the repository at this point in the history
* fix: handle incorrect schemas gracefully

* chore: bump openapi-to-json-schema
  • Loading branch information
P0lip authored Oct 16, 2019
1 parent bf23c12 commit 16058aa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/swagger-schema-official": "~2.0.18",
"@types/urijs": "~1.19.1",
"lodash": "^4.17.15",
"openapi-schema-to-json-schema": "philsturgeon/openapi-schema-to-json-schema#9692af184c6a3e3d952a88968da07491e47135fb",
"openapi-schema-to-json-schema": "stoplightio/openapi-schema-to-json-schema#c8b5f0c74270d505fc39635edef28e09df89601f",
"openapi3-ts": "~1.3.0",
"urijs": "~1.19.1"
},
Expand Down
46 changes: 45 additions & 1 deletion src/oas3/transformers/__tests__/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('translateMediaTypeObject', () => {
});
});

describe('shcmea invalid', () => {
describe('schema invalid', () => {
test('type as array does not throw error', () => {
const schema = ({
type: ['string', 'object'],
Expand All @@ -194,6 +194,50 @@ describe('shcmea invalid', () => {
),
).not.toThrow();
});

test('nullish values in arrays', () => {
/*
# Equivalent in YAML
type: array
items:
-
- object
*/
const schema = {
type: 'array',
items: [null, 'object'],
};

expect(() =>
translateMediaTypeObject(
{
schema,
},
'mediaType',
),
).not.toThrow();
});

test('nullish mapping value', () => {
/*
# Equivalent in YAML
type: array
items:
*/
const schema = {
type: 'array',
items: null,
} as any;

expect(() =>
translateMediaTypeObject(
{
schema,
},
'mediaType',
),
).not.toThrow();
});
});

describe('translateHeaderObject', () => {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6225,9 +6225,9 @@ onetime@^2.0.0:
dependencies:
mimic-fn "^1.0.0"

openapi-schema-to-json-schema@philsturgeon/openapi-schema-to-json-schema#9692af184c6a3e3d952a88968da07491e47135fb:
openapi-schema-to-json-schema@stoplightio/openapi-schema-to-json-schema#c8b5f0c74270d505fc39635edef28e09df89601f:
version "2.2.0"
resolved "https://codeload.github.com/philsturgeon/openapi-schema-to-json-schema/tar.gz/9692af184c6a3e3d952a88968da07491e47135fb"
resolved "https://codeload.github.com/stoplightio/openapi-schema-to-json-schema/tar.gz/c8b5f0c74270d505fc39635edef28e09df89601f"
dependencies:
deep-equal "^1.0.1"

Expand Down

0 comments on commit 16058aa

Please sign in to comment.