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.
Sometimes, I need to add a field to a definition.
Typical use case: the
discriminator
field (search for "discriminator" in there, this comment also explains a lot and points some limitations). This can also be a vendor field (x-my_field
).I created a specific definition helper for that, but I think it could be in apispec itself. There is nothing specific in it. So here's the PR.
I first added this to marshmallow plugin
schema_definition_helper
, but then I realized it was not specific to marshmallow schemas, so I moved it toAPISpec.definition
. I'm leaving the two commits on purpose to expose the two approaches. I can squash into one or remove the last one depending on which approach is preferred.This feature is pretty permissive. A more conservative approach would be to allow only fields that conform to the spec: a finite hardcoded list à la
_VALID_PROPERTIES
+ the possibility to pass any vendor field (x-
). I'm not sure this is needed. After all, the user addsextra_fields
explicitly, so he should know what he is doing. It's not like we're harvesting in some Schema's metadata. BTW, I don't thinkdiscriminator
should be defined in a field's metadata. It is schema level stuff. It shouldn't be in_VALID_PROPERTIES
, right?I'd be happy to hear your feedback about this.