Closed kaiku closed 2 months ago
When type
is a list, as it will be with OpenAPI 3.1 if none is allowed, this will fail:
The consequence of this is that _flatten
is not called recursively for type: [...]
and nested objects are not resolved into refs.
Here is where type
is made into either a string or list of strings:
I've added a fix in: https://github.com/plangrid/flask-rebar/pull/315/commits/f70f5b562253950aca3218c457746486ad9fbe9b. Needs updates to tests first.
Problem
The latest version of flask-rebar generates a swagger.json that "expands"
$ref
to nested schemas specifically when usingfields.List(fields.Nested(...), allow_none=True)
.Details
I have marshmallow schemas with fields that look like this:
In 2.4.1, using
swagger_generator_v3
produces a swagger.json that looks like this:In 3.3.0, it looks like this:
Expected:
The important difference here is that instead of a
$ref
, the swagger codegen now expandsNestedSchema
into an embedded dict. From a raw API perspective there is no functional difference in the spec, but this does cause problems in our unit tests because we use a python client generated by swagger-codegen-cli.jar to make calls against our service, and responses from that are different.Investigation
allow_none=True
seems to be the culprit. If I remove that line, I get a nice ref again. However, I can't do this because it would break our API contract of allowing that field to actually be None.I've tried both
fields.List(fields.Nested(...))
andfields.Nested(..., many=True)
. They seem similar but not equivalent. If I use the latter, it does create a $ref again, butnull
is missing from the type list, which breaks the API contract. I also triedfields.Nested(..., many=True, allow_none=True)
, which I do think is valid and marshmallow supports it, but the generated schema still does not reflect that it can be a nullable field.