Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use slash instead of dot to separate namespace #128

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 6 additions & 7 deletions models/eventing/testdata/asyncapi.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -409,4 +409,3 @@ components:
- a
- b
description: Event to stop

7 changes: 3 additions & 4 deletions models/file/testdata/asyncapi.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -223,4 +223,3 @@ components:
required:
- timeOfFailure
description: 'If a deletion is corrupted, we generate this event'

3 changes: 1 addition & 2 deletions models/milkman/testdata/asyncapi.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -126,4 +126,3 @@ components:
- verb
- location
- ids

40 changes: 22 additions & 18 deletions src/genevents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
})
}

Expand Down Expand Up @@ -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}`
}
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down