Skip to content
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

feat: addition of a getRequestBody accessor #580

Merged
merged 4 commits into from
Jan 12, 2022

Conversation

erunion
Copy link
Member

@erunion erunion commented Jan 12, 2022

🧰 Changes

Adds a new getRequestBody accessor on the Operation object that pulls back a request body Media Type Object for any specific media type that's present on the operation.

This isn't going to be used anywhere just yet but when we refactor/rewrite the getSchema() library here it can be used there.

🧬 QA & Testing

See tests.

@erunion erunion added the enhancement New feature or request label Jan 12, 2022
@erunion erunion force-pushed the feat/getrequestbody-accessor branch from 4e8e4bf to ab86b89 Compare January 12, 2022 00:55
describe('#getResponseByStatusCode()', () => {
it('should return false if the status code doesnt exist', () => {
const operation = Oas.init(petstore).operation('/pet/findByStatus', 'get');
expect(operation.getResponseByStatusCode(202)).toBe(false);
});

it('should return the response', () => {
const operation = Oas.init(petstore).operation('/pet/findByStatus', 'get');
it('should return the response', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to rework this test a bit because the dereferencing library we use does parameter reassigning so if one test dereferences the petstore spec then tests that use that spec after it will have a dereferenced spec.

@erunion erunion requested review from a team, Dashron and julshotal and removed request for a team January 12, 2022 01:09
}

const requestBody = this.schema.requestBody;
if (RMOAS.isRef(requestBody) || !(mediaType in requestBody.content)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return false if it's a ref? It's probably worth leaving those details as a comment here. I also don't see any tests for when the req body is a ref.

@erunion erunion merged commit 88b0b33 into main Jan 12, 2022
@erunion erunion deleted the feat/getrequestbody-accessor branch January 12, 2022 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants