Skip to content

Commit

Permalink
Merge pull request #216 from LiveRamp/APIE-17
Browse files Browse the repository at this point in the history
APIE-17: Improve topic names
  • Loading branch information
nhtzr authored Oct 25, 2021
2 parents 3db40a3 + 0c36f07 commit 9eefa34
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
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

0 comments on commit 9eefa34

Please sign in to comment.