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

feat(ui): show used by in schema #912

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

.description {
overflow: auto;
margin-bottom: -1em;
}

.example {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</ng-container>

<!-- Objects -->
<b *ngIf="Object.keys(schema().properties || {}).length > 0">Properties</b>
<mat-list *ngIf="Object.keys(schema().properties || {}).length > 0">
<mat-list-item
*ngFor="let property of schema().properties || {} | keyvalue"
Expand Down Expand Up @@ -74,7 +73,7 @@
{{ value.items.type }}[]
</span>

<div class="description">
<div class="description" *ngIf="value.description?.length > 0">
<markdown [data]="value.description"></markdown>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2>Schemas</h2>
<div class="table margin-vertical-1em">
<div class="table-row">
<span>Name</span>
<span>{{ schema.name }}</span>
<span class="text-console">{{ schema.name }}</span>
</div>
<div class="table-row">
<span>Type</span>
Expand All @@ -24,9 +24,30 @@ <h2>Schemas</h2>
<span>Description</span>
<markdown [data]="schema.description"></markdown>
</div>
<div class="table-row" *ngIf="schema.usedBy.length > 0">
<span>Used by</span>
<mat-chip-set>
@for (usageEl of schema.usedBy; track usageEl) {
<a [href]="usageEl.anchorUrl">
<mat-chip>
<mat-icon matChipAvatar>{{
usageEl.type == "schema" ? "schema" : "swap_vert"
}}</mat-icon>
{{ usageEl.name }}
</mat-chip></a
>
}
</mat-chip-set>
</div>
</div>

<h6>Example</h6>
<div>
<app-json [data]="schema.example?.rawValue"></app-json>
</div>

<app-schema [schema]="schema"></app-schema>
<h6>Properties</h6>
<app-schema-new [schema]="schema"></app-schema-new>
</mat-card-content>
</mat-card>
@if (!$last) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
minimum: 0.1,
maximum: 10,
exclusiveMinimum: true,
Expand All @@ -31,6 +32,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
minimum: 0.1,
maximum: 10,
exclusiveMinimum: true,
Expand All @@ -45,6 +47,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
minimum: 0.1,
maximum: 10,
exclusiveMinimum: false,
Expand All @@ -59,6 +62,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
minimum: 0.1,
maximum: 10,
exclusiveMinimum: true,
Expand All @@ -73,6 +77,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
minimum: 0.1,
maximum: 10,
});
Expand All @@ -85,6 +90,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
minimum: 0.1,
exclusiveMinimum: true,
});
Expand All @@ -97,6 +103,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
maximum: 10,
exclusiveMaximum: true,
});
Expand All @@ -109,6 +116,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
minimum: 0.1,
});

Expand All @@ -120,6 +128,7 @@ describe("SchemaRangeComponent", function () {
title: "test",
name: "test",
anchorIdentifier: "test",
usedBy: [],
maximum: 10,
});

Expand Down
1 change: 1 addition & 0 deletions springwolf-ui/src/app/models/channel.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const CHANNEL_ANCHOR_PREFIX = "channel-";
export interface ChannelOperation {
name: string;
anchorIdentifier: string;
anchorUrl: string;
description?: string;
operation: Operation;
bindings: Bindings;
Expand Down
1 change: 1 addition & 0 deletions springwolf-ui/src/app/models/schema.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Schema {
*/
title: string;
anchorIdentifier: string;
usedBy: { name: string; anchorUrl: string; type: "channel" | "schema" }[];
description?: string;
deprecated?: boolean;

Expand Down
61 changes: 52 additions & 9 deletions springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AsyncApiMapperService {
item.servers,
item.defaultContentType
);
return {
const asyncApi = {
info: this.mapInfo(item),
servers: this.mapServers(item.servers),
channels: channels,
Expand All @@ -59,6 +59,8 @@ export class AsyncApiMapperService {
schemas: this.mapSchemas(item.components.schemas),
},
};
this.postProcess(asyncApi);
return asyncApi;
} catch (e: any) {
this.notificationService.showError(
"Error parsing AsyncAPI: " + e?.message
Expand Down Expand Up @@ -223,16 +225,18 @@ export class AsyncApiMapperService {
operation.reply
);

const anchorIdentifier =
CHANNEL_ANCHOR_PREFIX +
[
mappedOperation.protocol,
channelName,
mappedOperation.operationType,
mappedOperation.message.title,
].join("-");
return {
name: channelName,
anchorIdentifier:
CHANNEL_ANCHOR_PREFIX +
[
mappedOperation.protocol,
channelName,
mappedOperation.operationType,
mappedOperation.message.title,
].join("-"),
anchorIdentifier: anchorIdentifier,
anchorUrl: AsyncApiMapperService.BASE_URL + anchorIdentifier,
description: channel.description,
operation: mappedOperation,
bindings: channel.bindings || {},
Expand Down Expand Up @@ -444,6 +448,7 @@ export class AsyncApiMapperService {
return {
name: schemaName,
title: schemaName.split(".")?.pop() || "undefined-title",
usedBy: [],
anchorIdentifier: schemaName,
description: schema.description,
deprecated: schema.deprecated,
Expand Down Expand Up @@ -514,6 +519,7 @@ export class AsyncApiMapperService {
return {
name: schemaName,
title: schemaName.split(".").pop()!!,
usedBy: [],
anchorIdentifier: schemaName,

// type == ref
Expand All @@ -538,6 +544,43 @@ export class AsyncApiMapperService {
}
}

private postProcess(asyncApi: AsyncApi) {
asyncApi.components.schemas.forEach((schema) => {
asyncApi.channels.forEach((channel) => {
channel.operations.forEach((channelOperation) => {
if (
channelOperation.operation.message.payload.title === schema.name
) {
schema.usedBy.push({
name: channelOperation.name,
anchorUrl: channelOperation.anchorUrl!!,
type: "channel",
});
}
});
});

asyncApi.components.schemas.forEach((otherSchema) => {
Object.values(otherSchema?.properties || {}).forEach((property) => {
if (property.refTitle === schema.name) {
schema.usedBy.push({
name: otherSchema.title,
anchorUrl: otherSchema.anchorUrl!!,
type: "schema",
});
}
});
if (otherSchema.items?.refTitle === schema.name) {
schema.usedBy.push({
name: otherSchema.title,
anchorUrl: otherSchema.anchorUrl!!,
type: "schema",
});
}
});
});
}

private parsingErrorBoundary<T>(path: string, f: () => T): T | undefined {
return catchException(f, (e) => {
this.notificationService.showError(
Expand Down
1 change: 1 addition & 0 deletions springwolf-ui/src/app/service/mock/init-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export const initSchema: Schema = {
title: "",
name: "",
anchorIdentifier: "",
usedBy: [],
};