-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
removes passing reference paths in nested field metadata #363
removes passing reference paths in nested field metadata #363
Conversation
del parameter['schema'] | ||
resolved += self.openapi.schema2parameters( | ||
schema_cls, | ||
schema_instance, |
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 change is to prevent a schema like SelfReferencingSchema
passed as a query string parameter from throwing an error due to unbound nested self referencing fields. It is not valid to have a self referencing schema in that location, but at least it doesn't throw an error.
855909a
to
acf318b
Compare
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.
LGTM. Thanks.
Some tests fail. From a quick look, it is due to an undeterministic order. I relaunched py37-marshmallow2 after the failure and it passed. I don't understand how it is related to this change and why it used to work, I don't have much time to look at it right now, but I think the order doesn't matter and the test could be modified to not rely on the order. |
Hint: I think making class PetSchema(Schema):
class Meta:
ordered = True I'd still be interested to understand what changed in this PR that triggered this. |
I think it has to be the change from using the schema class to using an instance that I referenced above. Not sure what the mechanism would be though. I could just back out that change. The end result of having nested fields in a query string location is invalid by definition. So we could (should?) just raise an error if an invalid field is in a query location. We already kind of do that with apispec/apispec/ext/marshmallow/openapi.py Lines 522 to 523 in f12ca72
We can just add a check for invalid fields in a query location such as |
I think you can have a Nested field in a query location if you use a custom parser such as the Or maybe I'm confused. |
This looks like a change between OpenAPI v2 and v3. In v2 only primitive types are supported:
In v3 they can be objects:
In which case, nesting is perfectly fine. Sorting this out is probably going to take a little more thought. I noticed that other tests are using Lines 500 to 512 in f12ca72
So I can probably do that too. |
0e1264b
to
f617648
Compare
TBH, I never even wondered if this was OpenAPI compliant... Shame on me. Let's be permissive and don't force the user to be compliant, especially if something is acceptable in v3 and not in v2.
is fine as well. More explicit than the |
Forgot to look at the failing test before commenting just instancing I think there is something not quite right about the nested query string parameters are handled, but it's also likely to be a relatively uncommon use case. |
field2property now ignores a ref key in field metadata and relies only on the field autoreferencing capability Self referencing instances of `marshmallow.fields.Nested` that are unbound cannot be passed to field2property, which means that the `schema` argument of `OpenAPI.schema2jsonschema` and `OpenAPI.schema2parameters` must be a schema instance and not a schema class
f617648
to
88eba0f
Compare
OK, I don't understand why passing an instance solves the problem but as long as it does... Should we specify in |
Looks like @Bangertm already did that for :param Schema schema: A marshmallow Schema instance Would be good to document that for |
Great. I'm also eager to get this released. I couldn't help but proposing a last-minute breaking change: #381. |
Guys, I've been trying the latest apispec revision on a huge project of ours to identify potential issues before we release. I've been spending a great deal of time diving into (my own) legacy spaghetti code dealing with pathological cases of auto-generated inheritance schemas that would generate all kinds of errors and warnings. The code is now a mess, but I think I'm done with the test and I got it to work by simply overriding This means I validate it works in my use case. In fact, the auto-registration feature will allow me to remove a lot of code that will become useless. Great. Thanks again @Bangertm for the work on this. I wanted to conclude that this is good to go, but there's #383 I didn't have the time to investigate. |
field2property now ignores a ref key in field metadata and relies
only on the field autoreferencing capability
Self referencing instances of
marshmallow.fields.Nested
that areunbound cannot be passed to field2property, which means that the
schema
argument ofOpenAPI.schema2jsonschema
andOpenAPI.schema2parameters
must be a schema instance and not aschema class