Skip to content

Commit 459ac43

Browse files
committed
Add redirect feature schema types
1 parent 7f7aa98 commit 459ac43

File tree

3 files changed

+104
-6
lines changed

3 files changed

+104
-6
lines changed

schemas/data.schema.json

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@
4444
"description": "Feature identifiers and data",
4545
"type": "object",
4646
"additionalProperties": {
47-
"$ref": "#/definitions/FeatureData"
47+
"oneOf": [
48+
{
49+
"$ref": "#/definitions/FeatureData"
50+
},
51+
{
52+
"$ref": "#/definitions/FeatureMovedData"
53+
},
54+
{
55+
"$ref": "#/definitions/FeatureSplitData"
56+
}
57+
]
4858
}
4959
},
5060
"groups": {
@@ -176,6 +186,50 @@
176186
"required": ["version", "date"],
177187
"additionalProperties": false
178188
},
189+
"FeatureMovedData": {
190+
"description": "A feature has permanently moved to exactly one other ID",
191+
"type": "object",
192+
"properties": {
193+
"redirect": {
194+
"type": "object",
195+
"properties": {
196+
"reason": {
197+
"const": "moved"
198+
},
199+
"target": {
200+
"description": "The new ID for this feature",
201+
"type": "string"
202+
}
203+
},
204+
"required": ["reason", "target"],
205+
"additionalProperties": false
206+
}
207+
},
208+
"required": ["redirect"],
209+
"additionalProperties": false
210+
},
211+
"FeatureSplitData": {
212+
"description": "A feature has split into two or more other features",
213+
"type": "object",
214+
"properties": {
215+
"redirect": {
216+
"type": "object",
217+
"properties": {
218+
"reason": {
219+
"const": "split"
220+
},
221+
"targets": {
222+
"description": "The new IDs for this feature",
223+
"$ref": "#/definitions/Strings"
224+
}
225+
},
226+
"required": ["reason", "targets"],
227+
"additionalProperties": false
228+
}
229+
},
230+
"required": ["redirect"],
231+
"additionalProperties": false
232+
},
179233
"Status": {
180234
"type": "object",
181235
"properties": {

types.quicktype.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export interface Release {
6060

6161
/**
6262
* A feature data entry
63+
*
64+
* A feature has permanently moved to exactly one other ID
65+
*
66+
* A feature has split into two or more other features
6367
*/
6468
export interface FeatureData {
6569
/**
@@ -73,11 +77,11 @@ export interface FeatureData {
7377
/**
7478
* Short description of the feature, as a plain text string
7579
*/
76-
description: string;
80+
description?: string;
7781
/**
7882
* Short description of the feature, as an HTML string
7983
*/
80-
description_html: string;
84+
description_html?: string;
8185
/**
8286
* Whether developers are formally discouraged from using this feature
8387
*/
@@ -89,20 +93,21 @@ export interface FeatureData {
8993
/**
9094
* Short name
9195
*/
92-
name: string;
96+
name?: string;
9397
/**
9498
* Snapshot identifier(s)
9599
*/
96100
snapshot?: string[] | string;
97101
/**
98102
* Specification URL(s)
99103
*/
100-
spec: string[] | string;
104+
spec?: string[] | string;
101105
/**
102106
* Whether a feature is considered a "Baseline" web platform feature and when it achieved
103107
* that status
104108
*/
105109
status?: StatusHeadline;
110+
redirect?: Redirect;
106111
[property: string]: any;
107112
}
108113

@@ -121,6 +126,20 @@ export interface Discouraged {
121126
alternatives?: string[];
122127
}
123128

129+
export interface Redirect {
130+
reason: Reason;
131+
/**
132+
* The new ID for this feature
133+
*/
134+
target?: string;
135+
/**
136+
* The new IDs for this feature
137+
*/
138+
targets?: string[];
139+
}
140+
141+
export type Reason = "moved" | "split";
142+
124143
/**
125144
* Whether a feature is considered a "Baseline" web platform feature and when it achieved
126145
* that status

types.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
GroupData,
1212
FeatureData as QuicktypeMonolithicFeatureData,
1313
WebFeaturesData as QuicktypeWebFeaturesData,
14+
Redirect,
1415
Release,
1516
SnapshotData,
1617
Status,
@@ -34,7 +35,9 @@ export type {
3435

3536
export interface WebFeaturesData
3637
extends Pick<QuicktypeWebFeaturesData, "browsers" | "groups" | "snapshots"> {
37-
features: { [key: string]: FeatureData };
38+
features: {
39+
[key: string]: FeatureData | FeatureMovedData | FeatureSplitData;
40+
};
3841
}
3942

4043
export type FeatureData = Required<
@@ -50,6 +53,28 @@ export type FeatureData = Required<
5053
>
5154
>;
5255

56+
export type FeatureRedirectData = Required<
57+
Pick<QuicktypeMonolithicFeatureData, "redirect">
58+
>;
59+
60+
export interface Moved extends Exclude<Redirect, "targets"> {
61+
reason: "moved";
62+
target: Redirect["target"];
63+
}
64+
65+
export interface Split extends Exclude<Redirect, "target"> {
66+
reason: "split";
67+
targets: Redirect["targets"];
68+
}
69+
70+
export interface FeatureMovedData extends FeatureRedirectData {
71+
redirect: Moved;
72+
}
73+
74+
export interface FeatureSplitData extends FeatureRedirectData {
75+
redirect: Split;
76+
}
77+
5378
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5479
const t1: FeatureData = {
5580
name: "Test",

0 commit comments

Comments
 (0)