Skip to content

Add appropriate nullable flag depending on OpenAPI version #197

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
wants to merge 1 commit into from

Conversation

Bangertm
Copy link
Collaborator

@Bangertm Bangertm commented Apr 6, 2018

Addresses issue identified by @lafrech in #165

@Bangertm Bangertm requested a review from lafrech April 6, 2018 18:46
if not field.allow_none:
return {}

if spec and spec.openapi_version.version[0] == 3:
Copy link
Member

Choose a reason for hiding this comment

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

spec.openapi_version.version[0]

This is accessed in two places, and more to come. Maybe we should add a shortcut for it.
For instance properties spec.major_version, spec.minor_version.

Nothing blocking, just a thought.

@@ -293,8 +310,7 @@ def field2property(field, spec=None, use_refs=True, dump=True, name=None):
if field.dump_only:
ret['readOnly'] = True

if field.allow_none:
ret['x-nullable'] = True
ret.update(field2nullable(field, spec))
Copy link
Member

@lafrech lafrech Apr 6, 2018

Choose a reason for hiding this comment

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

I'm a bit bothered by the fact that the spec attribute to the function is optional and defaults to None.

Same concern for get_ref_path, BTW. Even worse then because we don't check it is not None.

Maybe we should make spec mandatory. It breaks a lot of tests, but maybe not real-life use cases (otherwise, you'd get an AttributeError in the call to get_ref_path).

We should give this a thought and maybe refactor a bit. Check what spec is used for and decide what needs to be passed. From what I gathered, we only use OpenAPI version, the list of schema definitions (refs) and an optional schema_name_resolver callable). Maybe we don't need to carry the whole spec object all around.

Anyway, this issue is much wider than this specific PR, so I suppose we can merge this and open a separate issue for the spec attribute refactor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Making spec mandatory everywhere is probably the right first step. Practically the entry points to all of these functions (schema_definition_helper schema_path_helper and schema_operation_resolver) have spec as mandatory so it's only the tests that break.

I think there is definitely some opportunity for refactoring. We have quite a bit of complexity around multiple ways of handling nested schemas (using refs, inlining, waiting to see if a ref gets added later, immediately resolving a name). Simplifying that would probably help in other areas.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, totally.

I'm not sure the whole spec needs to be carried about, but I think the version should be everywhere, as it may affect anything, so it should be provided to all helpers.

Anyway, we can merge this PR and focus on the refactor later on.

@lafrech lafrech mentioned this pull request Apr 9, 2018
@lafrech
Copy link
Member

lafrech commented Apr 9, 2018

I just proposed a PR that does this and more: #199.

@sloria
Copy link
Member

sloria commented Apr 11, 2018

nullable is supported in #199. Thanks anyway for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants