Page MenuHomePhabricator

Find solution for documenting JSONField members in toolinfo api
Closed, ResolvedPublic

Description

The OpenAPI schema generation setup we are using does not have a really great solution for documenting the structure of JSONField members. Currently they are documented in the schema something like:

url_alternates : {
  <any-key>: {missing-type-info}
}

This does not tell the caller what they are expected to submit.

drf-spectacular allows adding OpenApiSerializerFieldExtension subclasses to change the serializer information (the missing-type-info above basically). This has a drawback that I have not found a solution for however. To apply a OpenApiSerializerFieldExtension fix one must make a named target class to apply it to rather than somehow decorating the existing model field. This in turn breaks the ability to inherit the API field's description and help_text from the backing model. So right now we can either have:

  • good help text and no structure
  • good structure and no help text

We need to find a way to get both. That may end up requiring a discussion upstream to either find a hidden feature in drf/drf-spectacular or to invent something new.

Event Timeline

This turns out to be a bit more than a documentation issue. The built-in api console for Toolhub is powered by generated schema and produces unexpected data because of the current state of the schema metadata.

bd808 triaged this task as Medium priority.
bd808 moved this task from Backlog to In Progress on the Toolhub board.

Change 658458 had a related patch set uploaded (by BryanDavis; owner: Bryan Davis):
[wikimedia/toolhub@main] api: Add JSONSchemaField for JSON data with a schema

https://gerrit.wikimedia.org/r/658458

Change 658458 merged by jenkins-bot:
[wikimedia/toolhub@main] api: Add JSONSchemaField for JSON data with a schema

https://gerrit.wikimedia.org/r/658458

Change 658487 had a related patch set uploaded (by BryanDavis; owner: Bryan Davis):
[wikimedia/toolhub@main] JSONSchemaField: Add a proper validator

https://gerrit.wikimedia.org/r/658487

Change 658487 merged by jenkins-bot:
[wikimedia/toolhub@main] JSONSchemaField: Add a proper validator

https://gerrit.wikimedia.org/r/658487

JSONSchemaField is handling this pretty well!