[PJL-10221] handle some edge cases in OpenAPI v3.1 swagger generation #319
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.
Change 1
Right now, ContainsOnly validators are being handled identically to OneOf validators. This is because, in Marshmallow, ContainsOnly is a subclass of OneOf. However, this isn't actually correct because the logic is different -
I added a separate validator to handle ContainsOnly and validated that it produces the expected output against one of our repos (PADD). You can see in the below screenshot that we were incorrectly specifying the
enum:
parameter at the level of thevalue
itself (which causes an error if you run this against an OpenAPI validator, because you're comparing an array to a string) when theenum:
should actually be at under theitems:
.Change 2
In OpenAPI 3 https://swagger.io/docs/specification/v3_0/data-models/dictionaries/ we are able to specify the allowed types of dictionary values (keys must always be strings so there is no need to specify their type) in the swagger file. The corresponding marshmallow param would be
values
. I added logic to factor in any schema passed into thevalues
param and generate it in the swagger file. I also tested this on PADD and got expected results.