-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init jsonschema catalog (#113)
* feat: init jsonschema catalog Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> * feat: sort catalog entries Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> * fix: update catalog after merging other pr Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
- Loading branch information
Showing
6 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/schema-catalog", | ||
"version": 1, | ||
"schemas": [ | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json", | ||
"name": "MessagePublishedData", | ||
"description": "The data received in an event when a message is published to a topic.", | ||
"datatype": "google.events.cloud.pubsub.v1.MessagePublishedData", | ||
"cloudeventTypes": [ | ||
"google.cloud.pubsub.topic.v1.messagePublished" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/audit/v1/LogEntryData.json", | ||
"name": "LogEntryData", | ||
"description": "Generic log entry, used as a wrapper for Cloud Audit Logs in events.\n This is copied from\n https://github.com/googleapis/googleapis/blob/master/google/logging/v2/log_entry.proto\n and adapted appropriately.", | ||
"datatype": "google.events.cloud.audit.v1.LogEntryData", | ||
"cloudeventTypes": [ | ||
"google.cloud.audit.log.v1.written" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json", | ||
"name": "BuildEventData", | ||
"description": "Build event data\n Common build format for Google Cloud Platform API operations.\n Copied from\n https://github.com/googleapis/googleapis/blob/master/google/devtools/cloudbuild/v1/cloudbuild.proto.", | ||
"datatype": "google.events.cloud.cloudbuild.v1.BuildEventData", | ||
"cloudeventTypes": [ | ||
"google.cloud.cloudbuild.build.v1.statusChanged" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json", | ||
"name": "SchedulerJobData", | ||
"description": "Scheduler job data.", | ||
"datatype": "google.events.cloud.scheduler.v1.SchedulerJobData", | ||
"cloudeventTypes": [ | ||
"google.cloud.scheduler.job.v1.executed" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json", | ||
"name": "StorageObjectData", | ||
"description": "An object within Google Cloud Storage.", | ||
"datatype": "google.events.cloud.storage.v1.StorageObjectData", | ||
"cloudeventTypes": [ | ||
"google.cloud.storage.object.v1.finalized", | ||
"google.cloud.storage.object.v1.archived", | ||
"google.cloud.storage.object.v1.deleted", | ||
"google.cloud.storage.object.v1.metadataUpdated" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json", | ||
"name": "DocumentEventData", | ||
"description": "The data within all Firestore document events.", | ||
"datatype": "google.events.cloud.firestore.v1.DocumentEventData", | ||
"cloudeventTypes": [ | ||
"google.cloud.firestore.document.v1.created", | ||
"google.cloud.firestore.document.v1.updated", | ||
"google.cloud.firestore.document.v1.deleted", | ||
"google.cloud.firestore.document.v1.written" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json", | ||
"name": "ReferenceEventData", | ||
"description": "The data within all Firebase Real Time Database reference events.", | ||
"datatype": "google.events.firebase.database.v1.ReferenceEventData", | ||
"cloudeventTypes": [ | ||
"google.firebase.database.ref.v1.created", | ||
"google.firebase.database.ref.v1.updated", | ||
"google.firebase.database.ref.v1.deleted", | ||
"google.firebase.database.ref.v1.written" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/firebase/auth/v1/AuthEventData.json", | ||
"name": "AuthEventData", | ||
"description": "The data within all Firebase Auth events", | ||
"datatype": "google.events.firebase.auth.v1.AuthEventData", | ||
"cloudeventTypes": [ | ||
"google.firebase.auth.user.v1.created", | ||
"google.firebase.auth.user.v1.deleted" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json", | ||
"name": "AnalyticsLogData", | ||
"description": "The data within Firebase Analytics log events.", | ||
"datatype": "google.events.firebase.analytics.v1.AnalyticsLogData", | ||
"cloudeventTypes": [ | ||
"google.firebase.analytics.log.v1.written" | ||
] | ||
}, | ||
{ | ||
"url": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json", | ||
"name": "RemoteConfigEventData", | ||
"description": "The data within all Firebase Remote Config events.", | ||
"datatype": "google.events.firebase.remoteconfig.v1.RemoteConfigEventData", | ||
"cloudeventTypes": [ | ||
"google.firebase.remoteconfig.remoteConfig.v1.updated" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# jsonschema-catalog | ||
|
||
This tool generates a catalog for JSON schemas. | ||
|
||
## Requirements | ||
|
||
This tool requires the following languages: | ||
|
||
* `node 10`+ | ||
|
||
## Install | ||
|
||
Install dependencies: | ||
|
||
``` sh | ||
npm i | ||
``` | ||
|
||
### Run | ||
|
||
Run the JSON schema catalog generator: | ||
|
||
``` sh | ||
npm start | ||
``` | ||
|
||
This catalog lives in a file: `jsonschema/catalog.json` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const recursive = require("recursive-readdir"); | ||
|
||
/** | ||
* Generates the jsonschema catalog file. | ||
*/ | ||
const ROOT = path.resolve(`${__dirname}/../../jsonschema`); | ||
console.log(`Iterating through JSON schemas:`); | ||
|
||
(async () => { | ||
const filePaths = await recursive(ROOT); | ||
|
||
// For every JSON schema file, besides the catalog, read the file and gather data. | ||
let cloudeventJSONSchemas = []; | ||
filePaths.map(filePath => { | ||
if (filePath.includes('catalog.json')) return; // don't include self | ||
const json = JSON.parse(fs.readFileSync(filePath).toString()); | ||
console.log(`- ${json.$id}`); | ||
|
||
// Add schema catalog entry with specific fields. | ||
cloudeventJSONSchemas.push({ | ||
url: json.$id, | ||
name: json.name, | ||
description: json.description, | ||
datatype: json.datatype, | ||
cloudeventTypes: json.cloudeventTypes, | ||
}); | ||
}); | ||
// Sort by URL (to prevent random ordering) | ||
cloudeventJSONSchemas = cloudeventJSONSchemas.sort((s1, s2) => s1.package < s2.package); | ||
|
||
// Create the catalog file that follows the schema-catalog. | ||
const catalog = { | ||
$schema: 'https://json.schemastore.org/schema-catalog', | ||
version: 1, // required | ||
schemas: cloudeventJSONSchemas, | ||
}; | ||
fs.writeFileSync(`${ROOT}/catalog.json`, JSON.stringify(catalog, null, 2)); | ||
console.log(`Created: ${ROOT}/catalog.json`); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node ." | ||
}, | ||
"dependencies": { | ||
"camelcase-keys": "^6.2.2", | ||
"recursive-readdir": "^2.2.2" | ||
} | ||
} |