diff --git a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.ts b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.ts index b77a7c4a1..f71cd0af6 100644 --- a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.ts +++ b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.ts @@ -53,7 +53,7 @@ export class ChannelMainComponent implements OnInit { this.defaultExample = this.schema.example || noExample; this.exampleTextAreaLineCount = this.defaultExample?.lineCount || 1; - this.defaultExampleType = this.operation().message.payload.type; + this.defaultExampleType = this.operation().message.payload.name; this.headersSchemaIdentifier = this.operation().message.headers.name.slice( diff --git a/springwolf-ui/src/app/components/new/channels/channel-main/channel-operation.component.ts b/springwolf-ui/src/app/components/new/channels/channel-main/channel-operation.component.ts index 1868a0477..ecac952cb 100644 --- a/springwolf-ui/src/app/components/new/channels/channel-main/channel-operation.component.ts +++ b/springwolf-ui/src/app/components/new/channels/channel-main/channel-operation.component.ts @@ -27,7 +27,6 @@ export class ChannelOperationComponent implements OnInit { defaultSchema: Schema = initSchema; defaultExample: Example = initExample; - defaultExampleType: string = ""; originalDefaultExample: Example = this.defaultExample; headers: Schema = initSchema; @@ -57,7 +56,6 @@ export class ChannelOperationComponent implements OnInit { const schema = schemas.get(schemaIdentifier)!!; this.defaultSchema = schema; this.originalDefaultExample = schema.example || noExample; - this.defaultExampleType = this.operation().message.payload.type; const headersSchemaIdentifier = this.operation().message.headers.name.slice( @@ -123,7 +121,7 @@ export class ChannelOperationComponent implements OnInit { publish(): void { const example = this.defaultExample.value; - const payloadType = this.defaultExampleType; + const payloadType = this.operation().message.payload.name; const headers = this.headersExample.value; const bindings = this.messageBindingExampleString; try { diff --git a/springwolf-ui/src/app/components/new/schemas/schemas.component.html b/springwolf-ui/src/app/components/new/schemas/schemas.component.html index 385ac53ea..80dff1dff 100644 --- a/springwolf-ui/src/app/components/new/schemas/schemas.component.html +++ b/springwolf-ui/src/app/components/new/schemas/schemas.component.html @@ -20,7 +20,7 @@

Schemas

>
{{ schema.type }}
-
+
Description
diff --git a/springwolf-ui/src/app/components/schemas/range/schema-range.component.spec.ts b/springwolf-ui/src/app/components/schemas/range/schema-range.component.spec.ts index d55aa945f..32ca9a16e 100644 --- a/springwolf-ui/src/app/components/schemas/range/schema-range.component.spec.ts +++ b/springwolf-ui/src/app/components/schemas/range/schema-range.component.spec.ts @@ -12,12 +12,17 @@ describe("SchemaRangeComponent", function () { }); }; + const minimalSchema: Schema = { + title: "test", + name: "test", + anchorUrl: "test", + anchorIdentifier: "test", + usedBy: [], + }; + it("should create the component", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, minimum: 0.1, maximum: 10, exclusiveMinimum: true, @@ -29,10 +34,7 @@ describe("SchemaRangeComponent", function () { it("should have `( 0.1 .. 10 )` as value", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, minimum: 0.1, maximum: 10, exclusiveMinimum: true, @@ -44,10 +46,7 @@ describe("SchemaRangeComponent", function () { it("should have `[ 0.1 .. 10 )` as value", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, minimum: 0.1, maximum: 10, exclusiveMinimum: false, @@ -59,10 +58,7 @@ describe("SchemaRangeComponent", function () { it("should have `( 0.1 .. 10 ]` as value", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, minimum: 0.1, maximum: 10, exclusiveMinimum: true, @@ -74,10 +70,7 @@ describe("SchemaRangeComponent", function () { it("should have `[ 0.1 .. 10 ]` as value", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, minimum: 0.1, maximum: 10, }); @@ -87,10 +80,7 @@ describe("SchemaRangeComponent", function () { it("should have `> 0.1` as value", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, minimum: 0.1, exclusiveMinimum: true, }); @@ -100,10 +90,7 @@ describe("SchemaRangeComponent", function () { it("should have `< 10` as value", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, maximum: 10, exclusiveMaximum: true, }); @@ -113,10 +100,7 @@ describe("SchemaRangeComponent", function () { it("should have `>= 0.1` as value", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, minimum: 0.1, }); @@ -125,10 +109,7 @@ describe("SchemaRangeComponent", function () { it("should have `<= 10` as value", async () => { await renderComponent({ - title: "test", - name: "test", - anchorIdentifier: "test", - usedBy: [], + ...minimalSchema, maximum: 10, }); diff --git a/springwolf-ui/src/app/components/schemas/schema/schema.component.html b/springwolf-ui/src/app/components/schemas/schema/schema.component.html index bcada1d38..609be2517 100644 --- a/springwolf-ui/src/app/components/schemas/schema/schema.component.html +++ b/springwolf-ui/src/app/components/schemas/schema/schema.component.html @@ -24,12 +24,14 @@ {{ property.value.items.type }}[] - - {{ property.value.items.refTitle }}[] + {{ property.value.items.refName }}[] diff --git a/springwolf-ui/src/app/models/channel.model.ts b/springwolf-ui/src/app/models/channel.model.ts index 82041f2b3..b8e53e115 100644 --- a/springwolf-ui/src/app/models/channel.model.ts +++ b/springwolf-ui/src/app/models/channel.model.ts @@ -15,6 +15,7 @@ export interface ChannelOperation { export interface Channel { name: string; anchorIdentifier: string; + anchorUrl: string; description?: string; operations: ChannelOperation[]; bindings: Bindings; diff --git a/springwolf-ui/src/app/models/message.model.ts b/springwolf-ui/src/app/models/message.model.ts index 4d49300e8..81c8bc2f8 100644 --- a/springwolf-ui/src/app/models/message.model.ts +++ b/springwolf-ui/src/app/models/message.model.ts @@ -8,7 +8,6 @@ export interface Message { contentType: string; payload: { name: string; - type: string; title: string; anchorUrl: string; }; diff --git a/springwolf-ui/src/app/models/schema.model.ts b/springwolf-ui/src/app/models/schema.model.ts index 34cc5793c..2834eb893 100644 --- a/springwolf-ui/src/app/models/schema.model.ts +++ b/springwolf-ui/src/app/models/schema.model.ts @@ -11,6 +11,7 @@ export interface Schema { */ title: string; anchorIdentifier: string; + anchorUrl: string; usedBy: { name: string; anchorUrl: string; type: "channel" | "schema" }[]; description?: string; deprecated?: boolean; @@ -21,9 +22,8 @@ export interface Schema { type?: string; format?: string; // type == ref - anchorUrl?: string; + refAnchorUrl?: string; refName?: string; - refTitle?: string; // type == object properties?: { [key: string]: Schema }; required?: string[]; diff --git a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts index 490c26677..3ae22550d 100644 --- a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts +++ b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts @@ -119,6 +119,7 @@ export class AsyncApiMapperService { mappedChannels[channelId] = { name: channel.address, anchorIdentifier: "channel-" + channelId, + anchorUrl: AsyncApiMapperService.BASE_URL + "channel-" + channelId, operations: [], bindings: channel.bindings || {}, }; @@ -128,7 +129,7 @@ export class AsyncApiMapperService { for (let operationsKey in operations) { this.parsingErrorBoundary("operation " + operationsKey, () => { const operation = operations[operationsKey]; - const channelId = this.resolveRef(operation.channel.$ref); + const channelId = this.resolveRefId(operation.channel.$ref); const channelName = channels[channelId].address; this.verifyBindings(operation.bindings, "operation " + operationsKey); @@ -200,16 +201,16 @@ export class AsyncApiMapperService { message: Message, servers: ServerServers ): ChannelOperation { - const mappedServers = - channel?.servers?.map((server) => this.resolveRef(server.$ref)) || + const serverIds = + channel?.servers?.map((server) => this.resolveRefId(server.$ref)) || Object.keys(servers); - const mappedOperationServers: OperationServer[] = mappedServers.map( - (serverKey) => { + const mappedOperationServers: OperationServer[] = serverIds.map( + (serverId) => { return { - name: serverKey, - anchorIdentifier: SERVER_ANCHOR_PREFIX + serverKey, + name: serverId, + anchorIdentifier: SERVER_ANCHOR_PREFIX + serverId, anchorUrl: - AsyncApiMapperService.BASE_URL + SERVER_ANCHOR_PREFIX + serverKey, + AsyncApiMapperService.BASE_URL + SERVER_ANCHOR_PREFIX + serverId, }; } ); @@ -255,34 +256,32 @@ export class AsyncApiMapperService { return this.parsingErrorBoundary( "message of channel " + channelName, () => { - const messageKey = this.resolveRef(operationMessage.$ref); - const channelMessage = channel.messages[messageKey]; - const channelMessageRef = this.resolveRef(channelMessage.$ref); - const message = messages[channelMessageRef]; + const messageId = this.resolveRefId(operationMessage.$ref); + const channelMessage = channel.messages[messageId]; + const channelMessageId = this.resolveRefId(channelMessage.$ref); + const message = messages[channelMessageId]; this.verifyBindings(message.bindings, "message " + message.name); + let payloadName = this.resolveRefId(message.payload.schema.$ref); const mappedMessage: Message = { name: message.name, title: message.title, description: message.description, contentType: message.contentType || defaultContentType, payload: { - name: message.payload.schema.$ref, - title: this.resolveRef(message.payload.schema.$ref), - type: this.resolveRef(message.payload.schema.$ref), - anchorUrl: - AsyncApiMapperService.BASE_URL + - this.resolveRef(message.payload.schema.$ref), + name: payloadName, + title: this.resolveTitleFromName(payloadName), + anchorUrl: AsyncApiMapperService.BASE_URL + payloadName, }, headers: { name: message.headers.$ref, title: - message.headers.$ref?.split("/")?.pop() || + this.resolveRefId(message.headers.$ref) || "undefined-header-title", anchorUrl: AsyncApiMapperService.BASE_URL + - this.resolveRef(message.headers.$ref), + this.resolveRefId(message.headers.$ref), }, bindings: this.mapServerAsyncApiMessageBindings(message.bindings), rawBindings: message.bindings || {}, @@ -356,18 +355,15 @@ export class AsyncApiMapperService { return undefined; } - const refChannelId = this.resolveRef(reply.channel.$ref); + const refChannelId = this.resolveRefId(reply.channel.$ref); const refChannelName = channels[refChannelId].address; + const refMessageId = this.resolveRefId(reply.messages[0].$ref); return { channelAnchorUrl: - AsyncApiMapperService.BASE_URL + - CHANNEL_ANCHOR_PREFIX + - this.resolveRef(reply.channel.$ref), + AsyncApiMapperService.BASE_URL + CHANNEL_ANCHOR_PREFIX + refChannelId, channelName: refChannelName, - messageAnchorUrl: - AsyncApiMapperService.BASE_URL + - this.resolveRef(reply.messages[0].$ref), - messageName: this.resolveRef(reply.messages[0].$ref), + messageAnchorUrl: AsyncApiMapperService.BASE_URL + refMessageId, + messageName: refMessageId, }; } @@ -447,9 +443,10 @@ export class AsyncApiMapperService { return { name: schemaName, - title: schemaName.split(".")?.pop() || "undefined-title", + title: this.resolveTitleFromName(schemaName) || "undefined-title", usedBy: [], anchorIdentifier: schemaName, + anchorUrl: AsyncApiMapperService.BASE_URL + schemaName, description: schema.description, deprecated: schema.deprecated, @@ -504,34 +501,38 @@ export class AsyncApiMapperService { let actualSchema = schema; while ("$ref" in actualSchema) { - const refName = this.resolveRef(actualSchema.$ref); - const refSchema = schemas[refName]; + const refId = this.resolveRefId(actualSchema.$ref); + const refSchema = schemas[refId]; if (refSchema !== undefined) { actualSchema = refSchema; } else { - throw new Error("Schema " + refName + " not found"); + throw new Error("Schema " + refId + " not found"); } } return actualSchema; } private mapSchemaRef(schemaName: string, schema: { $ref: string }): Schema { + let schemaRefId = this.resolveRefId(schema.$ref); return { name: schemaName, - title: schemaName.split(".").pop()!!, + title: this.resolveTitleFromName(schemaName), usedBy: [], anchorIdentifier: schemaName, + anchorUrl: AsyncApiMapperService.BASE_URL + schemaName, // type == ref - anchorUrl: AsyncApiMapperService.BASE_URL + this.resolveRef(schema.$ref), - refName: schema.$ref, - refTitle: this.resolveRef(schema.$ref), + refAnchorUrl: AsyncApiMapperService.BASE_URL + schemaRefId, + refName: schemaRefId, }; } - private resolveRef(ref: string): string { + private resolveRefId(ref: string): string { return ref.split("/").pop()!!; } + private resolveTitleFromName(name: string): string { + return name.split(".").pop()!!; + } private verifyBindings( bindings: ServerBindings | undefined, @@ -548,9 +549,7 @@ export class AsyncApiMapperService { asyncApi.components.schemas.forEach((schema) => { asyncApi.channels.forEach((channel) => { channel.operations.forEach((channelOperation) => { - if ( - channelOperation.operation.message.payload.title === schema.name - ) { + if (channelOperation.operation.message.payload.name === schema.name) { schema.usedBy.push({ name: channelOperation.name, anchorUrl: channelOperation.anchorUrl!!, @@ -562,18 +561,18 @@ export class AsyncApiMapperService { asyncApi.components.schemas.forEach((otherSchema) => { Object.values(otherSchema?.properties || {}).forEach((property) => { - if (property.refTitle === schema.name) { + if (property.refName === schema.name) { schema.usedBy.push({ name: otherSchema.title, - anchorUrl: otherSchema.anchorUrl!!, + anchorUrl: otherSchema.refAnchorUrl!!, type: "schema", }); } }); - if (otherSchema.items?.refTitle === schema.name) { + if (otherSchema.items?.refName === schema.name) { schema.usedBy.push({ name: otherSchema.title, - anchorUrl: otherSchema.anchorUrl!!, + anchorUrl: otherSchema.refAnchorUrl!!, type: "schema", }); } diff --git a/springwolf-ui/src/app/service/mock/init-values.ts b/springwolf-ui/src/app/service/mock/init-values.ts index 08e498ae3..4bc1f04f1 100644 --- a/springwolf-ui/src/app/service/mock/init-values.ts +++ b/springwolf-ui/src/app/service/mock/init-values.ts @@ -23,7 +23,7 @@ export const initMessage: Message = { bindings: new Map(), headers: { anchorUrl: "", name: "", title: "" }, name: "", - payload: { anchorUrl: "", name: "", title: "", type: "" }, + payload: { anchorUrl: "", name: "", title: "" }, rawBindings: {}, title: "", contentType: "", @@ -40,6 +40,7 @@ export const initOperation: Operation = { export const initSchema: Schema = { title: "", name: "", + anchorUrl: "", anchorIdentifier: "", usedBy: [], };