diff --git a/docs/releases.md b/docs/releases.md index 89600a65..ac3d73eb 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -1,3 +1,8 @@ +## 3.0.0 10/2/2020 + +Generate terraform-compatible GCP topic names. +Generate names with SLASH ("/") instead of DOT (".") between a topic's namespace and its versioned resource name. Even though DOT is a valid topic-name character according to GCP, it causes issues with terraform. + ## 2.2.5 9/16/2020 Now installable as a cmd line tool. Please follow the installation instructions, or run ./install-reslang to create links diff --git a/models/eventing/testdata/asyncapi.expected b/models/eventing/testdata/asyncapi.expected index 68679f56..133de951 100644 --- a/models/eventing/testdata/asyncapi.expected +++ b/models/eventing/testdata/asyncapi.expected @@ -10,42 +10,42 @@ servers: description: Production Google Pubsub server defaultContentType: application/json channels: - topics/andrew-simple-example.v1-simple-resource-resource: + topics/andrew/simple-example/v1-simple-resource-resource: description: A simple REST resource subscribe: summary: 'REST: SimpleResource' operationId: SimpleResource message: $ref: '#/components/messages/SimpleResource' - topics/andrew-simple-example.v2-test-resource-resource: + topics/andrew/simple-example/v2-test-resource-resource: description: A test REST resource subscribe: summary: 'REST: v2/TestResource' operationId: v2/TestResource message: $ref: '#/components/messages/v2TestResource' - topics/andrew-simple-example.v2-test-resource-foo-resource: + topics/andrew/simple-example/v2-test-resource-foo-resource: description: A REST subresource subscribe: summary: 'REST: v2/TestResource::Foo' operationId: 'v2/TestResource::Foo' message: $ref: '#/components/messages/v2TestResourceFoo' - topics/eventing.v1-start-signal: + topics/eventing/v1-start-signal: description: Event to start publish: summary: 'Adhoc: StartSignal' operationId: StartSignal message: $ref: '#/components/messages/StartSignal' - topics/eventing.v3-stop-signal: + topics/eventing/v3-stop-signal: description: Event to stop subscribe: summary: 'Adhoc: v3/StopSignal' operationId: v3/StopSignal message: $ref: '#/components/messages/v3StopSignal' - topics/eventing.v1-directory-delete-incomplete: + topics/eventing/v1-directory-delete-incomplete: description: 'If a deletion is corrupted, we generate this event' publish: summary: 'Adhoc: file.DirectoryDeleteIncomplete' @@ -409,4 +409,3 @@ components: - a - b description: Event to stop - diff --git a/models/file/testdata/asyncapi.expected b/models/file/testdata/asyncapi.expected index dd630c36..5896a5ce 100644 --- a/models/file/testdata/asyncapi.expected +++ b/models/file/testdata/asyncapi.expected @@ -10,21 +10,21 @@ servers: description: Production Google Pubsub server defaultContentType: application/json channels: - topics/file.v1-directory-file-resource: + topics/file/v1-directory-file-resource: description: This models a file in a directory subscribe: summary: 'REST: Directory::File' operationId: 'Directory::File' message: $ref: '#/components/messages/DirectoryFile' - topics/file.v1-directory-delete-request-resource: + topics/file/v1-directory-delete-request-resource: description: This models a long running request subscribe: summary: 'REST: DirectoryDeleteRequest' operationId: DirectoryDeleteRequest message: $ref: '#/components/messages/DirectoryDeleteRequest' - topics/file.v1-directory-delete-incomplete: + topics/file/v1-directory-delete-incomplete: description: 'If a deletion is corrupted, we generate this event' publish: summary: 'Adhoc: DirectoryDeleteIncomplete' @@ -223,4 +223,3 @@ components: required: - timeOfFailure description: 'If a deletion is corrupted, we generate this event' - diff --git a/models/milkman/testdata/asyncapi.expected b/models/milkman/testdata/asyncapi.expected index 3f5b3065..adda3ebd 100644 --- a/models/milkman/testdata/asyncapi.expected +++ b/models/milkman/testdata/asyncapi.expected @@ -10,7 +10,7 @@ servers: description: Production Google Pubsub server defaultContentType: application/json channels: - topics/milkman.v1-deliver-milk-resource: + topics/milkman/v1-deliver-milk-resource: description: no documentation subscribe: summary: 'REST: DeliverMilk' @@ -126,4 +126,3 @@ components: - verb - location - ids - diff --git a/src/genevents.ts b/src/genevents.ts index a44f34d0..8c9110df 100644 --- a/src/genevents.ts +++ b/src/genevents.ts @@ -117,15 +117,12 @@ export default class EventsGen extends BaseGen { const unique = camelCase(this.formSingleUniqueName(el)) if (isResourceLike(el) && !el.future && el.events) { - channels[ - "topics/" + - snakeCase(this.getSpace()) + - "." + - getVersion(el.name) + - "-" + - snakeCase(el.name) + - "-resource" - ] = { + let name = this.topicName( + this.getSpace(), + getVersion(el.name), + snakeCase(el.name) + ) + channels[`${name}-resource`] = { description: this.translateDoc(el.comment) || "no documentation", subscribe: { @@ -167,15 +164,12 @@ export default class EventsGen extends BaseGen { if (consumes.has(name)) { details.subscribe = msg } - - channels[ - "topics/" + - this.mainNamespace + - "." + - getVersion(def.name) + - "-" + - snakeCase(def.short) - ] = details + let topicName = this.topicName( + this.mainNamespace || "", + getVersion(def.name), + snakeCase(def.short) + ) + channels[topicName] = details }) } @@ -385,4 +379,14 @@ export default class EventsGen extends BaseGen { } } } + + private topicName( + namespace: string, + version: string, + name: string + ): string { + let str = `${version}-${name}` + if (namespace !== "") str = `${namespace}/${str}` + return `topics/${str}` + } } diff --git a/src/main.ts b/src/main.ts index fa0973fc..fbe85a8a 100755 --- a/src/main.ts +++ b/src/main.ts @@ -18,7 +18,7 @@ import JsonSchemaGen from "./genjsonschema" const RULES = "rules.json" const LOCAL_RULES = lpath.join(__dirname, "library", RULES) -export const VERSION = "v2.2.5" +export const VERSION = "v3.0.0" // parse the cmd line const args = yargs