Skip to content

Commit 608a7ef

Browse files
outdooracornjakobw
authored andcommitted
Search: Build OpenAPI Definition using JavaScript
Copies the existing structure for now for simplicity and easy understanding The openapi.json file can be validated to be semantically the same (e.g. with a tool like https://jsondiff.com) Continue to use `$ref`s to `#/components` where feasible, to reduce the size of the OAD and increase readability Bug: T379912 Change-Id: I8b2be98df2d6085d66e8627f19f63d51463f1020
1 parent d46de1c commit 608a7ef

File tree

11 files changed

+254
-198
lines changed

11 files changed

+254
-198
lines changed

repo/domains/search/.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ module.exports = {
1717
"max-len": [ "warn", { code: 130 } ],
1818
"no-implicit-coercion": [ "error", { disallowTemplateShorthand: true } ],
1919
"no-console": "error",
20-
"template-curly-spacing": 'off',
20+
"template-curly-spacing": "off",
2121
},
2222
overrides: [
2323
{
2424
files: [ "*.json" ],
25+
parser: "eslint-plugin-json-es",
26+
extends: "plugin:eslint-plugin-json-es/recommended",
2527
rules: {
2628
"max-len": "off",
2729
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
module.exports = {
4+
"rules": { },
5+
"overrides": [
6+
{
7+
"files": [ "*.js" ],
8+
"rules": {
9+
"brace-style": [ "warn", "1tbs", { "allowSingleLine": true } ],
10+
"semi": [ "error", "always", { "omitLastInOneLineBlock": true } ],
11+
// disable for now - easier to switch from JSON to JS if we aren't fussy about quotes
12+
"quotes": "off",
13+
"quote-props": "off",
14+
}
15+
},
16+
]
17+
};

repo/domains/search/specs/global/parameters.json renamed to repo/domains/search/specs/global/parameters.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{
1+
'use strict';
2+
3+
module.exports = {
24
"SearchQuery": {
35
"in": "query",
46
"name": "q",
@@ -42,4 +44,4 @@
4244
},
4345
"example": 4
4446
}
45-
}
47+
};

repo/domains/search/specs/global/responses.json renamed to repo/domains/search/specs/global/responses.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
{
1+
'use strict';
2+
3+
const schemaParts = require( './schema-parts' );
4+
5+
module.exports = {
26
"BadRequest": {
37
"description": "The request cannot be processed",
48
"content": {
@@ -36,7 +40,7 @@
3640
"description": "A list of search results",
3741
"content": {
3842
"application/json": {
39-
"schema": { "$ref": "./schema-parts.json#/SearchItemResultList" },
43+
"schema": schemaParts.SearchItemResultList,
4044
"example": {
4145
"results": [
4246
{
@@ -60,7 +64,7 @@
6064
"description": "A list of search results",
6165
"content": {
6266
"application/json": {
63-
"schema": { "$ref": "./schema-parts.json#/SearchPropertyResultList" },
67+
"schema": schemaParts.SearchPropertyResultList,
6468
"example": {
6569
"results": [
6670
{
@@ -80,4 +84,4 @@
8084
}
8185
}
8286
}
83-
}
87+
};
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict';
2+
3+
const DisplayLabel = {
4+
"type": [ "object", "null" ],
5+
"properties": {
6+
"language": { "type": "string" },
7+
"value": { "type": "string" }
8+
},
9+
"additionalProperties": false,
10+
"required": [ "language", "value" ],
11+
};
12+
13+
const Description = {
14+
"type": [ "object", "null" ],
15+
"properties": {
16+
"language": { "type": "string" },
17+
"value": { "type": "string" }
18+
},
19+
"additionalProperties": false,
20+
"required": [ "language", "value" ],
21+
};
22+
23+
const Match = {
24+
"type": "object",
25+
"properties": {
26+
"type": { "type": "string" },
27+
"language": { "type": "string" },
28+
"text": { "type": "string" }
29+
},
30+
"additionalProperties": false,
31+
"required": [ "type", "text" ],
32+
};
33+
34+
const SearchItemResult = {
35+
"type": "object",
36+
"properties": {
37+
"id": {
38+
"type": "string",
39+
"pattern": "^Q[1-9]\\d{0,9}$"
40+
},
41+
"display-label": DisplayLabel,
42+
"description": Description,
43+
"match": Match
44+
},
45+
"additionalProperties": false,
46+
"required": [ "id", "display-label", "description", "match" ],
47+
};
48+
49+
const SearchPropertyResult = {
50+
"type": "object",
51+
"properties": {
52+
"id": {
53+
"type": "string",
54+
"pattern": "^P[1-9]\\d{0,9}$"
55+
},
56+
"display-label": DisplayLabel,
57+
"description": Description,
58+
"match": Match
59+
},
60+
"additionalProperties": false,
61+
"required": [ "id", "display-label", "description", "match" ],
62+
};
63+
64+
const SearchItemResultList = {
65+
"type": "object",
66+
"properties": {
67+
"results": {
68+
"type": "array",
69+
"items": SearchItemResult,
70+
}
71+
},
72+
"additionalProperties": false,
73+
"required": [ "results" ],
74+
};
75+
76+
const SearchPropertyResultList = {
77+
"type": "object",
78+
"properties": {
79+
"results": {
80+
"type": "array",
81+
"items": SearchPropertyResult,
82+
}
83+
},
84+
"additionalProperties": false,
85+
"required": [ "results" ],
86+
};
87+
88+
module.exports = {
89+
SearchItemResultList,
90+
SearchPropertyResultList,
91+
};

repo/domains/search/specs/global/schema-parts.json

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
'use strict';
2+
3+
const parameters = require( './global/parameters' );
4+
5+
const openapi = {
6+
"openapi": "3.1.0",
7+
"info": {
8+
"title": "Wikibase Search Domain REST API",
9+
"version": "0.1",
10+
"description": "OpenAPI fragment of the Wikibase Search domain REST API"
11+
},
12+
"tags": [
13+
{
14+
"name": "item search",
15+
"description": "Simple item search"
16+
},
17+
{
18+
"name": "property search",
19+
"description": "Simple property search"
20+
}
21+
],
22+
"paths": {
23+
"/v0/search/items": {
24+
"get": {
25+
"operationId": "simpleItemSearch",
26+
"tags": [ "item search" ],
27+
"summary": "Simple Item search by label and aliases",
28+
"parameters": [
29+
{
30+
...parameters.SearchQuery,
31+
"example": "potato"
32+
},
33+
{ "$ref": "#/components/parameters/SearchLanguage" },
34+
{ "$ref": "#/components/parameters/Limit" },
35+
{ "$ref": "#/components/parameters/Offset" },
36+
],
37+
"responses": {
38+
"200": { "$ref": "#/components/responses/SearchItemSuccess" },
39+
"400": { "$ref": "#/components/responses/BadRequest" }
40+
}
41+
}
42+
},
43+
"/v0/search/properties": {
44+
"get": {
45+
"operationId": "simplePropertySearch",
46+
"tags": [ "property search" ],
47+
"summary": "Simple Property search by label and aliases",
48+
"parameters": [
49+
{
50+
...parameters.SearchQuery,
51+
"example": "taxon"
52+
},
53+
{ "$ref": "#/components/parameters/SearchLanguage" },
54+
{ "$ref": "#/components/parameters/Limit" },
55+
{ "$ref": "#/components/parameters/Offset" },
56+
],
57+
"responses": {
58+
"200": { "$ref": "#/components/responses/SearchPropertySuccess" },
59+
"400": { "$ref": "#/components/responses/BadRequest" }
60+
}
61+
}
62+
}
63+
},
64+
"components": {
65+
"parameters": require( './global/parameters' ),
66+
"responses": require( './global/responses' ),
67+
},
68+
};
69+
70+
// export the definition for use in other modules (useful in mocha tests and helpers, for example)
71+
module.exports = { openapi };
72+
73+
if ( require.main === module ) {
74+
// if executed directly, print the definition
75+
console.log( JSON.stringify( openapi, null, 2 ) ); // eslint-disable-line no-console
76+
}

repo/domains/search/specs/index.fragment.json

Lines changed: 0 additions & 60 deletions
This file was deleted.

repo/rest-api/.redocly.lint-ignore.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ specs/openapi-joined.json:
55
- '#/paths/~1v1~1openapi.json/get/responses'
66
- '#/paths/~1v1~1property-data-types/get/responses'
77
- '#/paths/~1v0~1search~1items/get/responses'
8+
9+
# temporarily ignore
10+
no-unused-components:
11+
- '#/components/parameters/SearchQuery'

0 commit comments

Comments
 (0)