Skip to content

Commit 7b71997

Browse files
authored
Change schema string | string[] properties to string[] (#3184)
1 parent b3b99ea commit 7b71997

File tree

5 files changed

+44
-60
lines changed

5 files changed

+44
-60
lines changed

index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ for (const [key, data] of yamlEntries('features')) {
137137
data.kind = "feature";
138138
}
139139

140+
// Upgrade authored strings to arrays of 1
141+
const optionalArrays = [
142+
"spec",
143+
"group",
144+
"snapshot",
145+
"caniuse",
146+
"foo"
147+
];
148+
const stringToStringArray = (value: string | string[]) => typeof value === "string" ? [value] : value;
149+
for (const optionalArray of optionalArrays) {
150+
const value = data[optionalArray];
151+
if (value) {
152+
data[optionalArray] = stringToStringArray(value);
153+
}
154+
}
155+
if (data.discouraged) {
156+
const value = data.discouraged.according_to;
157+
if (value) {
158+
data.discouraged.according_to = stringToStringArray(value);
159+
}
160+
}
161+
140162
// Convert markdown to text+HTML.
141163
if (data.description) {
142164
const { text, html } = convertMarkdown(data.description);

packages/web-features/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ It has the following properties:
7979
- `name` (type: `string`): A plain-text human-readable name for the feature
8080
- `description` (type: `string`): A short plain-text description of the feature
8181
- `description_html` (type: `string`): A short HTML-formatted description of the feature
82-
- `spec` (type: `string | string[]`): A specification URL or an array of them
82+
- `spec` (type: `string[]`): A specification URL or an array of them
8383
- `status`: Support status data.
8484
It has the following properties:
8585

@@ -91,9 +91,9 @@ It has the following properties:
9191
Keys are one of: `"chrome"`, `"chrome_android"`, `"edge"`, `"firefox"`, `"firefox"`, `"firefox_android"`, `"safari"`, `"safari_ios"`.
9292
Each value is a `string` containing the version number.
9393

94-
- `group` (optional, type: `string | string[]`): A `groups` key or an array of them
95-
- `snapshot` (optional, type: `string | string[]`): A `snapshots` key or an array of them
96-
- `caniuse` (optional, type: `string | string[]`): A caniuse feature ID that corresponds to the current feature, or an array of them.
94+
- `group` (optional, type: `string[]`): A `groups` key or an array of them
95+
- `snapshot` (optional, type: `string[]`): A `snapshots` key or an array of them
96+
- `caniuse` (optional, type: `string[]`): A caniuse feature ID that corresponds to the current feature, or an array of them.
9797
Use it to look up caniuse data from a package like [`caniuse-lite`](https://www.npmjs.com/package/caniuse-lite) or construct a URL to a page on caniuse.com.
9898
- `compat_features` (optional, type: `string[]`): An array of `@mdn/browser-compat-data` feature key strings.
9999
- `discouraged` (optional): An object indicating that web developers should avoid using the feature.

schemas/data.schema.json

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"properties": {
8282
"according_to": {
8383
"description": "Links to a formal discouragement notice, such as specification text, intent-to-unship, etc.",
84-
"$ref": "#/definitions/URLs"
84+
"$ref": "#/definitions/Strings"
8585
},
8686
"alternatives": {
8787
"description": "IDs for features that substitute some or all of this feature's utility",
@@ -129,20 +129,20 @@
129129
"type": "string"
130130
},
131131
"spec": {
132-
"description": "Specification URL(s)",
133-
"$ref": "#/definitions/URLOrURLs"
132+
"description": "Specification URLs",
133+
"$ref": "#/definitions/Strings"
134134
},
135135
"group": {
136-
"description": "Group identifier(s)",
137-
"$ref": "#/definitions/StringOrStrings"
136+
"description": "Group identifiers",
137+
"$ref": "#/definitions/Strings"
138138
},
139139
"snapshot": {
140-
"description": "Snapshot identifier(s)",
141-
"$ref": "#/definitions/StringOrStrings"
140+
"description": "Snapshot identifiers",
141+
"$ref": "#/definitions/Strings"
142142
},
143143
"caniuse": {
144-
"description": "caniuse.com identifier(s)",
145-
"$ref": "#/definitions/StringOrStrings"
144+
"description": "caniuse.com identifiers",
145+
"$ref": "#/definitions/Strings"
146146
},
147147
"compat_features": {
148148
"description": "Sources of support data for this feature",
@@ -308,50 +308,12 @@
308308
"required": ["baseline", "support"],
309309
"additionalProperties": false
310310
},
311-
"StringOrStrings": {
312-
"oneOf": [
313-
{
314-
"type": "string"
315-
},
316-
{
317-
"type": "array",
318-
"items": {
319-
"type": "string"
320-
},
321-
"minItems": 2
322-
}
323-
]
324-
},
325311
"Strings": {
326312
"type": "array",
327313
"items": {
328314
"type": "string"
329315
},
330316
"minItems": 1
331-
},
332-
"URL": {
333-
"type": "string"
334-
},
335-
"URLs": {
336-
"type": "array",
337-
"items": {
338-
"type": "string"
339-
},
340-
"minItems": 1
341-
},
342-
"URLOrURLs": {
343-
"oneOf": [
344-
{
345-
"type": "string"
346-
},
347-
{
348-
"type": "array",
349-
"items": {
350-
"type": "string"
351-
},
352-
"minItems": 2
353-
}
354-
]
355317
}
356318
}
357319
}

types.quicktype.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export interface Release {
6767
*/
6868
export interface FeatureData {
6969
/**
70-
* caniuse.com identifier(s)
70+
* caniuse.com identifiers
7171
*/
72-
caniuse?: string[] | string;
72+
caniuse?: string[];
7373
/**
7474
* Sources of support data for this feature
7575
*/
@@ -87,22 +87,22 @@ export interface FeatureData {
8787
*/
8888
discouraged?: Discouraged;
8989
/**
90-
* Group identifier(s)
90+
* Group identifiers
9191
*/
92-
group?: string[] | string;
92+
group?: string[];
9393
kind: Kind;
9494
/**
9595
* Short name
9696
*/
9797
name?: string;
9898
/**
99-
* Snapshot identifier(s)
99+
* Snapshot identifiers
100100
*/
101-
snapshot?: string[] | string;
101+
snapshot?: string[];
102102
/**
103-
* Specification URL(s)
103+
* Specification URLs
104104
*/
105-
spec?: string[] | string;
105+
spec?: string[];
106106
/**
107107
* Whether a feature is considered a "Baseline" web platform feature and when it achieved
108108
* that status

types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const goodFeatureData: FeatureData = {
9090
name: "Test",
9191
description: "Hi",
9292
description_html: "Hi",
93-
spec: "",
93+
spec: [""],
9494
status: {
9595
baseline: false,
9696
support: {},

0 commit comments

Comments
 (0)