-
Notifications
You must be signed in to change notification settings - Fork 77
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
add header validator #29
Conversation
d21a962
to
7c6f900
Compare
return model.getShapesWithTrait(HttpHeaderTrait.class).stream().flatMap(headerShape -> { | ||
String value = headerShape.getTrait(HttpHeaderTrait.class).get().getValue(); | ||
if (disallowedHeaderNames.contains(value)) { | ||
return Stream.of(error(headerShape, String.format("Header named `%s` should not be present since it is automatically filled", value))); |
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.
Maybe we should mention the @mediaType trait here
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.
Not sure, tbh. Like, the simpleRestJson protocol doesn't take it into consideration
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.
Also, error is too hard a severity. It might be that someone provides an implementation that allows for it, so
the error severity should only be used if we check that the header is in the closure of a simpleRestJson service.
If we don't perform that check, it should be a warning, not an error
public List<ValidationEvent> validate(Model model) { | ||
return model.getShapesWithTrait(HttpHeaderTrait.class).stream().flatMap(headerShape -> { | ||
String value = headerShape.getTrait(HttpHeaderTrait.class).get().getValue(); | ||
if (disallowedHeaderNames.contains(value)) { |
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.
Headers are case insensitive, so this doesn't quite cut it
Adds validator to make sure headers cannot be set if they are automatically set down the line.
Closes #28.