Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

New Feature: Validate with all properties required.#146

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
flixx wants to merge1 commit intopython-openapi:master
base:master
Choose a base branch
Loading
fromflixx:master

Conversation

flixx
Copy link

Hello.

We use openapi-core to validate our specs with the backend, so that we are sure that the documentation generated out of the specs is up-to-date.

However, so far, the validation only worked one-way:
Properties returned in the response of the backend that are missing in the specs generate an error. (good)
Properties in the specs that are not returned in the response of the backend generate no error unless they are required (bad).

One solution would be, of curse, to set all properties to required. However, we do not want to do that since it is 1. confusing in the documentation 2. a lot of work.

This PR introducesrequire_all_props
It can be set like this:

RequestValidator(spec, require_all_props=True)# orResponseValidator(spec, require_all_props=True)

If it is set to true, it is simulated that all properties defined in the specs are required.

Felix

When setting the new flag `require_all_props` to true,it is simulated that all properties in the specs are required.

for prop_name, prop in iteritems(all_props):
try:
prop_value = value[prop_name]
except KeyError:
if prop_name in all_req_props_names:
if(prop_name in all_req_props_names) or require_all_props:
Copy link
Author

Choose a reason for hiding this comment

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

@reviewers This is the important line. All other changes are passing around the flag.

@codecov
Copy link

codecovbot commentedJun 25, 2019

Codecov Report

Merging#146 intomaster willincrease coverage by0.25%.
The diff coverage is100%.

Impacted file tree graph

@@            Coverage Diff             @@##           master     #146      +/-   ##==========================================+ Coverage   96.19%   96.44%   +0.25%==========================================  Files          58       58                Lines        1602     1605       +3     ==========================================+ Hits         1541     1548       +7+ Misses         61       57       -4
Impacted FilesCoverage Δ
openapi_core/schema/media_types/models.py85.29% <100%> (ø)⬆️
openapi_core/schema/schemas/models.py96.67% <100%> (+0.01%)⬆️
openapi_core/schema/parameters/models.py96.82% <100%> (ø)⬆️
openapi_core/validation/response/validators.py100% <100%> (ø)⬆️
openapi_core/schema/schemas/unmarshallers.py100% <100%> (ø)⬆️
openapi_core/validation/request/validators.py100% <100%> (ø)⬆️
openapi_core/compat.py100% <0%> (+44.44%)⬆️

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update0e30b71...0b34ed1. Read thecomment docs.

1 similar comment
@codecov
Copy link

codecovbot commentedJun 25, 2019
edited
Loading

Codecov Report

Merging#146 intomaster willincrease coverage by0.25%.
The diff coverage is100%.

Impacted file tree graph

@@            Coverage Diff             @@##           master     #146      +/-   ##==========================================+ Coverage   96.19%   96.44%   +0.25%==========================================  Files          58       58                Lines        1602     1605       +3     ==========================================+ Hits         1541     1548       +7+ Misses         61       57       -4
Impacted FilesCoverage Δ
openapi_core/schema/media_types/models.py85.29% <100%> (ø)⬆️
openapi_core/schema/schemas/models.py96.67% <100%> (+0.01%)⬆️
openapi_core/schema/parameters/models.py96.82% <100%> (ø)⬆️
openapi_core/validation/response/validators.py100% <100%> (ø)⬆️
openapi_core/schema/schemas/unmarshallers.py100% <100%> (ø)⬆️
openapi_core/validation/request/validators.py100% <100%> (ø)⬆️
openapi_core/compat.py100% <0%> (+44.44%)⬆️

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update0e30b71...0b34ed1. Read thecomment docs.

for t, u in primitive_unmarshallers.items()
)

pass_defaults = lambda f: functools.partial(
Copy link
Author

Choose a reason for hiding this comment

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

I needed to refactor that part since the parameters were not passed in right with that lambda function here.

@bjmc
Copy link
Contributor

bjmc commentedJun 30, 2019
edited
Loading

Properties in the specs that are not returned in the response of the backend generate no error unless they are required (bad).

Could you explain this a little more? If those properties aren't required in the spec, then they are optional. Why is it bad to not return an error for optional properties being omitted? If all the properties are required, they should all be marked required in the spec.

Maybe there's something subtle I'm misunderstanding here.

p1c2u reacted with thumbs up emoji

@flixx
Copy link
Author

flixx commentedJul 8, 2019
edited
Loading

Sure@bjmc@p1c2u:
We publish an API Documentation based on our OpenAPI Spec to our customers.
We want to ensure that the Documentation is always up-to-date.

In order to ensure that all fields that are in the Specs are in the response of our Backend, we would need to set every single property as required.

I think the term "required" does not really make sense when you talk about responses. In our API Documentation, we want to tell the API-User what properties are "Required" in theRequest, yes, but naming something "required" in theResponse, does not really make sense - our Backend always gives a Response with a complete list of all properties (some of them are nullable).

So, yes technically, it would be most right to always mark all fields in the Response Schemes as required. But practically, this is both a lot of work (it is easy to forget to add new properties to the required list) and strange for a reader of a documentation.

So I understand your point - but the changes I suggest here already helped us to make our API Documentation a lot better.

Felix

@spacether
Copy link

@flixx if this is always the case then why not add an automated postprocessing step that marks all response schema properties as required and generates the updated spec. That way it will always be done.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@flixx@bjmc@spacether

[8]ページ先頭

©2009-2025 Movatter.jp