Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Fix incorrect OpenAPI examples (#5160)

Dhruv Bhanushalid5740c813388
diff --git a/api/api/docs/audio_docs.py b/api/api/docs/audio_docs.py
index 0bd3ab93d..4b4c721ef 100644
--- a/api/api/docs/audio_docs.py
+++ b/api/api/docs/audio_docs.py
@@ -58,7 +58,7 @@ search = custom_extend_schema(
desc=audio_search_description,
params=serializer,
res={
- 200: (AudioSerializer, audio_search_200_example),
+ 200: (AudioSerializer, audio_search_200_example["results"][0]),
400: (ValidationError, audio_search_400_example),
401: (NotAuthenticated, None),
},
@@ -77,7 +77,7 @@ stats = custom_extend_schema(
By using this endpoint, you can obtain info about content sources such
as {fields_to_md(SourceSerializer.Meta.fields)}.""",
res={
- 200: (SourceSerializer(many=True), audio_stats_200_example),
+ 200: (SourceSerializer(many=True), audio_stats_200_example[0]),
401: (AuthenticationFailed, None),
},
eg=[audio_stats_curl],
@@ -104,7 +104,7 @@ related = custom_extend_schema(
By using this endpoint, you can get the details of related audio such as
{fields_to_md(AudioSerializer.Meta.fields)}.""",
res={
- 200: (AudioSerializer(many=True), audio_related_200_example),
+ 200: (AudioSerializer(many=True), audio_related_200_example["results"][0]),
401: (AuthenticationFailed, None),
404: (NotFound, audio_related_404_example),
},
diff --git a/api/api/docs/base_docs.py b/api/api/docs/base_docs.py
index 1fad125c9..c5e4af65e 100644
--- a/api/api/docs/base_docs.py
+++ b/api/api/docs/base_docs.py
@@ -93,7 +93,7 @@ def get_examples(code, serializer, example):
):
example = APIExceptionOpenApiSerializerExtension.exception_example(serializer)
elif example:
- example = example["application/json"]
+ example = example
else:
return []
diff --git a/api/api/docs/image_docs.py b/api/api/docs/image_docs.py
index 9d0837cbb..e0146b188 100644
--- a/api/api/docs/image_docs.py
+++ b/api/api/docs/image_docs.py
@@ -61,7 +61,7 @@ search = custom_extend_schema(
desc=image_search_description,
params=serializer,
res={
- 200: (ImageSerializer, image_search_200_example),
+ 200: (ImageSerializer, image_search_200_example["results"][0]),
400: (ValidationError, image_search_400_example),
401: (NotAuthenticated, None),
},
@@ -80,7 +80,7 @@ stats = custom_extend_schema(
By using this endpoint, you can obtain info about content sources such
as {fields_to_md(SourceSerializer.Meta.fields)}.""",
res={
- 200: (SourceSerializer(many=True), image_stats_200_example),
+ 200: (SourceSerializer(many=True), image_stats_200_example[0]),
401: (AuthenticationFailed, None),
},
eg=[image_stats_curl],
@@ -107,7 +107,7 @@ related = custom_extend_schema(
By using this endpoint, you can get the details of related images such as
{fields_to_md(ImageSerializer.Meta.fields)}.""",
res={
- 200: (ImageSerializer, image_related_200_example),
+ 200: (ImageSerializer(many=True), image_related_200_example["results"][0]),
401: (AuthenticationFailed, None),
404: (NotFound, image_related_404_example),
},
diff --git a/api/api/examples/audio_responses.py b/api/api/examples/audio_responses.py
index a6b706020..f8498ac07 100644
--- a/api/api/examples/audio_responses.py
+++ b/api/api/examples/audio_responses.py
@@ -56,115 +56,101 @@ base_audio = {
}
audio_search_200_example = {
- "application/json": {
- "result_count": 1,
- "page_count": 1,
- "page_size": 20,
- "page": 1,
- "results": [
- base_audio | {"fields_matched": ["title"]},
- ],
- },
+ "result_count": 1,
+ "page_count": 1,
+ "page_size": 20,
+ "page": 1,
+ "results": [
+ base_audio | {"fields_matched": ["title"]},
+ ],
}
audio_search_400_example = {
- "application/json": {
- "error": "InputError",
- "detail": "Invalid input given for fields. 'license' -> License 'PDMNBCG' does not exist.", # noqa: E501
- "fields": ["license"],
- }
+ "error": "InputError",
+ "detail": "Invalid input given for fields. 'license' -> License 'PDMNBCG' does not exist.", # noqa: E501
+ "fields": ["license"],
}
-audio_stats_200_example = {
- "application/json": [
- {
- "source_name": "freesound",
- "display_name": "Freesound",
- "source_url": "https://freesound.org/",
- "logo_url": None,
- "media_count": 827,
- },
- {
- "source_name": "jamendo",
- "display_name": "Jamendo",
- "source_url": "https://www.jamendo.com",
- "logo_url": None,
- "media_count": 180,
- },
- {
- "source_name": "wikimedia_audio",
- "display_name": "Wikimedia",
- "source_url": "https://commons.wikimedia.org",
- "logo_url": None,
- "media_count": 3992,
- },
- {
- "display_name": "CCMixter",
- "logo_url": None,
- "media_count": 1,
- "source_name": "ccmixter",
- "source_url": "https://ccmixter.org",
- },
- ]
-}
+audio_stats_200_example = [
+ {
+ "source_name": "freesound",
+ "display_name": "Freesound",
+ "source_url": "https://freesound.org/",
+ "logo_url": None,
+ "media_count": 827,
+ },
+ {
+ "source_name": "jamendo",
+ "display_name": "Jamendo",
+ "source_url": "https://www.jamendo.com",
+ "logo_url": None,
+ "media_count": 180,
+ },
+ {
+ "source_name": "wikimedia_audio",
+ "display_name": "Wikimedia",
+ "source_url": "https://commons.wikimedia.org",
+ "logo_url": None,
+ "media_count": 3992,
+ },
+ {
+ "display_name": "CCMixter",
+ "logo_url": None,
+ "media_count": 1,
+ "source_name": "ccmixter",
+ "source_url": "https://ccmixter.org",
+ },
+]
-audio_detail_200_example = {"application/json": base_audio}
+audio_detail_200_example = base_audio
-audio_detail_404_example = {"application/json": {"detail": "Not found."}}
+audio_detail_404_example = {"detail": "Not found."}
audio_related_200_example = {
- "application/json": {
- "result_count": 10000,
- "page_count": 1,
- "results": [
- {
- "title": "File:Mozart - Eine kleine Nachtmusik - 1. Allegro.ogg",
- "id": "36537842-b067-4ca0-ad67-e00ff2e06b2e",
- "creator": "Wolfgang Amadeus Mozart",
- "creator_url": "https://en.wikipedia.org/wiki/Wolfgang_Amadeus_Mozart",
- "url": "https://upload.wikimedia.org/wikipedia/commons/2/24/Mozart_-_Eine_kleine_Nachtmusik_-_1._Allegro.ogg", # noqa: E501
- "provider": "wikimedia",
- "source": "wikimedia",
- "license": "by-sa",
- "license_version": "2.0",
- "license_url": "https://creativecommons.org/licenses/by-sa/2.0/",
- "foreign_landing_url": "https://commons.wikimedia.org/w/index.php?curid=3536953", # noqa: E501
- "detail_url": f"{ORIGIN}/v1/audio/36537842-b067-4ca0-ad67-e00ff2e06b2e", # noqa: E501
- "related_url": f"{ORIGIN}/v1/recommendations/audio/36537842-b067-4ca0-ad67-e00ff2e06b2e", # noqa: E501
- "fields_matched": ["description", "title"],
- "tags": [{"name": "exam"}, {"name": "tactics"}],
- }
- ],
- }
+ "result_count": 1,
+ "page_count": 1,
+ "page_size": 20,
+ "page": 1,
+ "results": [
+ {
+ "title": "File:Mozart - Eine kleine Nachtmusik - 1. Allegro.ogg",
+ "id": "36537842-b067-4ca0-ad67-e00ff2e06b2e",
+ "creator": "Wolfgang Amadeus Mozart",
+ "creator_url": "https://en.wikipedia.org/wiki/Wolfgang_Amadeus_Mozart",
+ "url": "https://upload.wikimedia.org/wikipedia/commons/2/24/Mozart_-_Eine_kleine_Nachtmusik_-_1._Allegro.ogg", # noqa: E501
+ "provider": "wikimedia",
+ "source": "wikimedia",
+ "license": "by-sa",
+ "license_version": "2.0",
+ "license_url": "https://creativecommons.org/licenses/by-sa/2.0/",
+ "foreign_landing_url": "https://commons.wikimedia.org/w/index.php?curid=3536953", # noqa: E501
+ "detail_url": f"{ORIGIN}/v1/audio/36537842-b067-4ca0-ad67-e00ff2e06b2e", # noqa: E501
+ "related_url": f"{ORIGIN}/v1/recommendations/audio/36537842-b067-4ca0-ad67-e00ff2e06b2e", # noqa: E501
+ "fields_matched": ["description", "title"],
+ "tags": [{"name": "exam"}, {"name": "tactics"}],
+ }
+ ],
}
-audio_related_404_example = {
- "application/json": {"detail": "An internal server error occurred."}
-}
+audio_related_404_example = {"detail": "An internal server error occurred."}
audio_complain_201_example = {
- "application/json": {
- "identifier": identifier,
- "reason": "mature",
- "description": "This audio contains sensitive content",
- }
+ "identifier": identifier,
+ "reason": "mature",
+ "description": "This audio contains sensitive content",
}
audio_waveform_200_example = {
- "application/json": {
- "len": 1083,
- "points": [
- 0.61275,
- 0.19593,
- 0.74023,
- # 1077 more entries
- 0.00089,
- 0.00043,
- 0.00049,
- ],
- }
+ "len": 1083,
+ "points": [
+ 0.61275,
+ 0.19593,
+ 0.74023,
+ # 1077 more entries
+ 0.00089,
+ 0.00043,
+ 0.00049,
+ ],
}
-audio_waveform_404_example = {
- "application/json": {"detail": "An internal server error occurred."}
-}
+audio_waveform_404_example = {"detail": "An internal server error occurred."}
diff --git a/api/api/examples/image_responses.py b/api/api/examples/image_responses.py
index b16a702e3..4205eadab 100644
--- a/api/api/examples/image_responses.py
+++ b/api/api/examples/image_responses.py
@@ -60,109 +60,85 @@ base_image = {
"unstable__sensitivity": [],
}
-detailed_image = base_image | {
- "attribution": '"Tree Bark Photo" by Tim Sullivan is marked with CC0 1.0. To view the terms, visit https://creativecommons.org/publicdomain/zero/1.0/.', # noqa: E501
- "height": 4016,
- "filesize": 896128,
- "filetype": "jpg",
- "width": 6016,
-}
-
image_search_200_example = {
- "application/json": {
- "result_count": 1,
- "page_count": 1,
- "page_size": 20,
- "page": 1,
- "results": [base_image | {"fields_matched": ["title"]}],
- },
+ "result_count": 1,
+ "page_count": 1,
+ "page_size": 20,
+ "page": 1,
+ "results": [base_image | {"fields_matched": ["title"]}],
}
image_search_400_example = {
- "application/json": {
- "error": "InputError",
- "detail": "Invalid input given for fields. 'license' -> License 'PDMNBCG' does not exist.", # noqa: E501
- "fields": ["license"],
- }
+ "error": "InputError",
+ "detail": "Invalid input given for fields. 'license' -> License 'PDMNBCG' does not exist.", # noqa: E501
+ "fields": ["license"],
}
-image_stats_200_example = {
- "application/json": [
- {
- "source_name": "flickr",
- "display_name": "Flickr",
- "source_url": "https://www.flickr.com",
- "logo_url": None,
- "media_count": 2500,
- },
- {
- "source_name": "stocksnap",
- "display_name": "StockSnap",
- "source_url": "https://stocksnap.io",
- "logo_url": None,
- "media_count": 2500,
- },
- ]
-}
+image_stats_200_example = [
+ {
+ "source_name": "flickr",
+ "display_name": "Flickr",
+ "source_url": "https://www.flickr.com",
+ "logo_url": None,
+ "media_count": 2500,
+ },
+ {
+ "source_name": "stocksnap",
+ "display_name": "StockSnap",
+ "source_url": "https://stocksnap.io",
+ "logo_url": None,
+ "media_count": 2500,
+ },
+]
-image_detail_200_example = {"application/json": detailed_image}
+image_detail_200_example = base_image
-image_detail_404_example = {"application/json": {"detail": "Not found."}}
+image_detail_404_example = {"detail": "Not found."}
image_related_200_example = {
- "application/json": {
- "result_count": 10000,
- "page_count": 1,
- "results": [
- {
- "title": "exam tactics",
- "id": "610756ec-ae31-4d5e-8f03-8cc52f31b71d",
- "creator": "Sean MacEntee",
- "creator_url": "https://www.flickr.com/photos/18090920@N07",
- "tags": [{"name": "exam"}, {"name": "tactics"}],
- "url": "https://live.staticflickr.com/4065/4459771899_07595dc42e.jpg", # noqa: E501
- "thumbnail": f"{ORIGIN}/v1/thumbs/610756ec-ae31-4d5e-8f03-8cc52f31b71d", # noqa: E501
- "provider": "flickr",
- "source": "flickr",
- "license": "by",
- "license_version": "2.0",
- "license_url": "https://creativecommons.org/licenses/by/2.0/",
- "foreign_landing_url": "https://www.flickr.com/photos/18090920@N07/4459771899", # noqa: E501
- "detail_url": f"{ORIGIN}/v1/images/610756ec-ae31-4d5e-8f03-8cc52f31b71d", # noqa: E501
- "related_url": f"{ORIGIN}/v1/recommendations/images/610756ec-ae31-4d5e-8f03-8cc52f31b71d", # noqa: E501
- }
- ],
- }
+ "result_count": 1,
+ "page_count": 1,
+ "page_size": 20,
+ "page": 1,
+ "results": [
+ {
+ "title": "exam tactics",
+ "id": "610756ec-ae31-4d5e-8f03-8cc52f31b71d",
+ "creator": "Sean MacEntee",
+ "creator_url": "https://www.flickr.com/photos/18090920@N07",
+ "tags": [{"name": "exam"}, {"name": "tactics"}],
+ "url": "https://live.staticflickr.com/4065/4459771899_07595dc42e.jpg", # noqa: E501
+ "thumbnail": f"{ORIGIN}/v1/thumbs/610756ec-ae31-4d5e-8f03-8cc52f31b71d", # noqa: E501
+ "provider": "flickr",
+ "source": "flickr",
+ "license": "by",
+ "license_version": "2.0",
+ "license_url": "https://creativecommons.org/licenses/by/2.0/",
+ "foreign_landing_url": "https://www.flickr.com/photos/18090920@N07/4459771899", # noqa: E501
+ "detail_url": f"{ORIGIN}/v1/images/610756ec-ae31-4d5e-8f03-8cc52f31b71d", # noqa: E501
+ "related_url": f"{ORIGIN}/v1/recommendations/images/610756ec-ae31-4d5e-8f03-8cc52f31b71d", # noqa: E501
+ }
+ ],
}
-image_related_404_example = {
- "application/json": {"detail": "An internal server error occurred."}
-}
+image_related_404_example = {"detail": "An internal server error occurred."}
image_oembed_200_example = {
- "application/json": {
- "version": "1.0",
- "type": "photo",
- "width": 6016,
- "height": 4016,
- "title": "Tree Bark Photo",
- "author_name": "Tim Sullivan",
- "author_url": "https://www.secretagencygroup.com",
- "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",
- }
+ "version": "1.0",
+ "type": "photo",
+ "width": 6016,
+ "height": 4016,
+ "title": "Tree Bark Photo",
+ "author_name": "Tim Sullivan",
+ "author_url": "https://www.secretagencygroup.com",
+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",
}
-image_oembed_404_example = {
- "application/json": {"detail": "An internal server error occurred."}
-}
-image_oembed_400_example = {
- "application/json": {"detail": {"url": ["Could not parse identifier from URL."]}}
-}
+image_oembed_404_example = {"detail": "An internal server error occurred."}
+image_oembed_400_example = {"detail": {"url": ["Could not parse identifier from URL."]}}
image_complain_201_example = {
- "application/json": {
- "identifier": identifier,
- "reason": "mature",
- "description": "Image contains sensitive content",
- }
+ "identifier": identifier,
+ "reason": "mature",
+ "description": "Image contains sensitive content",
}
diff --git a/api/api/examples/oauth2_responses.py b/api/api/examples/oauth2_responses.py
index 46f3a413b..492d35995 100644
--- a/api/api/examples/oauth2_responses.py
+++ b/api/api/examples/oauth2_responses.py
@@ -1,24 +1,20 @@
auth_register_201_example = {
- "application/json": {
- "name": "My amazing project",
- "client_id": "<Openverse API client ID>",
- "client_secret": "<Openverse API client secret>",
- }
+ "name": "My amazing project",
+ "client_id": "<Openverse API client ID>",
+ "client_secret": "<Openverse API client secret>",
}
+
auth_token_200_example = {
- "application/json": {
- "access_token": "<Openverse API token>",
- "scope": "read write groups",
- "expires_in": 36000,
- "token_type": "Bearer",
- }
+ "access_token": "<Openverse API token>",
+ "scope": "read write groups",
+ "expires_in": 36000,
+ "token_type": "Bearer",
}
+
auth_key_info_200_example = {
- "application/json": {
- "requests_this_minute": 2,
- "requests_today": 40,
- "rate_limit_model": "enhanced",
- }
+ "requests_this_minute": 2,
+ "requests_today": 40,
+ "rate_limit_model": "enhanced",
}
diff --git a/api/api/serializers/source_serializers.py b/api/api/serializers/source_serializers.py
index 26b4b017e..f5ec5d2f7 100644
--- a/api/api/serializers/source_serializers.py
+++ b/api/api/serializers/source_serializers.py
@@ -6,7 +6,6 @@ from api.models import ContentSource
@extend_schema_serializer(
- many=True,
deprecate_fields=["logo_url"],
)
class SourceSerializer(serializers.ModelSerializer):
diff --git a/api/api/utils/pagination.py b/api/api/utils/pagination.py
index b70f1b429..383d22598 100644
--- a/api/api/utils/pagination.py
+++ b/api/api/utils/pagination.py
@@ -81,7 +81,7 @@ class StandardPagination(PageNumberPagination):
"code": "partially invalid request parameter",
"message": (
"Some of the request parameters were bad, "
- "but we processed the request anywhere. "
+ "but we were able to process the request. "
"Here's some information that might help you "
"fix the problem for future requests."
),
diff --git a/api/test/test_examples.py b/api/test/test_examples.py
index 858c54a21..f76093d6d 100644
--- a/api/test/test_examples.py
+++ b/api/test/test_examples.py
@@ -28,10 +28,10 @@ def execute_request(request):
@pytest.mark.parametrize("in_val, out_val", list(audio_mappings.items()))
def test_audio_success_examples(in_val, out_val):
res = execute_request(in_val)
- assert res == out_val["application/json"]
+ assert res == out_val
@pytest.mark.parametrize("in_val, out_val", list(image_mappings.items()))
def test_image_success_examples(in_val, out_val):
res = execute_request(in_val)
- assert res == out_val["application/json"]
+ assert res == out_val