Skip to content

Commit

Permalink
chore: Support new structure of web features data.json
Browse files Browse the repository at this point in the history
The Web Features repo changed the structure of the data.json in this PR: web-platform-dx/web-features#1060

Instead of being a map of features, it is now an object with three top level keys:
- features
- groups
- snapshots

This is a breaking change and has caused us to start ingesting features as if they had IDs: features, groups, snapshots

This commit fixes that by updating the defs.schema.json to be the latest version (v0.10.0). This file comes from the web features repo.

After auto-generating the code for that schema file, this commit adjusts the code to use it.

We previously had v0.6.0 of the schema. And since then, some optional fields have become required fields. So you will see the
removal of some nil checks (since now the field is not nullable).

Change-Id: I9861421bc53ec8966eee80c33742d2a7e94d744c
  • Loading branch information
jcscottiii committed Jul 16, 2024
1 parent 6f069fc commit b296237
Show file tree
Hide file tree
Showing 10 changed files with 544 additions and 218 deletions.
124 changes: 102 additions & 22 deletions jsonschema/web-platform-dx_web-features/defs.schema.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"$id": "defs",
"$ref": "#/definitions/FeatureData",
"$ref": "#/definitions/WebFeaturesData",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"FeatureData": {
"additionalProperties": false,
"description": "Web platform feature",
"properties": {
"alias": {
"anyOf": [
Expand Down Expand Up @@ -52,10 +51,40 @@
"description": "Short description of the feature, as an HTML string",
"type": "string"
},
"group": {
"anyOf": [
{
"type": "string"
},
{
"items": {
"type": "string"
},
"minItems": 2,
"type": "array"
}
],
"description": "Group identifier"
},
"name": {
"description": "Short name",
"type": "string"
},
"snapshot": {
"anyOf": [
{
"type": "string"
},
{
"items": {
"type": "string"
},
"minItems": 2,
"type": "array"
}
],
"description": "Snapshot identifier"
},
"spec": {
"anyOf": [
{
Expand Down Expand Up @@ -135,37 +164,88 @@
}
},
"required": [
"baseline"
"baseline",
"support"
],
"type": "object"
},
"usage_stats": {
"anyOf": [
{
"description": "Usage stats URL",
"format": "uri",
"type": "string"
},
{
"items": {
"description": "Usage stats URL",
"format": "uri",
"type": "string"
},
"minItems": 2,
"type": "array"
}
],
"description": "Usage stats"
}
},
"required": [
"name",
"description",
"description_html",
"spec",
"status"
],
"type": "object"
},
"GroupData": {
"additionalProperties": false,
"properties": {
"name": {
"description": "Short name",
"type": "string"
},
"parent": {
"description": "Identifier of parent group",
"type": "string"
}
},
"required": [
"name"
],
"type": "object"
},
"SnapshotData": {
"additionalProperties": false,
"properties": {
"name": {
"description": "Short name",
"type": "string"
},
"spec": {
"description": "Specification",
"format": "uri",
"type": "string"
}
},
"required": [
"name",
"spec"
],
"type": "object"
},
"WebFeaturesData": {
"additionalProperties": false,
"properties": {
"features": {
"additionalProperties": {
"$ref": "#/definitions/FeatureData"
},
"description": "Feature identifiers and data",
"type": "object"
},
"groups": {
"additionalProperties": {
"$ref": "#/definitions/GroupData"
},
"description": "Group identifiers and data",
"type": "object"
},
"snapshots": {
"additionalProperties": {
"$ref": "#/definitions/SnapshotData"
},
"description": "Snapshot identifiers and data",
"type": "object"
}
},
"required": [
"features",
"groups",
"snapshots"
],
"type": "object"
}
}
}
67 changes: 32 additions & 35 deletions lib/gcpspanner/spanneradapters/web_features_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type WebFeaturesConsumer struct {

func (c *WebFeaturesConsumer) InsertWebFeatures(
ctx context.Context,
data map[string]web_platform_dx__web_features.FeatureData) (map[string]string, error) {
data map[string]web_platform_dx__web_features.FeatureValue) (map[string]string, error) {
ret := make(map[string]string, len(data))
for featureID, featureData := range data {
webFeature := gcpspanner.WebFeature{
Expand All @@ -65,10 +65,9 @@ func (c *WebFeaturesConsumer) InsertWebFeatures(
LowDate: nil,
HighDate: nil,
}
if featureData.Status != nil {
featureBaselineStatus.LowDate = convertStringToDate(featureData.Status.BaselineLowDate)
featureBaselineStatus.HighDate = convertStringToDate(featureData.Status.BaselineHighDate)
}

featureBaselineStatus.LowDate = convertStringToDate(featureData.Status.BaselineLowDate)
featureBaselineStatus.HighDate = convertStringToDate(featureData.Status.BaselineHighDate)

err = c.client.UpsertFeatureBaselineStatus(ctx, featureID, featureBaselineStatus)
if err != nil {
Expand Down Expand Up @@ -105,7 +104,7 @@ func (c *WebFeaturesConsumer) InsertWebFeatures(
func consumeFeatureSpecInformation(ctx context.Context,
client WebFeatureSpannerClient,
featureID string,
featureData web_platform_dx__web_features.FeatureData) error {
featureData web_platform_dx__web_features.FeatureValue) error {
if featureData.Spec == nil {
return nil
}
Expand Down Expand Up @@ -139,34 +138,32 @@ func consumeFeatureSpecInformation(ctx context.Context,
}

func extractBrowserAvailability(
featureData web_platform_dx__web_features.FeatureData) []gcpspanner.BrowserFeatureAvailability {
featureData web_platform_dx__web_features.FeatureValue) []gcpspanner.BrowserFeatureAvailability {
var fba []gcpspanner.BrowserFeatureAvailability
if featureData.Status != nil && featureData.Status.Support != nil {
support := featureData.Status.Support
if support.Chrome != nil {
fba = append(fba, gcpspanner.BrowserFeatureAvailability{
BrowserName: "chrome",
BrowserVersion: *support.Chrome,
})
}
if support.Edge != nil {
fba = append(fba, gcpspanner.BrowserFeatureAvailability{
BrowserName: "edge",
BrowserVersion: *support.Edge,
})
}
if support.Firefox != nil {
fba = append(fba, gcpspanner.BrowserFeatureAvailability{
BrowserName: "firefox",
BrowserVersion: *support.Firefox,
})
}
if support.Safari != nil {
fba = append(fba, gcpspanner.BrowserFeatureAvailability{
BrowserName: "safari",
BrowserVersion: *support.Safari,
})
}
support := featureData.Status.Support
if support.Chrome != nil {
fba = append(fba, gcpspanner.BrowserFeatureAvailability{
BrowserName: "chrome",
BrowserVersion: *support.Chrome,
})
}
if support.Edge != nil {
fba = append(fba, gcpspanner.BrowserFeatureAvailability{
BrowserName: "edge",
BrowserVersion: *support.Edge,
})
}
if support.Firefox != nil {
fba = append(fba, gcpspanner.BrowserFeatureAvailability{
BrowserName: "firefox",
BrowserVersion: *support.Firefox,
})
}
if support.Safari != nil {
fba = append(fba, gcpspanner.BrowserFeatureAvailability{
BrowserName: "safari",
BrowserVersion: *support.Safari,
})
}

return fba
Expand All @@ -190,8 +187,8 @@ func convertStringToDate(in *string) *time.Time {
}

// getBaselineStatusEnum converts the web feature status to the Spanner-compatible BaselineStatus type.
func getBaselineStatusEnum(status *web_platform_dx__web_features.Status) *gcpspanner.BaselineStatus {
if status == nil || status.Baseline == nil {
func getBaselineStatusEnum(status web_platform_dx__web_features.Status) *gcpspanner.BaselineStatus {
if status.Baseline == nil {
return nil
}
if status.Baseline.Enum != nil {
Expand Down
Loading

0 comments on commit b296237

Please sign in to comment.