diff --git a/springwolf-ui/src/app/app.module.ts b/springwolf-ui/src/app/app.module.ts index 9415caa7a..e6499d3d5 100644 --- a/springwolf-ui/src/app/app.module.ts +++ b/springwolf-ui/src/app/app.module.ts @@ -38,6 +38,7 @@ import { PrismEditorComponent } from "./components/new/code/prism-editor.compone import { SchemaNewComponent } from "./components/new/schema/schema.component"; import { ServersNewComponent } from "./components/new/servers/servers.component"; import { SchemasNewComponent } from "./components/new/schemas/schemas.component"; +import { RangeNewComponent } from "./components/new/schema/range/range.component"; @NgModule({ imports: [], @@ -64,6 +65,7 @@ export const declarations = [ ChannelOperationComponent, SchemasNewComponent, SchemaNewComponent, + RangeNewComponent, ]; export const imports = [ DirectivesModule, diff --git a/springwolf-ui/src/app/components/new/schema/range/range.component.html b/springwolf-ui/src/app/components/new/schema/range/range.component.html new file mode 100644 index 000000000..9242c7f56 --- /dev/null +++ b/springwolf-ui/src/app/components/new/schema/range/range.component.html @@ -0,0 +1,14 @@ + + + + {{ lowerBoundInclusive() ? ">=" : ">" }} {{ lowerBound() }} + + + {{ upperBoundInclusive() ? "<=" : "<" }} {{ upperBound() }} + + {{ lowerBoundInclusive() ? "[" : "(" }} {{ lowerBound() }} + .. + {{ upperBound() }} {{ upperBoundInclusive() ? "]" : ")" }} + + diff --git a/springwolf-ui/src/app/components/new/schema/range/range.component.spec.ts b/springwolf-ui/src/app/components/new/schema/range/range.component.spec.ts new file mode 100644 index 000000000..d70867c28 --- /dev/null +++ b/springwolf-ui/src/app/components/new/schema/range/range.component.spec.ts @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +import { RangeNewComponent as RangeComponent } from "./range.component"; +import { render, screen } from "@testing-library/angular"; + +describe("SchemaRangeNewComponent", function () { + it("should create the component", async () => { + await render(RangeComponent, { + componentInputs: { + lowerBound: 0.1, + upperBound: 10, + lowerBoundInclusive: false, + upperBoundInclusive: false, + }, + }); + + expect(screen).toBeTruthy(); + }); + + it("should have `( 0.1 .. 10 )` as value", async () => { + await render(RangeComponent, { + componentInputs: { + lowerBound: 0.1, + upperBound: 10, + lowerBoundInclusive: false, + upperBoundInclusive: false, + }, + }); + + expect(screen.getByText("( 0.1 .. 10 )")).toBeTruthy(); + }); + + it("should have `[ 0.1 .. 10 )` as value", async () => { + await render(RangeComponent, { + componentInputs: { + lowerBound: 0.1, + upperBound: 10, + lowerBoundInclusive: true, + upperBoundInclusive: false, + }, + }); + + expect(screen.getByText("[ 0.1 .. 10 )")).toBeTruthy(); + }); + + it("should have `( 0.1 .. 10 ]` as value", async () => { + await render(RangeComponent, { + componentInputs: { + lowerBound: 0.1, + upperBound: 10, + lowerBoundInclusive: false, + upperBoundInclusive: true, + }, + }); + + expect(screen.getByText("( 0.1 .. 10 ]")).toBeTruthy(); + }); + + it("should have `[ 0.1 .. 10 ]` as value", async () => { + await render(RangeComponent, { + componentInputs: { + lowerBound: 0.1, + upperBound: 10, + }, + }); + + expect(screen.getByText("[ 0.1 .. 10 ]")).toBeTruthy(); + }); + + it("should have `> 0.1` as value", async () => { + await render(RangeComponent, { + componentInputs: { + lowerBound: 0.1, + lowerBoundInclusive: false, + }, + }); + + expect(screen.getByText("> 0.1")).toBeTruthy(); + }); + + it("should have `< 10` as value", async () => { + await render(RangeComponent, { + componentInputs: { + upperBound: 10, + upperBoundInclusive: false, + }, + }); + + expect(screen.getByText("< 10")).toBeTruthy(); + }); + + it("should have `>= 0.1` as value", async () => { + await render(RangeComponent, { + componentInputs: { + lowerBound: 0.1, + }, + }); + + expect(screen.getByText(">= 0.1")).toBeTruthy(); + }); + + it("should have `<= 10` as value", async () => { + await render(RangeComponent, { + componentInputs: { + upperBound: 10, + }, + }); + + expect(screen.getByText("<= 10")).toBeTruthy(); + }); +}); diff --git a/springwolf-ui/src/app/components/new/schema/range/range.component.ts b/springwolf-ui/src/app/components/new/schema/range/range.component.ts new file mode 100644 index 000000000..6f32a460b --- /dev/null +++ b/springwolf-ui/src/app/components/new/schema/range/range.component.ts @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +import { Component, input } from "@angular/core"; + +@Component({ + selector: "app-schema-range-new", + templateUrl: "./range.component.html", +}) +export class RangeNewComponent { + lowerBound = input(); + upperBound = input(); + lowerBoundInclusive = input(true, { + transform: (value: boolean | string) => value === true || value == "true", + }); + upperBoundInclusive = input(true, { + transform: (value: boolean | string) => value === true || value == "true", + }); +} diff --git a/springwolf-ui/src/app/components/new/schema/schema.component.css b/springwolf-ui/src/app/components/new/schema/schema.component.css index 1240db18b..964ca0132 100644 --- a/springwolf-ui/src/app/components/new/schema/schema.component.css +++ b/springwolf-ui/src/app/components/new/schema/schema.component.css @@ -3,11 +3,22 @@ color: red; } +.deprecated { + color: red; +} + .description { overflow: auto; } .example { - display: block; word-break: break-all; } + +.attribute { + background-color: rgb(128, 90, 213); + color: rgb(255, 255, 255); + margin: 0 0.2em 0.2em 0; + padding: 0.1em 0.2em 0.1em 0.2em; + border-radius: 4px; +} diff --git a/springwolf-ui/src/app/components/new/schema/schema.component.html b/springwolf-ui/src/app/components/new/schema/schema.component.html index 11df0b34d..45b7b26fc 100644 --- a/springwolf-ui/src/app/components/new/schema/schema.component.html +++ b/springwolf-ui/src/app/components/new/schema/schema.component.html @@ -15,11 +15,14 @@ *ngFor="let property of schema().properties || {} | keyvalue" lines="99" > - - {{ property.key }} + + {{ property.key }} * +  (deprecated)   - -
+ + + + + + items + + + Unique items: + {{ value.uniqueItems ? "yes" : "no" }} + + + + + pattern: + + {{ value.pattern }} + + + + + length + + + + + value range + + + Multiple of + {{ value.multipleOf }} + + + + 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 2036f221e..0541ab894 100644 --- a/springwolf-ui/src/app/components/new/schemas/schemas.component.html +++ b/springwolf-ui/src/app/components/new/schemas/schemas.component.html @@ -11,7 +11,7 @@

