From bf251856d4e7b82b7fd73bd4dca8c9f97f7628db Mon Sep 17 00:00:00 2001 From: Itamar Givon Date: Mon, 21 Sep 2020 17:33:25 +0200 Subject: [PATCH] Declutter schemas.json (#66) * Create interfaces.json and payloads.json * Move AliasList * Move SnakHash * Move DocumentPatch * Remove unused lists * Move SitelinkMap and Snak * Reorganize payloads and interfaces * Remove unused SnakMapList * Move MediaWiki specific interfaces and payloads * Move PersistedStatement to payloads * Move PersistedReference to payloads * Move PersistedQualifiers to payloads * Reorganize HashedSnak anf list / map variants * Invert persisted and new statments, qualifiers, references * Fix new statement payload * Fix new reference payload format * Fix persisted reference and qualifiers responses * Reorder Sitelink * Add Snak to schema --- specs/global/interfaces.json | 129 +++++++++ specs/global/payloads.json | 106 +++++++ specs/global/requests.json | 37 +-- specs/global/responses.json | 29 +- specs/global/schemas.json | 296 ++------------------ specs/paths/statements/qualifiers/list.json | 2 +- 6 files changed, 303 insertions(+), 296 deletions(-) create mode 100644 specs/global/interfaces.json create mode 100644 specs/global/payloads.json diff --git a/specs/global/interfaces.json b/specs/global/interfaces.json new file mode 100644 index 0000000..bada686 --- /dev/null +++ b/specs/global/interfaces.json @@ -0,0 +1,129 @@ +{ + "Fingerprintable": { + "type": "object", + "properties": { + "labels": { + "$ref": "./schemas.json#/Labels" + }, + "descriptions": { + "$ref": "./schemas.json#/Descriptions" + }, + "aliases": { + "$ref": "./schemas.json#/Aliases" + } + }, + "required": [ + "labels", + "descriptions", + "aliases" + ] + }, + "HashBearing": { + "type": "object", + "properties": { "hash": { "$ref": "#/SnakHash"} } + }, + "HashedSnak": { + "allOf": [ + { + "$ref": "#/Snak" + }, + { + "type": "object", + "properties": { "hash": { "$ref": "#/SnakHash" } } + } + ] + }, + "HashedSnakList": { + "type": "array", + "items": { "$ref": "#/HashedSnak" } + }, + "HashedSnakMap": { + "type": "object", + "additionalProperties": { + "$ref": "#/HashedSnakList" + }, + "example": { + "P31": [], + "P100": [] + } + }, + "MediawikiEditComment": { "type": "string" }, + "MediawikiDeletionReason": { "type": "string" }, + "MediawikiEditTags": { + "type": "array", + "items": { "$ref": "#/MediawikiEditTag" } + }, + "MediawikiEditTag": { "type": "string" }, + "SitelinkMap": { + "type": "object", + "additionalProperties": { + "$ref": "./schemas.json#/Sitelink" + }, + "example": { + "afwiki": { + "site": "afwiki", + "title": "Douglas Adams", + "badges": [], + "url": "https://af.wikipedia.org/wiki/Douglas_Adams" + }, + "arwiki": { + "site": "arwiki", + "title": "دوغلاس آدمز", + "badges": [], + "url": "https://ar.wikipedia.org/wiki/%D8%AF%D9%88%D8%BA%D9%84%D8%A7%D8%B3_%D8%A2%D8%AF%D9%85%D8%B2" + } + } + }, + "Snak": { + "type": "object", + "properties": { + "snaktype": { + "type": "string" + }, + "property": { + "type": "string" + }, + "datatype": { + "type": "string" + }, + "datavalue": { + "type": "object", + "additionalProperties": true, + "example": { + "type" : "string", + "value" : "I am a goat" + } + } + } + }, + "SnakHash": { + "description": "Hash of a snak", + "type": "string", + "example": "455481eeac76e6a8af71a6b493c073d54788e7e9" + }, + "SnakList": { + "type": "array", + "items": { "$ref": "./interfaces.json#/Snak" } + }, + "SnakMap": { + "type": "object", + "additionalProperties": { + "$ref": "./interfaces.json#/SnakList" + }, + "example": { + "P31": [], + "P100": [] + } + }, + "StatementsBearing": { + "type": "object", + "properties": { + "statements": { + "type": "object" + } + }, + "required": [ + "statements" + ] + } +} \ No newline at end of file diff --git a/specs/global/payloads.json b/specs/global/payloads.json new file mode 100644 index 0000000..457ef74 --- /dev/null +++ b/specs/global/payloads.json @@ -0,0 +1,106 @@ +{ + "AliasList": { + "type": "array", + "items": { "$ref": "./schemas.json#/Term" } + }, + "DocumentPatch": { + "description": "A JSONPatch object as defined by RFC 6902", + "type": "object", + "properties": { + "op": { + "description": "The operation to perform", + "type": "string", + "enum": [ "add", "remove", "replace" ] + }, + "path": { + "description": "A JSON-Pointer for the property to manipulate", + "type": "string" + }, + "value": { + "description": "The value to be used within the operation" + } + }, + "required": ["op", "path"] + }, + "DocumentPatchList" : { + "description": "A list of JSONPatch objects as defined by RFC 6902", + "type": "array", + "items": { "$ref": "./payloads.json#/DocumentPatch" } + }, + "Error": { + "type": "object", + "properties": { + "code": { "type": "string" }, + "message": { "type": "string" } + }, + "required": [ "code", "message" ] + }, + "MediawikiEdit": { + "type": "object", + "properties": { + "comment": { + "$ref": "./interfaces.json#/MediawikiEditComment" + }, + "tags": { + "$ref": "./interfaces.json#/MediawikiEditTags" + } + } + }, + "MediawikiDeletion": { + "type": "object", + "properties": { + "reason": { + "$ref": "./interfaces.json#/MediawikiDeletionReason" + }, + "tags": { + "$ref": "./interfaces.json#/MediawikiEditTags" + } + } + }, + "NewQualifier": { + "$ref": "./interfaces.json#/Snak" + }, + "NewReference": { + "type": "object", + "properties": { + "snaks": { + "$ref": "./interfaces.json#/SnakMap" + } + } + }, + "NewReferences": { + "type": "array", + "items": { "$ref": "#/NewReference" } + }, + "NewStatement": { + "type": "object", + "properties": { + "mainsnak" : { + "$ref": "./interfaces.json#/Snak" + }, + "id": { + "type": "string" + }, + "rank": { + "type": "string" + }, + "qualifiers": { + "$ref": "./interfaces.json#/SnakMap" + }, + "references": { + "$ref": "#/NewReferences" + } + } + }, + "PersistedQualifiers": { + "$ref": "./interfaces.json#/HashedSnakMap" + }, + "PersistedReferences": { + "type": "array", + "items": { "$ref": "./schemas.json#/Reference" } + }, + "PersistedStatementList": { + "type": "array", + "items": { "$ref": "./schemas.json#/Statement" } + } +} \ No newline at end of file diff --git a/specs/global/requests.json b/specs/global/requests.json index fe7144b..de0c101 100644 --- a/specs/global/requests.json +++ b/specs/global/requests.json @@ -8,10 +8,10 @@ "allOf": [ { "type": "object", - "properties": { "patches": { "$ref": "./schemas.json#/DocumentPatchList" } } + "properties": { "patches": { "$ref": "./payloads.json#/DocumentPatchList" } } }, { - "$ref": "./schemas.json#/MediawikiEdit" + "$ref": "./payloads.json#/MediawikiEdit" } ] } @@ -27,10 +27,10 @@ "allOf": [ { "type": "object", - "properties": { "aliases": { "$ref": "./schemas.json#/AliasList" } } + "properties": { "aliases": { "$ref": "./payloads.json#/AliasList" } } }, { - "$ref": "./schemas.json#/MediawikiEdit" + "$ref": "./payloads.json#/MediawikiEdit" } ] } @@ -49,7 +49,7 @@ "properties": { "entity": { "$ref": "./schemas.json#/Entity" } } }, { - "$ref": "./schemas.json#/MediawikiEdit" + "$ref": "./payloads.json#/MediawikiEdit" } ] } @@ -57,7 +57,7 @@ } }, "Qualifier": { - "description": "A Wikibase Snak object", + "description": "A Wikibase qualifier object", "required": true, "content": { "application/json": { @@ -65,10 +65,10 @@ "allOf": [ { "type": "object", - "properties": { "snak": { "$ref": "./schemas.json#/Snak" } } + "properties": { "qualifier": { "$ref": "./payloads.json#/NewQualifier" } } }, { - "$ref": "./schemas.json#/MediawikiEdit" + "$ref": "./payloads.json#/MediawikiEdit" } ] } @@ -84,10 +84,10 @@ "allOf": [ { "type": "object", - "properties": { "statement": { "$ref": "./schemas.json#/Statement" } } + "properties": { "statement": { "$ref": "./payloads.json#/NewStatement" } } }, { - "$ref": "./schemas.json#/MediawikiEdit" + "$ref": "./payloads.json#/MediawikiEdit" } ] } @@ -103,11 +103,12 @@ "allOf": [ { "type": "object", - "properties": { "reference": { "$ref": "./schemas.json#/SnakMap" } } + "properties": { + "reference": { "$ref": "./payloads.json#/NewReference" } + } + }, - { - "$ref": "./schemas.json#/MediawikiEdit" - } + { "$ref": "./payloads.json#/MediawikiEdit" } ] } } @@ -125,7 +126,7 @@ "properties": { "sitelink": { "$ref": "./schemas.json#/Sitelink" } } }, { - "$ref": "./schemas.json#/MediawikiEdit" + "$ref": "./payloads.json#/MediawikiEdit" } ] } @@ -144,7 +145,7 @@ "properties": { "term": { "$ref": "./schemas.json#/Term" } } }, { - "$ref": "./schemas.json#/MediawikiEdit" + "$ref": "./payloads.json#/MediawikiEdit" } ] } @@ -156,7 +157,7 @@ "content": { "application/json": { "schema": { - "$ref": "./schemas.json#/MediawikiEdit" + "$ref": "./payloads.json#/MediawikiEdit" } } } @@ -166,7 +167,7 @@ "content": { "application/json": { "schema": { - "$ref": "./schemas.json#/MediawikiDeletion" + "$ref": "./payloads.json#/MediawikiDeletion" } } } diff --git a/specs/global/responses.json b/specs/global/responses.json index ecf3415..dccfc4e 100644 --- a/specs/global/responses.json +++ b/specs/global/responses.json @@ -37,7 +37,7 @@ "description": "The specified resource was not found", "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/Error" } + "schema": { "$ref": "./payloads.json#/Error" } } } }, @@ -45,7 +45,7 @@ "description": "An unexpected error has occurred", "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/Error" } + "schema": { "$ref": "./payloads.json#/Error" } } } }, @@ -53,7 +53,7 @@ "description": "An authentication error has occurred. This can happen due to missing authentication (i.e. no token presented) on resources which require it.", "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/Error" } + "schema": { "$ref": "./payloads.json#/Error" } } } }, @@ -61,7 +61,7 @@ "description": "An authorization error has occurred. This can happen if an authenticated user has insufficient privileges.", "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/Error" } + "schema": { "$ref": "./payloads.json#/Error" } } } }, @@ -123,7 +123,7 @@ "application/json": { "schema": { "properties": { - "aliases": { "$ref": "./schemas.json#/AliasList" } + "aliases": { "$ref": "./payloads.json#/AliasList" } } } } @@ -279,7 +279,7 @@ }, "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/SitelinkMap" } + "schema": { "$ref": "./interfaces.json#/SitelinkMap" } } } }, @@ -301,7 +301,7 @@ }, "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/PersistedStatement" } + "schema": { "$ref": "./schemas.json#/Statement" } } } }, @@ -325,7 +325,7 @@ "application/json": { "schema": { "properties": { - "statements": { "$ref": "./schemas.json#/PersistedStatementList" } + "statements": { "$ref": "./payloads.json#/PersistedStatementList" } } } } @@ -349,7 +349,7 @@ }, "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/HashedSnak" } + "schema": { "$ref": "./schemas.json#/Qualifier" } } } }, @@ -371,7 +371,7 @@ }, "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/PersistedQualifiers" } + "schema": { "$ref": "./payloads.json#/PersistedQualifiers" } } } }, @@ -393,7 +393,7 @@ }, "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/PersistedReference" } + "schema": { "$ref": "./schemas.json#/Reference" } } } }, @@ -415,7 +415,12 @@ }, "content": { "application/json": { - "schema": { "$ref": "./schemas.json#/PersistedReferences" } + "schema": { + "type": "object", + "properties": { + "references": { "$ref": "./payloads.json#/PersistedReferences" } + } + } } } } diff --git a/specs/global/schemas.json b/specs/global/schemas.json index 4bb87fb..964604d 100644 --- a/specs/global/schemas.json +++ b/specs/global/schemas.json @@ -34,7 +34,7 @@ "Aliases": { "type": "object", "additionalProperties": { - "$ref": "./schemas.json#/AliasList" + "$ref": "./payloads.json#/AliasList" }, "example": { "en": [ @@ -55,41 +55,20 @@ ] } }, - "AliasList": { - "type": "array", - "items": { "$ref": "./schemas.json#/Term" } - }, - "Error": { - "type": "object", - "properties": { - "code": { "type": "string" }, - "message": { "type": "string" } - }, - "required": [ "code", "message" ] - }, - "DocumentPatchList" : { - "description": "A list of JSONPatch objects as defined by RFC 6902", - "type": "array", - "items": { "$ref": "./schemas.json#/DocumentPatch" } - }, - "DocumentPatch": { - "description": "A JSONPatch object as defined by RFC 6902", + "Sitelink": { "type": "object", "properties": { - "op": { - "description": "The operation to perform", - "type": "string", - "enum": [ "add", "remove", "replace" ] + "site": { + "type": "string" }, - "path": { - "description": "A JSON-Pointer for the property to manipulate", + "title": { "type": "string" }, - "value": { - "description": "The value to be used within the operation" + "badges": { + "type": "array", + "items": { "type": "string" } } - }, - "required": ["op", "path"] + } }, "Item": { "allOf": [ @@ -97,15 +76,15 @@ "$ref": "./schemas.json#/Entity" }, { - "$ref": "./schemas.json#/Fingerprintable" + "$ref": "./interfaces.json#/Fingerprintable" }, { - "$ref": "./schemas.json#/StatementsBearing" + "$ref": "./interfaces.json#/StatementsBearing" }, { "type": "object", "properties": { - "sitelinks": { "$ref": "./schemas.json#/SitelinkMap" } + "sitelinks": { "$ref": "./interfaces.json#/SitelinkMap" } } } ] @@ -116,10 +95,10 @@ "$ref": "./schemas.json#/Entity" }, { - "$ref": "./schemas.json#/Fingerprintable" + "$ref": "./interfaces.json#/Fingerprintable" }, { - "$ref": "./schemas.json#/StatementsBearing" + "$ref": "./interfaces.json#/StatementsBearing" }, { "type": "object", @@ -134,36 +113,6 @@ } ] }, - "Fingerprintable": { - "type": "object", - "properties": { - "labels": { - "$ref": "./schemas.json#/Labels" - }, - "descriptions": { - "$ref": "./schemas.json#/Descriptions" - }, - "aliases": { - "$ref": "./schemas.json#/Aliases" - } - }, - "required": [ - "labels", - "descriptions", - "aliases" - ] - }, - "StatementsBearing": { - "type": "object", - "properties": { - "statements": { - "type": "object" - } - }, - "required": [ - "statements" - ] - }, "Entity": { "type": "object", "properties": { @@ -186,10 +135,6 @@ "propertyName": "type" } }, - "EntityList": { - "type": "array", - "items": { "$ref": "./schemas.json#/Entity" } - }, "Term": { "type": "object", "properties": { @@ -215,16 +160,14 @@ "type": "string", "example": "455481eeac76e6a8af71a6b493c073d54788e7e9" }, - "SnakHash": { - "description": "Hash of a snak", - "type": "string", - "example": "455481eeac76e6a8af71a6b493c073d54788e7e9" + "Snak":{ + "$ref": "./interfaces.json#/Snak" }, "Statement": { "type": "object", "properties": { "mainsnak" : { - "$ref": "./schemas.json#/Snak" + "$ref": "#/Snak" }, "id": { "type": "string" @@ -233,208 +176,31 @@ "type": "string" }, "qualifiers": { - "$ref": "./schemas.json#/Qualifiers" + "$ref": "./interfaces.json#/HashedSnakMap" }, "references": { - "$ref": "./schemas.json#/References" - } - } - }, - "StatementList": { - "type": "array", - "items": { "$ref": "./schemas.json#/Statement" } - }, - "Sitelink": { - "type": "object", - "properties": { - "site": { - "type": "string" - }, - "title": { - "type": "string" - }, - "badges": { "type": "array", - "items": { "type": "string" } - } - } - }, - "SitelinkMap": { - "type": "object", - "additionalProperties": { - "$ref": "./schemas.json#/Sitelink" - }, - "example": { - "afwiki": { - "site": "afwiki", - "title": "Douglas Adams", - "badges": [], - "url": "https://af.wikipedia.org/wiki/Douglas_Adams" - }, - "arwiki": { - "site": "arwiki", - "title": "دوغلاس آدمز", - "badges": [], - "url": "https://ar.wikipedia.org/wiki/%D8%AF%D9%88%D8%BA%D9%84%D8%A7%D8%B3_%D8%A2%D8%AF%D9%85%D8%B2" - } - } - }, - "Snak": { - "type": "object", - "properties": { - "snaktype": { - "type": "string" - }, - "property": { - "type": "string" - }, - "datatype": { - "type": "string" - }, - "datavalue": { - "type": "object", - "additionalProperties": true, - "example": { - "type" : "string", - "value" : "I am a goat" - } + "items": { "$ref": "./schemas.json#/Reference" } } } }, - "SnakList": { - "type": "array", - "items": { "$ref": "./schemas.json#/Snak" } - }, - "SnakMap": { - "type": "object", - "additionalProperties": { - "$ref": "./schemas.json#/SnakList" - }, - "example": { - "P31": [], - "P100": [] - } - }, - "SnakMapList": { - "type": "array", - "items": { "$ref": "./schemas.json#/SnakMap" } - }, - "MediawikiEditComment": { "type": "string" }, - "MediawikiDeletionReason": { "type": "string" }, - "MediawikiEditTags": { - "type": "array", - "items": { "$ref": "./schemas.json#/MediawikiEditTag" } - }, - "MediawikiEditTag": { "type": "string" }, - "MediawikiEdit": { - "type": "object", - "properties": { - "comment": { - "$ref": "./schemas.json#/MediawikiEditComment" - }, - "tags": { - "$ref": "./schemas.json#/MediawikiEditTags" - } - } - }, - "MediawikiDeletion": { - "type": "object", - "properties": { - "reason": { - "$ref": "./schemas.json#/MediawikiDeletionReason" - }, - "tags": { - "$ref": "./schemas.json#/MediawikiEditTags" - } - } - }, - "Qualifiers": { - "$ref": "./schemas.json#/SnakMap" - }, - "References": { - "type": "array", - "items": { "$ref": "./schemas.json#/Reference" } - }, - "Reference": { - "type": "object", - "properties": { - "snaks": { - "$ref": "./schemas.json#/SnakMap" - } - } - }, - "PersistedStatementList": { - "type": "array", - "items": { "$ref": "./schemas.json#/PersistedStatement" } - }, - "PersistedStatement": { - "type": "object", - "properties": { - "mainsnak" : { - "$ref": "./schemas.json#/HashedSnak" - }, - "id": { - "type": "string" - }, - "rank": { - "type": "string" - }, - "qualifiers": { - "$ref": "./schemas.json#/PersistedQualifiers" - }, - "references": { - "$ref": "./schemas.json#/PersistedReferences" - } - } - }, - "PersistedReference": { + "Qualifier": { "allOf": [ - { - "$ref": "./schemas.json#/Reference" - }, - { - "type": "object", - "properties": { "hash": { "$ref": "./schemas.json#/ReferenceHash" } } - } - ], - "example": { - "hash": "", - "snaks": { - "P31": [], - "P100": [] - } - } - }, - "PersistedReferences": { - "type": "array", - "items": { "$ref": "./schemas.json#/PersistedReference" } - }, - "PersistedQualifiers": { - "$ref": "./schemas.json#/HashedSnakMap" + { "$ref": "./interfaces.json#/HashBearing"}, + { "$ref": "./interfaces.json#/Snak" } + ] }, - "HashedSnak": { + "Reference": { "allOf": [ - { - "$ref": "./schemas.json#/Snak" - }, + { "$ref": "./interfaces.json#/HashBearing"}, { "type": "object", - "properties": { "hash": { "$ref": "./schemas.json#/SnakHash" } } + "properties": { + "snaks": { + "$ref": "./interfaces.json#/HashedSnakMap" + } + } } ] - }, - "HashedSnakList": { - "type": "array", - "items": { "$ref": "./schemas.json#/HashedSnak" } - }, - "HashedSnakMap": { - "type": "object", - "additionalProperties": { - "$ref": "./schemas.json#/HashedSnakList" - }, - "example": { - "P31": [], - "P100": [] - } - } + } } \ No newline at end of file diff --git a/specs/paths/statements/qualifiers/list.json b/specs/paths/statements/qualifiers/list.json index a25ee78..751ccb4 100644 --- a/specs/paths/statements/qualifiers/list.json +++ b/specs/paths/statements/qualifiers/list.json @@ -13,7 +13,7 @@ { "$ref": "../../../global/parameters.json#/ifModifiedSince" } ], "responses": { - "200": { "$ref": "../../../global/responses.json#/Qualifier" }, + "200": { "$ref": "../../../global/responses.json#/Qualifiers" }, "304": { "$ref": "../../../global/responses.json#/NotModified" }, "404": { "$ref": "../../../global/responses.json#/NotFound" }, "default": { "$ref": "../../../global/responses.json#/UnexpectedError" }