diff --git a/apis_ontology/api/views.py b/apis_ontology/api/views.py index ef77632..21a4fdb 100644 --- a/apis_ontology/api/views.py +++ b/apis_ontology/api/views.py @@ -270,23 +270,7 @@ def get_paginated_response_schema(self, schema): "work_type": { "type": "array", "nullable": True, - "items": { - "type": "object", - "properties": { - "id": { - "type": "integer", - }, - "key": { - "type": "string", - }, - "count": { - "type": "integer", - }, - "children": { - "$ref": "#/components/schemas/PaginatedWorkPreviewList/properties/facets/properties/work_type" - }, - }, - }, + "items": {"$ref": "#/components/schemas/WorkTypeFacet"}, "example": [ { "id": 4, diff --git a/apis_ontology/schema.py b/apis_ontology/schema.py new file mode 100644 index 0000000..a54197a --- /dev/null +++ b/apis_ontology/schema.py @@ -0,0 +1,16 @@ +def postprocess_facets(result, generator, request, public): + work_type_facet_component = { + "type": "object", + "required": ["id", "key", "count"], + "properties": { + "id": {"type": "integer"}, + "key": {"type": "string"}, + "count": {"type": "integer"}, + "children": { + "type": "array", + "items": {"$ref": "#/components/schemas/WorkTypeFacet"}, + }, + }, + } + result["components"]["schemas"]["WorkTypeFacet"] = work_type_facet_component + return result diff --git a/apis_ontology/settings.py b/apis_ontology/settings.py index 0c0e8e2..57230ff 100644 --- a/apis_ontology/settings.py +++ b/apis_ontology/settings.py @@ -148,6 +148,10 @@ SPECTACULAR_SETTINGS["DEFAULT_GENERATOR_CLASS"] = ( "apis_core.generic.generators.CustomSchemaGenerator" ) +SPECTACULAR_SETTINGS["POSTPROCESSING_HOOKS"] = [ + "drf_spectacular.hooks.postprocess_schema_enums", + "apis_ontology.schema.postprocess_facets", +] # Database