This repository was archived by the owner on Jul 15, 2025. It is now read-only.
check response input is json#63
Merged
backwardspy merged 1 commit intomasterfrom Jan 6, 2023
feature/MER-1958-api-reflector-check-the-input-is-a-valid-json-when-content-type-is-application-json
Conversation
backwardspy
suggested changes
Jan 5, 2023
Owner
There was a problem hiding this comment.
this needs to check content type is application/json before trying to validate the content, otherwise we will lose support for non json responses.
additionally, i can see the appeal of doing this sort of validation for other content types in future. perhaps consider moving the validation into its own function and mapping content types to validators.
perhaps something along these lines:
def is_valid_json(data: str) -> None:
json.loads(data)
validators = {
"application/json": is_valid_json,
}
def on_model_change(...):
if validator := validators.get(form.content_type.data):
validator(form.content.data)
super.on_model_change(...)
Mick-Cadac
reviewed
Jan 6, 2023
Contributor
Mick-Cadac
left a comment
There was a problem hiding this comment.
As well as Chris's comment you need to make sure AC2 is covered too. The content field can be left empty, no validation is required for this case.
Mick-Cadac
reviewed
Jan 6, 2023
Mick-Cadac
approved these changes
Jan 6, 2023
currently supports the application/json content type with space for more in future.
d982cc4 to
367c657
Compare
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
https://hellobink.atlassian.net/browse/MER-1958