From 81933181b2125810855a74a6adafd2fe8c2f1275 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Wed, 18 Nov 2020 00:27:43 -0600 Subject: [PATCH 1/3] feat: enhances jsonschema Signed-off-by: Grant Timmerman --- .../events/cloud/audit/v1/LogEntryData.json | 7 +- .../cloud/cloudbuild/v1/BuildEventData.json | 7 +- .../cloud/firestore/v1/DocumentEventData.json | 10 +- .../cloud/pubsub/v1/MessagePublishedData.json | 7 +- .../cloud/scheduler/v1/SchedulerJobData.json | 7 +- .../cloud/storage/v1/StorageObjectData.json | 10 +- .../analytics/v1/AnalyticsLogData.json | 7 +- .../firebase/auth/v1/AuthEventData.json | 8 +- .../database/v1/ReferenceEventData.json | 10 +- .../v1/RemoteConfigEventData.json | 7 +- tools/README.md | 25 +++-- tools/proto2jsonschema/package-lock.json | 94 +++++++++++++++++++ tools/proto2jsonschema/package.json | 2 + tools/proto2jsonschema/postgen.js | 54 ++++++++++- 14 files changed, 226 insertions(+), 29 deletions(-) diff --git a/jsonschema/google/events/cloud/audit/v1/LogEntryData.json b/jsonschema/google/events/cloud/audit/v1/LogEntryData.json index 4f6f8339..bebc1992 100644 --- a/jsonschema/google/events/cloud/audit/v1/LogEntryData.json +++ b/jsonschema/google/events/cloud/audit/v1/LogEntryData.json @@ -1,7 +1,12 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/audit/v1/LogEntryData.json", "name": "LogEntryData", - "cloudevent": "google.events.cloud.audit.v1", + "package": "google.events.cloud.audit.v1", + "datatype": "google.events.cloud.audit.v1.LogEntryData", + "types": [ + "google.cloud.audit.log.v1.written" + ], + "product": "Cloud Audit Logs", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "logName": { diff --git a/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json b/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json index 075c1726..b4d2c2c4 100644 --- a/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json +++ b/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json @@ -1,7 +1,12 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json", "name": "BuildEventData", - "cloudevent": "google.events.cloud.cloudbuild.v1", + "package": "google.events.cloud.cloudbuild.v1", + "datatype": "google.events.cloud.cloudbuild.v1.BuildEventData", + "types": [ + "google.cloud.cloudbuild.build.v1.statusChanged" + ], + "product": "Cloud Build", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "id": { diff --git a/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json b/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json index 972a1c54..373b3638 100644 --- a/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json +++ b/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json @@ -1,7 +1,15 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json", "name": "DocumentEventData", - "cloudevent": "google.events.cloud.firestore.v1", + "package": "google.events.cloud.firestore.v1", + "datatype": "google.events.cloud.firestore.v1.DocumentEventData", + "types": [ + "google.cloud.firestore.document.v1.created", + "google.cloud.firestore.document.v1.updated", + "google.cloud.firestore.document.v1.deleted", + "google.cloud.firestore.document.v1.written" + ], + "product": "Cloud Firestore", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "value": { diff --git a/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json b/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json index 56f2d66d..9ce7c7f0 100644 --- a/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json +++ b/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json @@ -1,7 +1,12 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json", "name": "MessagePublishedData", - "cloudevent": "google.events.cloud.pubsub.v1", + "package": "google.events.cloud.pubsub.v1", + "datatype": "google.events.cloud.pubsub.v1.MessagePublishedData", + "types": [ + "google.cloud.pubsub.topic.v1.messagePublished" + ], + "product": "Cloud Pub/Sub", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "message": { diff --git a/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json b/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json index 2469190b..06f5b8ab 100644 --- a/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json +++ b/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json @@ -1,7 +1,12 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json", "name": "SchedulerJobData", - "cloudevent": "google.events.cloud.scheduler.v1", + "package": "google.events.cloud.scheduler.v1", + "datatype": "google.events.cloud.scheduler.v1.SchedulerJobData", + "types": [ + "google.cloud.scheduler.job.v1.executed" + ], + "product": "Cloud Scheduler", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "customData": { diff --git a/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json b/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json index 8c5baa7f..f230ddb2 100644 --- a/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json +++ b/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json @@ -1,7 +1,15 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json", "name": "StorageObjectData", - "cloudevent": "google.events.cloud.storage.v1", + "package": "google.events.cloud.storage.v1", + "datatype": "google.events.cloud.storage.v1.StorageObjectData", + "types": [ + "google.cloud.storage.object.v1.finalized", + "google.cloud.storage.object.v1.archived", + "google.cloud.storage.object.v1.deleted", + "google.cloud.storage.object.v1.metadataUpdated" + ], + "product": "Cloud Storage", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "contentEncoding": { diff --git a/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json b/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json index b574ac49..d52126f4 100644 --- a/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json +++ b/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json @@ -1,7 +1,12 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json", "name": "AnalyticsLogData", - "cloudevent": "google.events.firebase.analytics.v1", + "package": "google.events.firebase.analytics.v1", + "datatype": "google.events.firebase.analytics.v1.AnalyticsLogData", + "types": [ + "google.firebase.analytics.log.v1.written" + ], + "product": "Google Analytics for Firebase", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "userDim": { diff --git a/jsonschema/google/events/firebase/auth/v1/AuthEventData.json b/jsonschema/google/events/firebase/auth/v1/AuthEventData.json index c1d8cd9c..464c6188 100644 --- a/jsonschema/google/events/firebase/auth/v1/AuthEventData.json +++ b/jsonschema/google/events/firebase/auth/v1/AuthEventData.json @@ -1,7 +1,13 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/firebase/auth/v1/AuthEventData.json", "name": "AuthEventData", - "cloudevent": "google.events.firebase.auth.v1", + "package": "google.events.firebase.auth.v1", + "datatype": "google.events.firebase.auth.v1.AuthEventData", + "types": [ + "google.firebase.auth.user.v1.created", + "google.firebase.auth.user.v1.deleted" + ], + "product": "Firebase Authentication", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "uid": { diff --git a/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json b/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json index 87506d15..377658b7 100644 --- a/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json +++ b/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json @@ -1,7 +1,15 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json", "name": "ReferenceEventData", - "cloudevent": "google.events.firebase.database.v1", + "package": "google.events.firebase.database.v1", + "datatype": "google.events.firebase.database.v1.ReferenceEventData", + "types": [ + "google.firebase.database.ref.v1.created", + "google.firebase.database.ref.v1.updated", + "google.firebase.database.ref.v1.deleted", + "google.firebase.database.ref.v1.written" + ], + "product": "Firebase Realtime Database", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "data": { diff --git a/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json b/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json index edae3f7a..cfedd4ff 100644 --- a/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json +++ b/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json @@ -1,7 +1,12 @@ { "$id": "https://googleapis.github.io/google-cloudevents/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json", "name": "RemoteConfigEventData", - "cloudevent": "google.events.firebase.remoteconfig.v1", + "package": "google.events.firebase.remoteconfig.v1", + "datatype": "google.events.firebase.remoteconfig.v1.RemoteConfigEventData", + "types": [ + "google.firebase.remoteconfig.remoteConfig.v1.updated" + ], + "product": "Firebase Remote Config", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "versionNumber": { diff --git a/tools/README.md b/tools/README.md index 736a0363..fd692c45 100644 --- a/tools/README.md +++ b/tools/README.md @@ -1,24 +1,21 @@ -# Tools +# Google CloudEvent Repo Tools The tools in this directory are not required in order to *use* the rest of the content of this repository. They are present to help create or maintain the content. -While they are *currently* written in C#, requiring .NET Core 3.1 to -build and run, this is purely incidental. Pull requests to rewrite -the tools in languages more commonly used at Google (e.g. Java, Go -or Python) are welcome. +## [readme-list](./readme-list/readme.md) -## registry +This tool edits the top-level [README](../README.md) event list. -This tool edits the top-level [README](../README.md) to maintain the -event registry. It requires that the protobuf descriptor set (a -protobuf representation of all the .proto files) is already -compiled via protoc. (The [root compile.sh script](../compile.sh) -does this.) +## [quicktype-wrapper](./quicktype-wrapper/README.md) -## quicktype-wrapper +This tool wraps the `quicktype` tool to generate any language using JSON schemas. -This tool wraps the quicktype tool to generate code using JSON Schema. +## [proto2jsonschema](./proto2jsonschema/README.md) -See [`quicktype-wrapper/`](./quicktype-wrapper/README.md). +This tool converts protobufs to JSON schemas. + +## [jsonschema-registry](./jsonschema-registry/README.md) + +This tool generates a registry for JSON schemas. \ No newline at end of file diff --git a/tools/proto2jsonschema/package-lock.json b/tools/proto2jsonschema/package-lock.json index 668cba67..09a441de 100644 --- a/tools/proto2jsonschema/package-lock.json +++ b/tools/proto2jsonschema/package-lock.json @@ -2,6 +2,70 @@ "requires": true, "lockfileVersion": 1, "dependencies": { + "@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha1-m4sMxmPWaafY9vXQiToU00jzD78=" + }, + "@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" + }, + "@protobufjs/codegen": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", + "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" + }, + "@protobufjs/eventemitter": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", + "integrity": "sha1-NVy8mLr61ZePntCV85diHx0Ga3A=" + }, + "@protobufjs/fetch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", + "integrity": "sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU=", + "requires": { + "@protobufjs/aspromise": "^1.1.1", + "@protobufjs/inquire": "^1.1.0" + } + }, + "@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha1-Xp4avctz/Ap8uLKR33jIy9l7h9E=" + }, + "@protobufjs/inquire": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", + "integrity": "sha1-/yAOPnzyQp4tyvwRQIKOjMY48Ik=" + }, + "@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha1-bMKyDFya1q0NzP0hynZz2Nf79o0=" + }, + "@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha1-Cf0V8tbTq/qbZbw2ZQbWrXhG/1Q=" + }, + "@protobufjs/utf8": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", + "integrity": "sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=" + }, + "@types/long": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.1.tgz", + "integrity": "sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==" + }, + "@types/node": { + "version": "13.13.31", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.31.tgz", + "integrity": "sha512-gBk54XbcRj8EKTi7Syo4JU4purbRJaZpkvMVs7+t+b9JaOtwsGo7vCbXdVJN3gH/wu/GyZGD8lAKo0qpQuNjOw==" + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -36,6 +100,16 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, + "flat": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==" + }, + "long": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", + "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" + }, "map-obj": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.1.0.tgz", @@ -49,6 +123,26 @@ "brace-expansion": "^1.1.7" } }, + "protobufjs": { + "version": "6.10.2", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.10.2.tgz", + "integrity": "sha512-27yj+04uF6ya9l+qfpH187aqEzfCF4+Uit0I9ZBQVqK09hk/SQzKa2MUqUpXaVa7LOFRg1TSSr3lVxGOk6c0SQ==", + "requires": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.4", + "@protobufjs/eventemitter": "^1.1.0", + "@protobufjs/fetch": "^1.1.0", + "@protobufjs/float": "^1.0.2", + "@protobufjs/inquire": "^1.1.0", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.0", + "@types/long": "^4.0.1", + "@types/node": "^13.7.0", + "long": "^4.0.0" + } + }, "quick-lru": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", diff --git a/tools/proto2jsonschema/package.json b/tools/proto2jsonschema/package.json index 6820ad4d..f553b4b4 100644 --- a/tools/proto2jsonschema/package.json +++ b/tools/proto2jsonschema/package.json @@ -5,6 +5,8 @@ }, "dependencies": { "camelcase-keys": "^6.2.2", + "flat": "^5.0.2", + "protobufjs": "^6.10.2", "recursive-readdir": "^2.2.2" } } diff --git a/tools/proto2jsonschema/postgen.js b/tools/proto2jsonschema/postgen.js index de70d9ab..5daa8325 100644 --- a/tools/proto2jsonschema/postgen.js +++ b/tools/proto2jsonschema/postgen.js @@ -2,6 +2,8 @@ const path = require('path'); const fs = require('fs'); const recursive = require("recursive-readdir"); const camelcaseKeys = require('camelcase-keys'); +const protobufjs = require('protobufjs'); +const flatten = require('flat'); /** * This tool polishes the JSON schemas with a few modifications: @@ -21,11 +23,15 @@ console.log(`Fixing paths in dir: ${ROOT}`); // Create the modified JSON schema output const json = JSON.parse(fs.readFileSync(filePath).toString()); + const packageName = getCloudEventPackage(filePath); + const resultJSON = { // Add the $id and name first $id: getId(filePath), name: dataName, - cloudevent: getCloudEventType(filePath), + package: packageName, + datatype: `${packageName}.${dataName}`, + ...getCloudEventProperties(packageName), // Add all other fields. Convert keys to camelCase (i.e. remove snake_case keys) ...camelcaseKeys(json, {deep: true}) }; @@ -85,7 +91,7 @@ console.log(`Fixing paths in dir: ${ROOT}`); // Replace all complex $refs const refReplacementList = []; // a list of [before, after] strings - const typePrefix = lcfirst(getCloudEventType(filePath).split('.').map(ucfirst).join('')); + const typePrefix = lcfirst(getCloudEventPackage(filePath).split('.').map(ucfirst).join('')); const unnecessaryTypePrefix = `#/definitions/${typePrefix}`; // Go through all $refs const uniqueRefs = [...new Set(allRefs)]; @@ -120,17 +126,55 @@ function getId(filepath) { } /** - * Gets the CloudEvent#type represented in the JSON schema. + * Gets the cloudevent package represented in the JSON schema. * @param {string} filepath The input file path * @example filepath: /Documents/github/googleapis/google-cloudevents/jsonschema/google/events/cloud/audit/v1/LogEntryData.json + * @returns {string} The CloudEvent package for this file represents. * @example out: google.events.cloud.audit.v1 - * @returns {string} The CloudEvent ID for this file represents. */ -function getCloudEventType(filepath) { +function getCloudEventPackage(filepath) { const removePrefix = filepath.split('jsonschema/')[1]; const removeSuffix = removePrefix.substring(0, removePrefix.lastIndexOf("/")); return removeSuffix.replace(/\//g, '.'); } +/** + * Gets the CloudEvent properties from the corresponding `events.proto` file. + * @param {string} packageName The package name of the CloudEvent. + * @return {object} cloudevent The CloudEvent properties object. + * @return {string[]} cloudevent.types The CloudEvent type strings. + * @return {string} cloudevent.product The CloudEvent product. + */ +function getCloudEventProperties(packageName) { + const protoPath = packageName.split('.').join('/'); + const eventPath = path.resolve(`${__dirname}/../../proto/${protoPath}/events.proto`); + const proto = protobufjs.loadSync(eventPath); + const protoAsJSON = proto.toJSON(); + + // Flatten the protobuf representation and look directly for these keys: + const CLOUD_EVENT_TYPE = '(google.events.cloud_event_type)'; + const CLOUD_EVENT_PRODUCT = '(google.events.cloud_event_product)'; + const flattenedProtoValueMap = flatten(protoAsJSON); + const flattenedProtoValueMapEntries = Object.entries(flattenedProtoValueMap); + + // Go through all the keys, add the type or product if found. + const types = []; + let product = ''; + for (const [k, v] of flattenedProtoValueMapEntries) { + if (k.endsWith(CLOUD_EVENT_TYPE)) { + types.push(v); + } + if (k.endsWith(CLOUD_EVENT_PRODUCT)) { + product = v; + } + } + + // Return types and product. + return { + types, + product, + }; +} + const ucfirst = (w) => w.charAt(0).toUpperCase() + w.slice(1); const lcfirst = (w) => w.charAt(0).toLowerCase() + w.slice(1); \ No newline at end of file From c6a65aff3f01186112aa1101110afe11443cb2df Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Wed, 18 Nov 2020 00:29:48 -0600 Subject: [PATCH 2/3] docs: revert tools readme registry Signed-off-by: Grant Timmerman --- tools/README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/README.md b/tools/README.md index fd692c45..131596af 100644 --- a/tools/README.md +++ b/tools/README.md @@ -4,7 +4,7 @@ The tools in this directory are not required in order to *use* the rest of the content of this repository. They are present to help create or maintain the content. -## [readme-list](./readme-list/readme.md) +## [registry](./registry/readme.md) This tool edits the top-level [README](../README.md) event list. @@ -15,7 +15,3 @@ This tool wraps the `quicktype` tool to generate any language using JSON schemas ## [proto2jsonschema](./proto2jsonschema/README.md) This tool converts protobufs to JSON schemas. - -## [jsonschema-registry](./jsonschema-registry/README.md) - -This tool generates a registry for JSON schemas. \ No newline at end of file From b2da7ac12253a3cee438127abbf6e0ef758252dc Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Wed, 18 Nov 2020 08:55:41 -0600 Subject: [PATCH 3/3] fix: jsonschema types to clouddeventTypes Signed-off-by: Grant Timmerman --- jsonschema/google/events/cloud/audit/v1/LogEntryData.json | 2 +- .../google/events/cloud/cloudbuild/v1/BuildEventData.json | 2 +- .../google/events/cloud/firestore/v1/DocumentEventData.json | 2 +- .../google/events/cloud/pubsub/v1/MessagePublishedData.json | 2 +- .../google/events/cloud/scheduler/v1/SchedulerJobData.json | 2 +- .../google/events/cloud/storage/v1/StorageObjectData.json | 2 +- .../events/firebase/analytics/v1/AnalyticsLogData.json | 2 +- .../google/events/firebase/auth/v1/AuthEventData.json | 2 +- .../events/firebase/database/v1/ReferenceEventData.json | 2 +- .../firebase/remoteconfig/v1/RemoteConfigEventData.json | 2 +- tools/proto2jsonschema/postgen.js | 6 +++--- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/jsonschema/google/events/cloud/audit/v1/LogEntryData.json b/jsonschema/google/events/cloud/audit/v1/LogEntryData.json index bebc1992..9e5899d2 100644 --- a/jsonschema/google/events/cloud/audit/v1/LogEntryData.json +++ b/jsonschema/google/events/cloud/audit/v1/LogEntryData.json @@ -3,7 +3,7 @@ "name": "LogEntryData", "package": "google.events.cloud.audit.v1", "datatype": "google.events.cloud.audit.v1.LogEntryData", - "types": [ + "cloudeventTypes": [ "google.cloud.audit.log.v1.written" ], "product": "Cloud Audit Logs", diff --git a/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json b/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json index b4d2c2c4..52bfe1e4 100644 --- a/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json +++ b/jsonschema/google/events/cloud/cloudbuild/v1/BuildEventData.json @@ -3,7 +3,7 @@ "name": "BuildEventData", "package": "google.events.cloud.cloudbuild.v1", "datatype": "google.events.cloud.cloudbuild.v1.BuildEventData", - "types": [ + "cloudeventTypes": [ "google.cloud.cloudbuild.build.v1.statusChanged" ], "product": "Cloud Build", diff --git a/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json b/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json index 373b3638..ab4761e2 100644 --- a/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json +++ b/jsonschema/google/events/cloud/firestore/v1/DocumentEventData.json @@ -3,7 +3,7 @@ "name": "DocumentEventData", "package": "google.events.cloud.firestore.v1", "datatype": "google.events.cloud.firestore.v1.DocumentEventData", - "types": [ + "cloudeventTypes": [ "google.cloud.firestore.document.v1.created", "google.cloud.firestore.document.v1.updated", "google.cloud.firestore.document.v1.deleted", diff --git a/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json b/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json index 9ce7c7f0..6cc0ec4d 100644 --- a/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json +++ b/jsonschema/google/events/cloud/pubsub/v1/MessagePublishedData.json @@ -3,7 +3,7 @@ "name": "MessagePublishedData", "package": "google.events.cloud.pubsub.v1", "datatype": "google.events.cloud.pubsub.v1.MessagePublishedData", - "types": [ + "cloudeventTypes": [ "google.cloud.pubsub.topic.v1.messagePublished" ], "product": "Cloud Pub/Sub", diff --git a/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json b/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json index 06f5b8ab..70dcf73f 100644 --- a/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json +++ b/jsonschema/google/events/cloud/scheduler/v1/SchedulerJobData.json @@ -3,7 +3,7 @@ "name": "SchedulerJobData", "package": "google.events.cloud.scheduler.v1", "datatype": "google.events.cloud.scheduler.v1.SchedulerJobData", - "types": [ + "cloudeventTypes": [ "google.cloud.scheduler.job.v1.executed" ], "product": "Cloud Scheduler", diff --git a/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json b/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json index f230ddb2..9d2bab70 100644 --- a/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json +++ b/jsonschema/google/events/cloud/storage/v1/StorageObjectData.json @@ -3,7 +3,7 @@ "name": "StorageObjectData", "package": "google.events.cloud.storage.v1", "datatype": "google.events.cloud.storage.v1.StorageObjectData", - "types": [ + "cloudeventTypes": [ "google.cloud.storage.object.v1.finalized", "google.cloud.storage.object.v1.archived", "google.cloud.storage.object.v1.deleted", diff --git a/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json b/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json index d52126f4..e3582a05 100644 --- a/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json +++ b/jsonschema/google/events/firebase/analytics/v1/AnalyticsLogData.json @@ -3,7 +3,7 @@ "name": "AnalyticsLogData", "package": "google.events.firebase.analytics.v1", "datatype": "google.events.firebase.analytics.v1.AnalyticsLogData", - "types": [ + "cloudeventTypes": [ "google.firebase.analytics.log.v1.written" ], "product": "Google Analytics for Firebase", diff --git a/jsonschema/google/events/firebase/auth/v1/AuthEventData.json b/jsonschema/google/events/firebase/auth/v1/AuthEventData.json index 464c6188..0b3da351 100644 --- a/jsonschema/google/events/firebase/auth/v1/AuthEventData.json +++ b/jsonschema/google/events/firebase/auth/v1/AuthEventData.json @@ -3,7 +3,7 @@ "name": "AuthEventData", "package": "google.events.firebase.auth.v1", "datatype": "google.events.firebase.auth.v1.AuthEventData", - "types": [ + "cloudeventTypes": [ "google.firebase.auth.user.v1.created", "google.firebase.auth.user.v1.deleted" ], diff --git a/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json b/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json index 377658b7..40cfea7e 100644 --- a/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json +++ b/jsonschema/google/events/firebase/database/v1/ReferenceEventData.json @@ -3,7 +3,7 @@ "name": "ReferenceEventData", "package": "google.events.firebase.database.v1", "datatype": "google.events.firebase.database.v1.ReferenceEventData", - "types": [ + "cloudeventTypes": [ "google.firebase.database.ref.v1.created", "google.firebase.database.ref.v1.updated", "google.firebase.database.ref.v1.deleted", diff --git a/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json b/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json index cfedd4ff..80dce67f 100644 --- a/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json +++ b/jsonschema/google/events/firebase/remoteconfig/v1/RemoteConfigEventData.json @@ -3,7 +3,7 @@ "name": "RemoteConfigEventData", "package": "google.events.firebase.remoteconfig.v1", "datatype": "google.events.firebase.remoteconfig.v1.RemoteConfigEventData", - "types": [ + "cloudeventTypes": [ "google.firebase.remoteconfig.remoteConfig.v1.updated" ], "product": "Firebase Remote Config", diff --git a/tools/proto2jsonschema/postgen.js b/tools/proto2jsonschema/postgen.js index 5daa8325..0a206195 100644 --- a/tools/proto2jsonschema/postgen.js +++ b/tools/proto2jsonschema/postgen.js @@ -158,11 +158,11 @@ function getCloudEventProperties(packageName) { const flattenedProtoValueMapEntries = Object.entries(flattenedProtoValueMap); // Go through all the keys, add the type or product if found. - const types = []; + const cloudeventTypes = []; let product = ''; for (const [k, v] of flattenedProtoValueMapEntries) { if (k.endsWith(CLOUD_EVENT_TYPE)) { - types.push(v); + cloudeventTypes.push(v); } if (k.endsWith(CLOUD_EVENT_PRODUCT)) { product = v; @@ -171,7 +171,7 @@ function getCloudEventProperties(packageName) { // Return types and product. return { - types, + cloudeventTypes, product, }; }