Skip to content

feat: upgrading oas dependencies off v4.2.1 #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 4.3.0 (2022-04-05)

* feat: ugprading oas dependencies on v4.2.1 ([c328fd4](https://github.com/readmeio/api/commit/c328fd4))



## <small>4.2.1 (2022-03-18)</small>

* fix: quirk with node 16 and `response.clone()` ([de8d964](https://github.com/readmeio/api/commit/de8d964))



## 4.2.0 (2022-01-03)

* chore(deps-dev): bump @commitlint/cli from 15.0.0 to 16.0.1 (#372) ([2279bcf](https://github.com/readmeio/api/commit/2279bcf)), closes [#372](https://github.com/readmeio/api/issues/372)
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "4.2.0"
"version": "4.3.0"
}
340 changes: 151 additions & 189 deletions package-lock.json

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions packages/api/__tests__/lib/getSchema.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const getSchema = require('../../src/lib/getSchema');

const schema = { type: 'string' };

test('should return the first type if there is content', () => {
expect(
getSchema({
requestBody: {
content: {
'application/json': {
schema,
},
'text/xml': {
schema: { type: 'number' },
},
},
},
})
).toStrictEqual({
type: 'application/json',
schema: { schema },
});

expect(
getSchema({
requestBody: {
content: {
'text/xml': {
schema,
},
'application/json': {
schema: { type: 'number' },
},
},
},
})
).toStrictEqual({
type: 'text/xml',
schema: { schema },
});
});

test('should return undefined', () => {
expect(getSchema({})).toBeUndefined();
});

test('should return if theres a $ref on the top level', () => {
const $ref = '#/definitions/schema';
expect(getSchema({ requestBody: { $ref } })).toStrictEqual({
type: 'application/json',
schema: { $ref },
});
});

// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#requestBodyObject
test('should look up the schema if it looks like the first $ref is a request body object', () => {
const $ref = '#/components/schemas/schema';
expect(
getSchema(
{
requestBody: { $ref: '#/components/requestBodies/schema' },
},
{
components: {
requestBodies: { schema: { content: { 'application/json': { schema: { $ref } } } } },
},
}
).schema.schema.$ref
).toStrictEqual($ref);
});

test('should return the inline schema from request body object', () => {
expect(
getSchema(
{
requestBody: { $ref: '#/components/requestBodies/schema' },
},
{
components: { requestBodies: { schema: { content: { 'application/json': { schema } } } } },
}
).schema
).toStrictEqual({ schema });
});

test('should retain examples if they are present alongside the schema', () => {
expect(
getSchema({
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
properties: {
id: {
type: 'integer',
},
name: {
type: 'string',
},
},
},
examples: {
id: 10,
name: 'buster',
},
},
},
},
}).schema.examples
).toStrictEqual({
id: 10,
name: 'buster',
});
});
Loading