Skip to content
This repository was archived by the owner on Jun 18, 2023. It is now read-only.

Commit e3a71fe

Browse files
timonbackstavshamir
authored andcommitted
feat: Add anchorIdentifier to schema
1 parent 69c812c commit e3a71fe

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/app/schemas/schemas.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1>Schemas</h1>
22
<mat-accordion>
3-
<mat-expansion-panel *ngFor="let schema of schemas | keyvalue;" [id]="schema.key" [expanded]="selectedSchema == schema.key" (opened)="this.setSchemaSelection(schema.key)">
3+
<mat-expansion-panel *ngFor="let schema of schemas | keyvalue;" [id]="schema.value.anchorIdentifier" [expanded]="selectedSchema == schema.value.anchorIdentifier" (opened)="this.setSchemaSelection(schema.value)">
44
<mat-expansion-panel-header>
55
<mat-panel-title>
66
<h3>{{ schema.key }}</h3>

src/app/schemas/schemas.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export class SchemasComponent implements OnInit {
2323
this.asyncApiService.getAsyncApis().subscribe(asyncapi => this.schemas = asyncapi.components.schemas);
2424
}
2525

26-
setSchemaSelection(schema: string): void {
27-
window.location.hash = '#' + schema
26+
setSchemaSelection(schema: Schema): void {
27+
window.location.hash = '#' + schema.anchorIdentifier
2828
}
2929
setSchemaSelectionFromLocation(): void {
3030
this.selectedSchema = window.location.hash.substr(1);

src/app/shared/asyncapi-mapper.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,16 @@ export class AsyncApiMapperService {
136136

137137
private mapSchemas(schemas: Map<string, ServerAsyncApiSchema>): Map<string, Schema> {
138138
const s = new Map<string, Schema>();
139-
Object.entries(schemas).forEach(([k, v]) => s.set(k, this.mapSchema(v)));
139+
Object.entries(schemas).forEach(([k, v]) => s.set(k, this.mapSchema(k, v)));
140140
return s;
141141
}
142142

143-
private mapSchema(schema: ServerAsyncApiSchema): Schema {
143+
private mapSchema(schemaName: string, schema: ServerAsyncApiSchema): Schema {
144144
const properties = schema.properties !== undefined ? this.mapSchemas(schema.properties) : undefined
145145
const example = schema.example !== undefined ? new Example(schema.example) : undefined
146146
return {
147147
description: schema.description,
148+
anchorIdentifier: schemaName,
148149
type: schema.type,
149150
format: schema.format,
150151
enum: schema.enum,

src/app/shared/models/schema.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Example } from './example.model';
22

33
export interface Schema {
44
description?: string;
5+
anchorIdentifier: string;
56
type: string;
67
format?: string;
78
enum?: string[];

0 commit comments

Comments
 (0)