This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
Conversation
This file contains 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
yeralin
commented
Aug 23, 2019
diego-plan9
reviewed
Sep 4, 2019
It is done to highlight this schema being used with GET request (using query parameters).
Following up on Can you make |
diego-plan9
approved these changes
Sep 6, 2019
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.
Summary
Addresses #289
Adds schemas that describe request and response payloads for "root" endpoints.
Details and comments
I found couple problems while preparing this PR:
marshmallow.fileds.Dict
is not fully supportedIf you look at the official doc for
Dict
field under Marshmallow 2.0: https://marshmallow.readthedocs.io/en/2.x-line/api_reference.html#marshmallow.fields.DictIt states: "This field is only appropriate when the structure of nested data is not known." i.e. if you use
mashmallow.fields.Dict
field under your schema, it will be deserialized as a simpledict
object, no support formarshmallow.fields.Nested
.However, if you look at docs for
Dict
in Marshmallow 3.0:https://marshmallow.readthedocs.io/en/stable/api_reference.html#marshmallow.fields.Dict
You can explicitly set a nested schema for keys and values like:
They discussed the implementation of this feature under marshmallow-code/marshmallow#483
Because of this limitation schemas like
HubsResponseSchema
andCircuitResponseSchema
can only be deserialized partially.Also because of this issue,
marshmallow-jsonschema
package cannot generate a proper JSON schema for nested dicts, and rendered as<not serializable>
:HubsResponseSchema
will always fail bc@bind_schema
does not allow passingmany = True
The issue was raised under
qiskit-terra
repo: Qiskit/qiskit#3021If we were to create a model for
HubsResponseSchema
using@bind_schema
decorator, and then use it to deserialize hubs response payload, the deserialization will always fail withModelValidationError
. The reason is bc the payload is of the following format:[<payload>]
i.e. the payload is wrapped in an array. This could be easily fixed by passingmany = True
while creating an instance ofHubsResponseSchema(many=True)
, but the instance is created internally in@bind_schema
decorator, and we cannot pass any arguments inside.