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

APIE-17: Improve topic names #216

Merged
merged 6 commits into from
Oct 25, 2021
Merged
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
6 changes: 3 additions & 3 deletions models/eventing/testdata/asyncapi.expected
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ channels:
operationId: 'v2/TestResource::Foo'
message:
$ref: '#/components/messages/v2TestResourceFoo'
topics/eventing_v1-start-signal:
topics/andrew-simple-example_v1-start-signal:
description: Event to start
publish:
summary: 'Adhoc: StartSignal'
operationId: StartSignal
message:
$ref: '#/components/messages/StartSignal'
topics/eventing_v3-stop-signal:
topics/andrew-simple-example_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/andrew-simple-example_v1-directory-delete-incomplete:
description: 'If a deletion is corrupted, we generate this event'
publish:
summary: 'Adhoc: file.DirectoryDeleteIncomplete'
Expand Down
41 changes: 25 additions & 16 deletions src/genevents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,8 @@ export default class EventsGen extends BaseGen {

const unique = camelCase(this.formSingleUniqueName(el))
if (isResourceLike(el) && !el.future && el.events) {
channels[
"topics/" +
kebabCase(this.getSpace()) +
"_" +
getVersion(el.name) +
"-" +
kebabCase(el.name)
] = {
const topic = this.topicOfRestResource(el);
channels[topic] = {
description:
this.translateDoc(el.comment) || "no documentation",
subscribe: {
Expand All @@ -148,6 +142,7 @@ export default class EventsGen extends BaseGen {

all.forEach((name) => {
const def = this.extractDefinition(name)
const topic = this.topicOfAdhocEvent(def);
const unq = camelCase(this.formSingleUniqueName(def))
const details: any = {
description:
Expand All @@ -167,17 +162,31 @@ export default class EventsGen extends BaseGen {
details.subscribe = msg
}

channels[
"topics/" +
this.mainNamespace +
"_" +
getVersion(def.name) +
"-" +
kebabCase(def.short)
] = details
channels[topic] = details
})
}

private topicOfAdhocEvent(def: IReference) {
let ns = kebabCase(this.getSpace());
let version = getVersion(def.name);
let name = kebabCase(def.short);
return this.toEventTopic(ns, version, name);
}

private topicOfRestResource(el: IReference) {
let ns = kebabCase(this.getSpace());
let version = getVersion(el.name);
let name = kebabCase(el.name);
return this.toEventTopic(ns, version, name);
}

private toEventTopic(ns: string, version: string, name: string) {
const basic = `${ns}_${version}-${name}`;
const escaped = basic.replace(/[^a-zA-Z0-9_-]/, "_");
const prefixed = "topics/" + escaped;
return prefixed
}

private addStandardHeaderDefinition(schemas: any, el: IResourceLike) {
const name = camelCase(this.formSingleUniqueName(el)) + "Header"
const verb = this.buildVerbProperty(el);
Expand Down
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 = "v6.1.3"
export const VERSION = "v6.1.4"

// parse the cmd line
const args = yargs
Expand Down