-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pulling over more oas tooling from @readme/api-explorer (#104)
* chore(deps-dev): upgrading @readme/eslint-config to 1.11.0 * feat: pulling over flattenArray and flattenSchema from @readme/api-explorer * chore: re-adding .prettierrc, prettier doesn't pick it up from eslint * docs: adding some comments to clarify ambiguous code
- Loading branch information
Showing
8 changed files
with
289 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"printWidth": 120, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
printWidth: 120, | ||
singleQuote: true, | ||
trailingComma: 'es5', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const flattenArray = require('../../src/lib/flatten-array'); | ||
|
||
test('should flatten array', () => { | ||
const array = [[1], [2, 3], [[4, 5]]]; | ||
expect(flattenArray(array)).toStrictEqual([1, 2, 3, 4, 5]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const flattenSchema = require('../../src/lib/flatten-schema'); | ||
|
||
const petstore = require('../fixtures/petstore'); | ||
|
||
test('should flatten schema to an array', () => { | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
category: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
expect(flattenSchema(schema)).toStrictEqual([ | ||
{ | ||
name: 'category', | ||
type: '[String]', | ||
description: undefined, | ||
}, | ||
]); | ||
}); | ||
|
||
test('should flatten a component schema to an array', () => { | ||
const schema = petstore.components.schemas.Pet; | ||
|
||
expect(flattenSchema(schema, petstore)).toStrictEqual([ | ||
{ name: 'id', type: 'Integer', description: undefined }, | ||
{ name: 'category', type: 'Object', description: undefined }, | ||
{ name: 'category.id', type: 'Integer', description: undefined }, | ||
{ name: 'category.name', type: 'String', description: undefined }, | ||
{ name: 'name', type: 'String', description: undefined }, | ||
{ name: 'photoUrls', type: '[String]', description: undefined }, | ||
{ name: 'tags', type: '[Object]', description: undefined }, | ||
{ name: 'tags[].id', type: 'Integer', description: undefined }, | ||
{ name: 'tags[].name', type: 'String', description: undefined }, | ||
{ name: 'status', type: 'String', description: 'pet status in the store' }, | ||
]); | ||
}); | ||
|
||
describe('$ref usages', () => { | ||
const schema = { | ||
properties: { | ||
responses: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/components/schemas/ApiResponse', | ||
}, | ||
}, | ||
tag: { | ||
$ref: '#/components/schemas/Tag', | ||
}, | ||
}, | ||
}; | ||
|
||
const expected = [ | ||
{ name: 'responses', type: '[Object]', description: undefined }, | ||
{ name: 'responses[].code', type: 'Integer', description: undefined }, | ||
{ name: 'responses[].type', type: 'String', description: undefined }, | ||
{ name: 'responses[].message', type: 'String', description: undefined }, | ||
{ name: 'tag', type: 'Object', description: undefined }, | ||
{ name: 'tag.id', type: 'Integer', description: undefined }, | ||
{ name: 'tag.name', type: 'String', description: undefined }, | ||
]; | ||
|
||
it('should flatten a schema that is a mix of objects and arrays', () => { | ||
expect(flattenSchema(schema, petstore)).toStrictEqual(expected); | ||
}); | ||
|
||
it('should flatten a schema that is a mix of objects and arrays but without explicit `type` properties set`', () => { | ||
const oas = { | ||
components: { | ||
schemas: { | ||
ApiResponse: { | ||
properties: petstore.components.schemas.ApiResponse.properties, | ||
}, | ||
Tag: { | ||
properties: petstore.components.schemas.Tag.properties, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
expect(flattenSchema(schema, oas)).toStrictEqual(expected); | ||
}); | ||
}); |
Oops, something went wrong.