-
Notifications
You must be signed in to change notification settings - Fork 343
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
fix: respect the required parameter in the body #450
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
f51591f
feat: kill the validator registry concept for body
XVincentX bc7ea22
test: kill tests that aren't needed anymore
XVincentX 0277d37
test: kill snapshot
XVincentX ec67ffe
test: keep the test that make sense
XVincentX 9538e5f
test: use a verb that does not exist for real
XVincentX 8229744
Merge branch 'master' into feat/validator-registry-off
XVincentX 34d1346
Merge branch 'master' into feat/validator-registry-off
XVincentX 3e74fa7
test: fix the documents
XVincentX 4985851
test: add harness test 1
XVincentX c15d35b
test: harness part 2
XVincentX 60be4c8
test: add shell:true flag
XVincentX fc933db
fix: put better error message when stuff does not match
XVincentX 2f94dfb
test: adjust responses
XVincentX f890bc4
chore(deps): [security] bump lodash.template from 4.4.0 to 4.5.0 (#447)
dependabot-preview[bot] 7572966
chore(deps): [security] bump lodash from 4.17.11 to 4.17.13 (#448)
dependabot-preview[bot] aadffed
use bash for harness on windows
XVincentX df980e9
Merge branch 'master' into feat/validator-registry-off
XVincentX f77f040
test: no harness on windows
XVincentX bdbbfa3
test: add failing test
XVincentX 4682ba4
docs: precise yet another limitation
XVincentX 76d2fd9
fix: add validation error if body is required but not present
XVincentX 65ebac9
feat: validate only when necessary
XVincentX bf8d637
test:fix
XVincentX 082e52d
chore: cleanup
XVincentX 3928e74
test: make test behave as they should
XVincentX a071b25
chore: only post has body
XVincentX 62efb4d
test:fix
XVincentX a30aa19
Merge branch 'master' into feat/body-validation-required
XVincentX 1f1780a
Merge branch 'master' into feat/body-validation-required
XVincentX ecee804
test: do not repeat the test stuff and generalise
XVincentX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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 @@ | ||
import { IPrismDiagnostic, IValidator } from '@stoplight/prism-core'; | ||
import { IHttpContent, IHttpHeaderParam, IHttpOperation, IHttpQueryParam } from '@stoplight/types'; | ||
import { DiagnosticSeverity, IHttpContent, IHttpHeaderParam, IHttpOperation, IHttpQueryParam } from '@stoplight/types'; | ||
import * as caseless from 'caseless'; | ||
|
||
import { IHttpConfig, IHttpNameValue, IHttpNameValues, IHttpRequest, IHttpResponse } from '../types'; | ||
|
@@ -33,10 +33,15 @@ export class HttpValidator implements IValidator<IHttpOperation, IHttpRequest, I | |
|
||
if (config.body) { | ||
const { body } = input; | ||
|
||
this.bodyValidator | ||
.validate(body, (request && request.body && request.body.contents) || [], mediaType) | ||
.forEach(validationResult => results.push(validationResult)); | ||
if (request && request.body) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be way easier to read when we'll introduce |
||
if (!body && request.body.required) { | ||
results.push({ code: 'required', message: 'Body parameter is required', severity: DiagnosticSeverity.Error }); | ||
} else if (body) { | ||
this.bodyValidator | ||
.validate(body, (request && request.body && request.body.contents) || [], mediaType) | ||
.forEach(validationResult => results.push(validationResult)); | ||
} | ||
} | ||
} | ||
|
||
if (config.headers) { | ||
|
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
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,39 @@ | ||
====test==== | ||
When I send a request to an operation that has a body parameter | ||
and such body parameter is not required | ||
I shuold get 200 response | ||
====spec==== | ||
swagger: '2.0' | ||
paths: | ||
/pet: | ||
post: | ||
produces: | ||
- application/json | ||
consumes: | ||
- application/json | ||
parameters: | ||
- in: body | ||
name: body | ||
required: false | ||
schema: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 | ||
responses: | ||
'200': | ||
schema: | ||
type: string | ||
====server==== | ||
mock -p 4010 | ||
====command==== | ||
curl -i -X POST http://127.0.0.1:4010/pet | ||
====expect==== | ||
HTTP/1.1 200 OK | ||
content-type: application/json; charset=utf-8 | ||
content-length: 7 | ||
Date: Fri, 21 Jun 2019 09:25:34 GMT | ||
Connection: keep-alive | ||
|
||
"string" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you're wondering, get should not really have body parameters.