-
-
Notifications
You must be signed in to change notification settings - Fork 135
Adding support for readOnly and writeOnly #135
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
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
43d93ac
Implementing readOnly and writeOnly validation
badcure ae2479c
Adding readOnly and writeOnly support to validator.
badcure faf1f49
Ignoring reports directory
badcure 709ce8c
Fixing string issue for Python 2.7
badcure 147d9f7
Python 2 uses str as "bytes" which is still a string.
badcure 1f8b2bc
Fixing a bug with the logic when requried was specified. Including te…
badcure 66d2ace
Attempting to fix string issues between 2 and 3.
badcure d369076
Attempting to fix string issues between 2 and 3...again
badcure 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ nosetests.xml | |
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
reports/ | ||
|
||
# Translations | ||
*.mo | ||
|
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
openapi: "3.0.0" | ||
info: | ||
version: 1.0.0 | ||
title: Test Post and Get | ||
license: | ||
name: MIT | ||
paths: | ||
/object: | ||
post: | ||
summary: Post an Object | ||
operationId: postObject | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ObjectDesc' | ||
responses: | ||
'201': | ||
description: Null response | ||
/object/{objectId}: | ||
get: | ||
summary: Get an Object | ||
operationId: getObject | ||
parameters: | ||
- name: objectId | ||
in: path | ||
required: true | ||
description: The id of the object | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: Object description | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/ObjectDesc" | ||
components: | ||
schemas: | ||
ObjectDesc: | ||
type: object | ||
additionalProperties: False | ||
properties: | ||
object_id: | ||
type: string | ||
readOnly: true | ||
message: | ||
type: string | ||
password: | ||
type: string | ||
writeOnly: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import pytest | ||
import json | ||
|
||
from openapi_core.shortcuts import create_spec | ||
from openapi_core.validation.request.validators import RequestValidator | ||
from openapi_core.validation.response.validators import ResponseValidator | ||
from openapi_core.wrappers.mock import MockRequest, MockResponse | ||
|
||
|
||
class TestGetAndPost(object): | ||
|
||
get_object = [{ | ||
"object_id": "random_id", | ||
"message": "test message" | ||
}] | ||
|
||
post_object = [{ | ||
"message": "second message", | ||
"password": "fakepassword" | ||
}] | ||
spec_paths = [ | ||
"data/v3.0/get_and_post.yaml", | ||
] | ||
|
||
@pytest.mark.parametrize("response", post_object) | ||
@pytest.mark.parametrize("spec_path", spec_paths) | ||
def test_post_object_success(self, factory, response, spec_path): | ||
spec_dict = factory.spec_from_file(spec_path) | ||
spec = create_spec(spec_dict) | ||
validator = RequestValidator(spec) | ||
request = MockRequest("http://www.example.com", "post", | ||
"/object", data=json.dumps(response)) | ||
|
||
result = validator.validate(request) | ||
assert not result.errors | ||
|
||
@pytest.mark.parametrize("response", get_object) | ||
@pytest.mark.parametrize("spec_path", spec_paths) | ||
def test_post_object_failure(self, factory, response, spec_path): | ||
spec_dict = factory.spec_from_file(spec_path) | ||
spec = create_spec(spec_dict) | ||
validator = RequestValidator(spec) | ||
request = MockRequest("http://www.example.com", "post", | ||
"/object", data=json.dumps(response)) | ||
|
||
result = validator.validate(request) | ||
assert result.errors | ||
|
||
@pytest.mark.parametrize("response", get_object) | ||
@pytest.mark.parametrize("spec_path", spec_paths) | ||
def test_get_object_success(self, factory, response, spec_path): | ||
spec_dict = factory.spec_from_file(spec_path) | ||
spec = create_spec(spec_dict) | ||
request = MockRequest("http://www.example.com", "get", | ||
"/object/{objectId}") | ||
validator = ResponseValidator(spec) | ||
response = MockResponse(data=json.dumps(response)) | ||
|
||
result = validator.validate(request, response) | ||
print(result.errors) | ||
assert not result.errors | ||
|
||
@pytest.mark.parametrize("response", post_object) | ||
@pytest.mark.parametrize("spec_path", spec_paths) | ||
def test_get_object_failure(self, factory, response, spec_path): | ||
spec_dict = factory.spec_from_file(spec_path) | ||
spec = create_spec(spec_dict) | ||
request = MockRequest("http://www.example.com", "get", | ||
"/object/{objectId}") | ||
|
||
validator = ResponseValidator(spec) | ||
response = MockResponse(data=json.dumps(response)) | ||
|
||
result = validator.validate(request, response) | ||
assert result.errors |
Oops, something went wrong.
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.
This allows a given schema to be both readOnly and writeOnly at the same time.