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

Commit 4ea49d5

Browse files
DmitriButorchinstavshamir
authored andcommitted
Add display of description, examples and required fields
springwolf/springwolf-core#35
1 parent c51b1f8 commit 4ea49d5

15 files changed

+121
-66
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'io.github.springwolf'
9-
version = '0.4.0' + (Boolean.valueOf(System.getProperty('snapshot')) ? '-SNAPSHOT' : '')
9+
version = '0.5.0' + (Boolean.valueOf(System.getProperty('snapshot')) ? '-SNAPSHOT' : '')
1010
sourceCompatibility = '1.8'
1111

1212
node {

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { AsyncApiService } from './shared/asyncapi.service';
1919
import { MockServer } from './shared/mock-server';
2020
import { PublisherService } from './shared/publisher.service';
2121
import { FormsModule } from '@angular/forms';
22+
import { JsonComponent } from './shared/components/json/json.component';
2223

2324
@NgModule({
2425
declarations: [
@@ -30,6 +31,7 @@ import { FormsModule } from '@angular/forms';
3031
ChannelMainComponent,
3132
SchemasComponent,
3233
SchemaComponent,
34+
JsonComponent,
3335
],
3436
imports: [
3537
BrowserModule,

src/app/channels/channel-main/channel-main.component.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
textarea {
22
margin-top: 16px;
33
padding: 8px;
4-
width: 99%;
54
border-radius: 4px;
65
border-width: 0;
76
line-height: 24px;

src/app/channels/channel-main/channel-main.component.html

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@
22
<mat-divider></mat-divider>
33
<mat-tab-group animationDuration="0ms">
44
<mat-tab label="Example">
5-
<textarea spellcheck="false" #exampleTextArea [rows]="exampleTextAreaLineCount"
6-
[value]="defaultExample?.value" (keyup)="recalculateLineCount(exampleTextArea.value)"></textarea>
7-
<div fxLayout fxLayoutGap="8px">
8-
<button mat-raised-button color="primary" (click)="publish(exampleTextArea.value)">
9-
Publish
10-
</button>
11-
<button mat-raised-button color="primary"
12-
(click)="exampleTextArea.value = defaultExample.value; exampleTextAreaLineCount=defaultExample.lineCount">
13-
Default
14-
</button>
15-
<button mat-raised-button color="primary" [cdkCopyToClipboard]="exampleTextArea.value">Copy</button>
5+
<div fxLayout="column">
6+
<textarea spellcheck="false"
7+
#exampleTextArea
8+
[rows]="exampleTextAreaLineCount"
9+
[value]="defaultExample?.value"
10+
(keyup)="recalculateLineCount(exampleTextArea.value)"
11+
></textarea>
12+
<div fxLayout fxLayoutGap="8px">
13+
<button mat-raised-button color="primary" (click)="publish(exampleTextArea.value)">
14+
Publish
15+
</button>
16+
<button mat-raised-button color="primary"
17+
(click)="exampleTextArea.value = defaultExample.value; exampleTextAreaLineCount=defaultExample.lineCount">
18+
Default
19+
</button>
20+
<button mat-raised-button color="primary" [cdkCopyToClipboard]="exampleTextArea.value">Copy</button>
21+
</div>
1622
</div>
1723
</mat-tab>
1824
<mat-tab label="Schema">
1925
<h4>{{ operation.message.title }} </h4>
2026
<div class="payload-name">{{ operation.message.name }}</div>
21-
<app-schema *ngIf="schema" [schema]="schema" [root]="schemaRoot"></app-schema>
27+
<app-schema *ngIf="schema" [schema]="schema"></app-schema>
2228
</mat-tab>
2329
<mat-tab label="Bindings">
24-
<app-schema [schema]="operation.bindings" [root]="protocolName"></app-schema>
30+
<app-json [data]="operation.bindings[protocolName]"></app-json>
2531
</mat-tab>
2632
</mat-tab-group>
2733
</section>

src/app/channels/channel-main/channel-main.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class ChannelMainComponent implements OnInit {
2222
schema: Schema;
2323
defaultExample: Example;
2424
exampleTextAreaLineCount: number;
25-
schemaRoot = "properties";
2625
protocolName: string;
2726
nameSubscription: Subscription;
2827

@@ -36,8 +35,8 @@ export class ChannelMainComponent implements OnInit {
3635
this.asyncApiService.getAsyncApis().subscribe(
3736
asyncapi => {
3837
let schemas: Map<string, Schema> = asyncapi.get(this.docName).components.schemas;
39-
this.schema = schemas.get(this.operation.message.title);
40-
this.defaultExample = this.schema.example;
38+
this.schema = schemas[this.operation.message.title];
39+
this.defaultExample = new Example(this.schema.example);
4140
this.exampleTextAreaLineCount = this.defaultExample.lineCount;
4241
}
4342
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.schema {
2+
font-weight: 500;
3+
}
4+
5+
.key {
6+
width: 12em;
7+
vertical-align: top;
8+
}
9+
10+
.required {
11+
color: red;
12+
}
13+
14+
.type {
15+
color: #55A;
16+
}
17+
18+
.example {
19+
color: #6B6B6B;
20+
font-style: italic;
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<table class="schema">
2+
<tbody>
3+
<tr *ngFor="let property of schema.properties | keyvalue">
4+
<td class="key">
5+
{{ property.key }}
6+
<span class="required" *ngIf="schema.required?.includes(property.key)">*</span>
7+
</td>
8+
<td>
9+
<span class="type" *ngIf="property.value.type">{{ property.value.type }}</span>
10+
<span class="type" *ngIf="property.value['$ref']">
11+
<a [href]="'#' + property.value['$ref'].split('/').pop()">{{ property.value['$ref'] }}</a>
12+
</span>
13+
<span class="format" *ngIf="property.value.format">({{ property.value.format }})</span>
14+
<div class="description">{{ property.value.description }}</div>
15+
<span class="example" *ngIf="property.value.example">example: {{ property.value.example }}</span>
16+
<mat-select *ngIf="property.value.enum" placeholder="Enum">
17+
<mat-option *ngFor="let enum of property.value.enum" [value]="enum">{{ enum }}</mat-option>
18+
</mat-select>
19+
</td>
20+
</tbody>
21+
</table>
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
import { Component, OnInit, Input } from '@angular/core';
1+
import { Component, Input } from '@angular/core';
2+
import { Schema } from 'src/app/shared/models/schema.model';
23

34
@Component({
45
selector: 'app-schema',
5-
template: '<pre><code [highlight]="json"></code></pre>',
6-
styles: [`code {
7-
margin-top: 16px;
8-
padding: 8px;
9-
border-radius: 4px;
10-
}`]
6+
templateUrl: './schema.component.html',
7+
styleUrls: ['./schema.component.css']
118
})
12-
export class SchemaComponent implements OnInit {
9+
export class SchemaComponent {
1310

14-
@Input() root: string;
15-
@Input() schema: any;
16-
json: string;
17-
18-
constructor() { }
19-
20-
ngOnInit(): void {
21-
this.json = JSON.stringify(this.schema[this.root], null, 2);
22-
}
11+
@Input() schema: Schema;
2312

2413
}

src/app/schemas/schemas.component.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h3 {
2+
margin: 0;
3+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<h1>Schemas</h1>
22
<mat-accordion>
3-
<mat-expansion-panel *ngFor="let schema of schemas | keyvalue">
3+
<mat-expansion-panel *ngFor="let schema of schemas | keyvalue" [id]="schema.key">
44
<mat-expansion-panel-header>
55
<mat-panel-title>
66
<h3>{{ schema.key }}</h3>
77
</mat-panel-title>
8+
<mat-panel-description>
9+
{{ schema.value.description }}
10+
</mat-panel-description>
811
</mat-expansion-panel-header>
9-
<app-schema [schema]="schema?.value" [root]="schemaRoot"></app-schema>
12+
<app-schema [schema]="schema?.value"></app-schema>
1013
</mat-expansion-panel>
1114
</mat-accordion>

0 commit comments

Comments
 (0)