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): add syntax highlighting for other payloads than json #927

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 @@ -38,6 +38,7 @@ describe("InfoComponent", function () {
components: {
schemas: new Map<string, Schema>(),
},
defaultContentType: "application/json",
}),
};

Expand Down
1 change: 1 addition & 0 deletions springwolf-ui/src/app/components/mock-components.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class MockChannelOperationComponent {
@Component({ selector: "app-prism-editor", template: "" })
export class MockPrismEditorComponent {
code = input<string>("");
language = input<string>("");
}

@Component({ selector: "app-schema-new", template: "" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ <h6>Payload</h6>
</div>

<div class="width-6/12 width-12/12-s">
<app-prism-editor [(code)]="defaultExample.value" language="json" />
<app-prism-editor
[(code)]="defaultExample.value"
[language]="exampleContentType"
/>

<div class="flex space-between">
<div class="flex gap-8">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class ChannelOperationComponent implements OnInit {
defaultSchema: Schema = initSchema;
defaultExample: Example = initExample;
originalDefaultExample: Example = this.defaultExample;
exampleContentType: string = "json";

headers: Schema = initSchema;
headersExample: Example = initExample;
Expand Down Expand Up @@ -56,6 +57,8 @@ export class ChannelOperationComponent implements OnInit {
const schema = schemas.get(schemaIdentifier)!!;
this.defaultSchema = schema;
this.originalDefaultExample = schema.example || noExample;
this.exampleContentType =
this.operation().message.contentType.split("/").pop() || "json";

const headersSchemaIdentifier =
this.operation().message.headers.name.slice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import { highlightBracketPairs } from "prism-code-editor/highlight-brackets";
import { editHistory } from "prism-code-editor/commands";
import { copyButton } from "prism-code-editor/copy-button";
import "prism-code-editor/prism/languages/json";
import "prism-code-editor/prism/languages/yaml";
import "prism-code-editor/prism/languages/http";
import "prism-code-editor/prism/languages/java";
import "prism-code-editor/prism/languages/kotlin";
import "prism-code-editor/prism/languages/markdown";
import "prism-code-editor/prism/languages/xml";

@Component({
selector: "app-prism-editor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("SchemasNewComponent", () => {
components: {
schemas: new Map<string, Schema>(),
},
defaultContentType: "application/json",
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("SchemasComponent", () => {
components: {
schemas: new Map<string, Schema>(),
},
defaultContentType: "application/json",
}),
};

Expand Down
1 change: 1 addition & 0 deletions springwolf-ui/src/app/models/asyncapi.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface AsyncApi {
*/
channelOperations: ChannelOperation[];
components: { schemas: Map<string, Schema> };
defaultContentType: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class AsyncApiMapperService {
components: {
schemas: this.mapSchemas(item.components.schemas),
},
defaultContentType: item.defaultContentType,
};
this.postProcess(asyncApi);
return asyncApi;
Expand Down
4 changes: 4 additions & 0 deletions springwolf-ui/src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ a {
background-color: #f5f5f5;
}

.mat-typography markdown > p {
margin: 0;
}

/* Migration away from @angular/flex-layout (https://github.com/angular/flex-layout/issues/1426) */
.flex {
display: flex;
Expand Down