Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3b9661e

Browse files
authoredMar 13, 2023
Revert SchemaGenerator description value from tuple to str (#1138)
1 parent 2e931e0 commit 3b9661e

File tree

3 files changed

+548
-6
lines changed

3 files changed

+548
-6
lines changed
 

‎example/tests/__snapshots__/test_openapi.ambr

Lines changed: 545 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,548 @@
706706
}
707707
'''
708708
# ---
709+
# name: test_schema_construction
710+
'''
711+
{
712+
"components": {
713+
"parameters": {
714+
"fields": {
715+
"description": "[sparse fieldsets](https://jsonapi.org/format/#fetching-sparse-fieldsets).\nUse fields[\\<typename\\>]=field1,field2,...,fieldN",
716+
"explode": true,
717+
"in": "query",
718+
"name": "fields",
719+
"required": false,
720+
"schema": {
721+
"type": "object"
722+
},
723+
"style": "deepObject"
724+
},
725+
"include": {
726+
"description": "[list of included related resources](https://jsonapi.org/format/#fetching-includes)",
727+
"in": "query",
728+
"name": "include",
729+
"required": false,
730+
"schema": {
731+
"type": "string"
732+
},
733+
"style": "form"
734+
}
735+
},
736+
"schemas": {
737+
"AuthorList": {
738+
"additionalProperties": false,
739+
"properties": {
740+
"attributes": {
741+
"properties": {
742+
"defaults": {
743+
"default": "default",
744+
"description": "help for defaults",
745+
"maxLength": 20,
746+
"minLength": 3,
747+
"type": "string",
748+
"writeOnly": true
749+
},
750+
"email": {
751+
"format": "email",
752+
"maxLength": 254,
753+
"type": "string"
754+
},
755+
"fullName": {
756+
"maxLength": 50,
757+
"type": "string"
758+
},
759+
"initials": {
760+
"readOnly": true,
761+
"type": "string"
762+
},
763+
"name": {
764+
"maxLength": 50,
765+
"type": "string"
766+
}
767+
},
768+
"required": [
769+
"name",
770+
"fullName",
771+
"email"
772+
],
773+
"type": "object"
774+
},
775+
"id": {
776+
"$ref": "#/components/schemas/id"
777+
},
778+
"links": {
779+
"properties": {
780+
"self": {
781+
"$ref": "#/components/schemas/link"
782+
}
783+
},
784+
"type": "object"
785+
},
786+
"relationships": {
787+
"properties": {
788+
"authorType": {
789+
"$ref": "#/components/schemas/reltoone"
790+
},
791+
"bio": {
792+
"$ref": "#/components/schemas/reltoone"
793+
},
794+
"comments": {
795+
"$ref": "#/components/schemas/reltomany"
796+
},
797+
"entries": {
798+
"$ref": "#/components/schemas/reltomany"
799+
},
800+
"firstEntry": {
801+
"$ref": "#/components/schemas/reltoone"
802+
}
803+
},
804+
"type": "object"
805+
},
806+
"type": {
807+
"$ref": "#/components/schemas/type"
808+
}
809+
},
810+
"required": [
811+
"type",
812+
"id"
813+
],
814+
"type": "object"
815+
},
816+
"ResourceIdentifierObject": {
817+
"oneOf": [
818+
{
819+
"$ref": "#/components/schemas/relationshipToOne"
820+
},
821+
{
822+
"$ref": "#/components/schemas/relationshipToMany"
823+
}
824+
]
825+
},
826+
"datum": {
827+
"description": "singular item",
828+
"properties": {
829+
"data": {
830+
"$ref": "#/components/schemas/resource"
831+
}
832+
}
833+
},
834+
"error": {
835+
"additionalProperties": false,
836+
"properties": {
837+
"code": {
838+
"type": "string"
839+
},
840+
"detail": {
841+
"type": "string"
842+
},
843+
"id": {
844+
"type": "string"
845+
},
846+
"links": {
847+
"$ref": "#/components/schemas/links"
848+
},
849+
"source": {
850+
"properties": {
851+
"meta": {
852+
"$ref": "#/components/schemas/meta"
853+
},
854+
"parameter": {
855+
"description": "A string indicating which query parameter caused the error.",
856+
"type": "string"
857+
},
858+
"pointer": {
859+
"description": "A [JSON Pointer](https://tools.ietf.org/html/rfc6901) to the associated entity in the request document [e.g. `/data` for a primary data object, or `/data/attributes/title` for a specific attribute.",
860+
"type": "string"
861+
}
862+
},
863+
"type": "object"
864+
},
865+
"status": {
866+
"type": "string"
867+
},
868+
"title": {
869+
"type": "string"
870+
}
871+
},
872+
"type": "object"
873+
},
874+
"errors": {
875+
"items": {
876+
"$ref": "#/components/schemas/error"
877+
},
878+
"type": "array",
879+
"uniqueItems": true
880+
},
881+
"failure": {
882+
"properties": {
883+
"errors": {
884+
"$ref": "#/components/schemas/errors"
885+
},
886+
"jsonapi": {
887+
"$ref": "#/components/schemas/jsonapi"
888+
},
889+
"links": {
890+
"$ref": "#/components/schemas/links"
891+
},
892+
"meta": {
893+
"$ref": "#/components/schemas/meta"
894+
}
895+
},
896+
"required": [
897+
"errors"
898+
],
899+
"type": "object"
900+
},
901+
"id": {
902+
"description": "Each resource object\u2019s type and id pair MUST [identify](https://jsonapi.org/format/#document-resource-object-identification) a single, unique resource.",
903+
"type": "string"
904+
},
905+
"jsonapi": {
906+
"additionalProperties": false,
907+
"description": "The server's implementation",
908+
"properties": {
909+
"meta": {
910+
"$ref": "#/components/schemas/meta"
911+
},
912+
"version": {
913+
"type": "string"
914+
}
915+
},
916+
"type": "object"
917+
},
918+
"link": {
919+
"oneOf": [
920+
{
921+
"description": "a string containing the link's URL",
922+
"format": "uri-reference",
923+
"type": "string"
924+
},
925+
{
926+
"properties": {
927+
"href": {
928+
"description": "a string containing the link's URL",
929+
"format": "uri-reference",
930+
"type": "string"
931+
},
932+
"meta": {
933+
"$ref": "#/components/schemas/meta"
934+
}
935+
},
936+
"required": [
937+
"href"
938+
],
939+
"type": "object"
940+
}
941+
]
942+
},
943+
"linkage": {
944+
"description": "the 'type' and 'id'",
945+
"properties": {
946+
"id": {
947+
"$ref": "#/components/schemas/id"
948+
},
949+
"meta": {
950+
"$ref": "#/components/schemas/meta"
951+
},
952+
"type": {
953+
"$ref": "#/components/schemas/type"
954+
}
955+
},
956+
"required": [
957+
"type",
958+
"id"
959+
],
960+
"type": "object"
961+
},
962+
"links": {
963+
"additionalProperties": {
964+
"$ref": "#/components/schemas/link"
965+
},
966+
"type": "object"
967+
},
968+
"meta": {
969+
"additionalProperties": true,
970+
"type": "object"
971+
},
972+
"nulltype": {
973+
"default": null,
974+
"nullable": true,
975+
"type": "object"
976+
},
977+
"onlymeta": {
978+
"additionalProperties": false,
979+
"properties": {
980+
"meta": {
981+
"$ref": "#/components/schemas/meta"
982+
}
983+
}
984+
},
985+
"pageref": {
986+
"oneOf": [
987+
{
988+
"format": "uri-reference",
989+
"type": "string"
990+
},
991+
{
992+
"$ref": "#/components/schemas/nulltype"
993+
}
994+
]
995+
},
996+
"pagination": {
997+
"properties": {
998+
"first": {
999+
"$ref": "#/components/schemas/pageref"
1000+
},
1001+
"last": {
1002+
"$ref": "#/components/schemas/pageref"
1003+
},
1004+
"next": {
1005+
"$ref": "#/components/schemas/pageref"
1006+
},
1007+
"prev": {
1008+
"$ref": "#/components/schemas/pageref"
1009+
}
1010+
},
1011+
"type": "object"
1012+
},
1013+
"relationshipLinks": {
1014+
"additionalProperties": true,
1015+
"description": "optional references to other resource objects",
1016+
"properties": {
1017+
"related": {
1018+
"$ref": "#/components/schemas/link"
1019+
},
1020+
"self": {
1021+
"$ref": "#/components/schemas/link"
1022+
}
1023+
},
1024+
"type": "object"
1025+
},
1026+
"relationshipToMany": {
1027+
"description": "An array of objects each containing the 'type' and 'id' for to-many relationships",
1028+
"items": {
1029+
"$ref": "#/components/schemas/linkage"
1030+
},
1031+
"type": "array",
1032+
"uniqueItems": true
1033+
},
1034+
"relationshipToOne": {
1035+
"anyOf": [
1036+
{
1037+
"$ref": "#/components/schemas/nulltype"
1038+
},
1039+
{
1040+
"$ref": "#/components/schemas/linkage"
1041+
}
1042+
],
1043+
"description": "reference to other resource in a to-one relationship"
1044+
},
1045+
"reltomany": {
1046+
"description": "a multiple 'to-many' relationship",
1047+
"properties": {
1048+
"data": {
1049+
"$ref": "#/components/schemas/relationshipToMany"
1050+
},
1051+
"links": {
1052+
"$ref": "#/components/schemas/relationshipLinks"
1053+
},
1054+
"meta": {
1055+
"$ref": "#/components/schemas/meta"
1056+
}
1057+
},
1058+
"type": "object"
1059+
},
1060+
"reltoone": {
1061+
"description": "a singular 'to-one' relationship",
1062+
"properties": {
1063+
"data": {
1064+
"$ref": "#/components/schemas/relationshipToOne"
1065+
},
1066+
"links": {
1067+
"$ref": "#/components/schemas/relationshipLinks"
1068+
},
1069+
"meta": {
1070+
"$ref": "#/components/schemas/meta"
1071+
}
1072+
},
1073+
"type": "object"
1074+
},
1075+
"resource": {
1076+
"additionalProperties": false,
1077+
"properties": {
1078+
"attributes": {
1079+
"type": "object"
1080+
},
1081+
"id": {
1082+
"$ref": "#/components/schemas/id"
1083+
},
1084+
"links": {
1085+
"$ref": "#/components/schemas/links"
1086+
},
1087+
"meta": {
1088+
"$ref": "#/components/schemas/meta"
1089+
},
1090+
"relationships": {
1091+
"type": "object"
1092+
},
1093+
"type": {
1094+
"$ref": "#/components/schemas/type"
1095+
}
1096+
},
1097+
"required": [
1098+
"type",
1099+
"id"
1100+
],
1101+
"type": "object"
1102+
},
1103+
"type": {
1104+
"description": "The [type](https://jsonapi.org/format/#document-resource-object-identification) member is used to describe resource objects that share common attributes and relationships.",
1105+
"type": "string"
1106+
}
1107+
}
1108+
},
1109+
"info": {
1110+
"title": "",
1111+
"version": ""
1112+
},
1113+
"openapi": "3.0.2",
1114+
"paths": {
1115+
"/authors/": {
1116+
"get": {
1117+
"description": "",
1118+
"operationId": "List/authors/",
1119+
"parameters": [
1120+
{
1121+
"$ref": "#/components/parameters/include"
1122+
},
1123+
{
1124+
"$ref": "#/components/parameters/fields"
1125+
},
1126+
{
1127+
"description": "A page number within the paginated result set.",
1128+
"in": "query",
1129+
"name": "page[number]",
1130+
"required": false,
1131+
"schema": {
1132+
"type": "integer"
1133+
}
1134+
},
1135+
{
1136+
"description": "Number of results to return per page.",
1137+
"in": "query",
1138+
"name": "page[size]",
1139+
"required": false,
1140+
"schema": {
1141+
"type": "integer"
1142+
}
1143+
},
1144+
{
1145+
"description": "[list of fields to sort by](https://jsonapi.org/format/#fetching-sorting)",
1146+
"in": "query",
1147+
"name": "sort",
1148+
"required": false,
1149+
"schema": {
1150+
"type": "string"
1151+
}
1152+
},
1153+
{
1154+
"description": "author_type",
1155+
"in": "query",
1156+
"name": "filter[authorType]",
1157+
"required": false,
1158+
"schema": {
1159+
"type": "string"
1160+
}
1161+
},
1162+
{
1163+
"description": "name",
1164+
"in": "query",
1165+
"name": "filter[name]",
1166+
"required": false,
1167+
"schema": {
1168+
"type": "string"
1169+
}
1170+
},
1171+
{
1172+
"description": "A search term.",
1173+
"in": "query",
1174+
"name": "filter[search]",
1175+
"required": false,
1176+
"schema": {
1177+
"type": "string"
1178+
}
1179+
}
1180+
],
1181+
"responses": {
1182+
"200": {
1183+
"content": {
1184+
"application/vnd.api+json": {
1185+
"schema": {
1186+
"properties": {
1187+
"data": {
1188+
"items": {
1189+
"$ref": "#/components/schemas/AuthorList"
1190+
},
1191+
"type": "array"
1192+
},
1193+
"included": {
1194+
"items": {
1195+
"$ref": "#/components/schemas/resource"
1196+
},
1197+
"type": "array",
1198+
"uniqueItems": true
1199+
},
1200+
"jsonapi": {
1201+
"$ref": "#/components/schemas/jsonapi"
1202+
},
1203+
"links": {
1204+
"allOf": [
1205+
{
1206+
"$ref": "#/components/schemas/links"
1207+
},
1208+
{
1209+
"$ref": "#/components/schemas/pagination"
1210+
}
1211+
],
1212+
"description": "Link members related to primary data"
1213+
}
1214+
},
1215+
"required": [
1216+
"data"
1217+
],
1218+
"type": "object"
1219+
}
1220+
}
1221+
},
1222+
"description": "List/authors/"
1223+
},
1224+
"401": {
1225+
"content": {
1226+
"application/vnd.api+json": {
1227+
"schema": {
1228+
"$ref": "#/components/schemas/failure"
1229+
}
1230+
}
1231+
},
1232+
"description": "not authorized"
1233+
},
1234+
"404": {
1235+
"content": {
1236+
"application/vnd.api+json": {
1237+
"schema": {
1238+
"$ref": "#/components/schemas/failure"
1239+
}
1240+
}
1241+
},
1242+
"description": "not found"
1243+
}
1244+
},
1245+
"tags": [
1246+
"authors"
1247+
]
1248+
}
1249+
}
1250+
}
1251+
}
1252+
'''
1253+
# ---

‎example/tests/test_openapi.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_delete_request(snapshot):
9797
"DEFAULT_SCHEMA_CLASS": "rest_framework_json_api.schemas.openapi.AutoSchema"
9898
}
9999
)
100-
def test_schema_construction():
100+
def test_schema_construction(snapshot):
101101
"""Construction of the top level dictionary."""
102102
patterns = [
103103
re_path("^authors/?$", views.AuthorViewSet.as_view({"get": "list"})),
@@ -107,10 +107,7 @@ def test_schema_construction():
107107
request = create_request("/")
108108
schema = generator.get_schema(request=request)
109109

110-
assert "openapi" in schema
111-
assert "info" in schema
112-
assert "paths" in schema
113-
assert "components" in schema
110+
assert snapshot == json.dumps(schema, indent=2, sort_keys=True)
114111

115112

116113
def test_schema_related_serializers():

‎rest_framework_json_api/schemas/openapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class SchemaGenerator(drf_openapi.SchemaGenerator):
185185
"A [JSON Pointer](https://tools.ietf.org/html/rfc6901) "
186186
"to the associated entity in the request document "
187187
"[e.g. `/data` for a primary data object, or "
188-
"`/data/attributes/title` for a specific attribute.",
188+
"`/data/attributes/title` for a specific attribute."
189189
),
190190
},
191191
"parameter": {

0 commit comments

Comments
 (0)
Please sign in to comment.