Schemas

- Title + Name {{ schema.name }}
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 f7a4bca2b..7ff60443c 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 @@ -15,6 +15,8 @@ describe("SchemaRangeComponent", function () { it("should create the component", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", minimum: 0.1, maximum: 10, exclusiveMinimum: true, @@ -27,6 +29,8 @@ describe("SchemaRangeComponent", function () { it("should have `( 0.1 .. 10 )` as value", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", minimum: 0.1, maximum: 10, exclusiveMinimum: true, @@ -39,6 +43,8 @@ describe("SchemaRangeComponent", function () { it("should have `[ 0.1 .. 10 )` as value", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", minimum: 0.1, maximum: 10, exclusiveMinimum: false, @@ -51,6 +57,8 @@ describe("SchemaRangeComponent", function () { it("should have `( 0.1 .. 10 ]` as value", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", minimum: 0.1, maximum: 10, exclusiveMinimum: true, @@ -63,6 +71,8 @@ describe("SchemaRangeComponent", function () { it("should have `[ 0.1 .. 10 ]` as value", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", minimum: 0.1, maximum: 10, }); @@ -73,6 +83,8 @@ describe("SchemaRangeComponent", function () { it("should have `> 0.1` as value", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", minimum: 0.1, exclusiveMinimum: true, }); @@ -83,6 +95,8 @@ describe("SchemaRangeComponent", function () { it("should have `< 10` as value", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", maximum: 10, exclusiveMaximum: true, }); @@ -93,6 +107,8 @@ describe("SchemaRangeComponent", function () { it("should have `>= 0.1` as value", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", minimum: 0.1, }); @@ -102,6 +118,8 @@ describe("SchemaRangeComponent", function () { it("should have `<= 10` as value", async () => { await renderComponent({ title: "test", + name: "test", + anchorIdentifier: "test", maximum: 10, }); diff --git a/springwolf-ui/src/app/components/schemas/schemas.component.html b/springwolf-ui/src/app/components/schemas/schemas.component.html index d22ad516a..a6ae42c2e 100644 --- a/springwolf-ui/src/app/components/schemas/schemas.component.html +++ b/springwolf-ui/src/app/components/schemas/schemas.component.html @@ -20,7 +20,7 @@

{{ schema.value.title }}

- Title: {{ schema.value.name }} + Name: {{ schema.value.name }}

diff --git a/springwolf-ui/src/app/models/schema.model.ts b/springwolf-ui/src/app/models/schema.model.ts index d42c7fa35..e75041073 100644 --- a/springwolf-ui/src/app/models/schema.model.ts +++ b/springwolf-ui/src/app/models/schema.model.ts @@ -2,27 +2,43 @@ import { Example } from "./example.model"; export interface Schema { - name?: string; + /** + * Fully qualified schema name + */ + name: string; + /** + * Short schema name + */ title: string; + anchorIdentifier: string; description?: string; + deprecated?: boolean; - refName?: string; - refTitle?: string; - anchorIdentifier?: string; - anchorUrl?: string; + enum?: string[]; + example?: Example; type?: string; + format?: string; + // type == ref + anchorUrl?: string; + refName?: string; + refTitle?: string; // type == object properties?: { [key: string]: Schema }; + required?: string[]; // type == array items?: Schema; - - format?: string; - required?: string[]; - enum?: string[]; - example?: Example; + minItems?: number; + maxItems?: number; + uniqueItems?: boolean; + // type == string + minLength?: number; + maxLength?: number; + pattern?: string; + // type == number minimum?: number; maximum?: number; exclusiveMinimum?: boolean; exclusiveMaximum?: boolean; + multipleOf?: number; } 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 63ee9d51f..a151cfe32 100644 --- a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts +++ b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts @@ -444,19 +444,28 @@ export class AsyncApiMapperService { return { name: schemaName, title: schemaName.split(".")?.pop() || "undefined-title", - description: schema.description, anchorIdentifier: schemaName, + description: schema.description, + deprecated: schema.deprecated, + + enum: schema.enum, + example, type: schema.type, - required: schema.required, format: schema.format, - + // type == object properties, + required: schema.required, + // type == array items, - enum: schema.enum, - - example, - + minItems: schema.minItems, + maxItems: schema.maxItems, + uniqueItems: schema.uniqueItems, + // type == string + minLength: schema.minLength, + maxLength: schema.maxLength, + pattern: schema.pattern, + // type == number minimum: schema.exclusiveMinimum ? schema.exclusiveMinimum : schema.minimum, @@ -465,6 +474,7 @@ export class AsyncApiMapperService { : schema.maximum, exclusiveMinimum: schema.minimum == schema.exclusiveMinimum, exclusiveMaximum: schema.maximum == schema.exclusiveMaximum, + multipleOf: schema.multipleOf, }; } @@ -504,12 +514,12 @@ export class AsyncApiMapperService { return { name: schemaName, title: schemaName.split(".").pop()!!, + anchorIdentifier: schemaName, + // type == ref + anchorUrl: AsyncApiMapperService.BASE_URL + this.resolveRef(schema.$ref), refName: schema.$ref, refTitle: this.resolveRef(schema.$ref), - - anchorIdentifier: schemaName, - anchorUrl: AsyncApiMapperService.BASE_URL + this.resolveRef(schema.$ref), }; } diff --git a/springwolf-ui/src/app/service/asyncapi/models/schema.model.ts b/springwolf-ui/src/app/service/asyncapi/models/schema.model.ts index 063142d39..2ef34f5a7 100644 --- a/springwolf-ui/src/app/service/asyncapi/models/schema.model.ts +++ b/springwolf-ui/src/app/service/asyncapi/models/schema.model.ts @@ -3,23 +3,36 @@ export type ServerAsyncApiSchemaOrRef = ServerAsyncApiSchema | { $ref: string }; export interface ServerAsyncApiSchema { description?: string; - type: string; - format?: string; + deprecated?: boolean; + enum?: string[]; + examples?: any[]; - properties?: { - [key: string]: ServerAsyncApiSchemaOrRef; - }; + type: string; + format?: string; + // type == ref + not?: ServerAsyncApiSchemaOrRef; allOf?: ServerAsyncApiSchemaOrRef[]; anyOf?: ServerAsyncApiSchemaOrRef[]; oneOf?: ServerAsyncApiSchemaOrRef[]; - - items?: ServerAsyncApiSchemaOrRef; - examples?: any[]; - + // type == object + properties?: { + [key: string]: ServerAsyncApiSchemaOrRef; + }; required?: string[]; + // type == array + items?: ServerAsyncApiSchemaOrRef; + minItems?: number; + maxItems?: number; + uniqueItems?: boolean; + // type == string + minLength?: number; + maxLength?: number; + pattern?: string; + // type == number minimum?: number; maximum?: number; exclusiveMinimum?: number; exclusiveMaximum?: number; + multipleOf?: number; } diff --git a/springwolf-ui/src/app/service/mock/init-values.ts b/springwolf-ui/src/app/service/mock/init-values.ts index 206c0b4b6..e5bd12e12 100644 --- a/springwolf-ui/src/app/service/mock/init-values.ts +++ b/springwolf-ui/src/app/service/mock/init-values.ts @@ -39,4 +39,6 @@ export const initOperation: Operation = { export const initSchema: Schema = { title: "", + name: "", + anchorIdentifier: "", }; diff --git a/springwolf-ui/src/main.css b/springwolf-ui/src/main.css index f1fd44d4f..a0742e304 100644 --- a/springwolf-ui/src/main.css +++ b/springwolf-ui/src/main.css @@ -32,6 +32,9 @@ a { display: flex; flex-direction: column; } +.flex-wrap { + flex-wrap: wrap; +} .gap-8 { gap: 8px; }