@@ -1,5 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseApiDocument, validateOpenApi } from "../../src/core/parse";
|
||||
import { collectAsyncOperations } from "../../src/core/asyncapi";
|
||||
import {
|
||||
parseApiDocument,
|
||||
validateApiDescription,
|
||||
validateOpenApi,
|
||||
} from "../../src/core/parse";
|
||||
import {
|
||||
createWorkspace,
|
||||
generateSchemaSample,
|
||||
@@ -23,6 +28,23 @@ describe("OpenAPI parsing and local references", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("recognizes OpenAPI 3.2 QUERY and bounded additional operations", () => {
|
||||
const document = parseApiDocument(
|
||||
`openapi: 3.2.0
|
||||
info: { title: Extended, version: '1' }
|
||||
paths:
|
||||
/search:
|
||||
query: { responses: { '200': { description: ok } } }
|
||||
additionalOperations:
|
||||
COPY: { responses: { '204': { description: copied } } }
|
||||
`,
|
||||
"extended.yaml",
|
||||
);
|
||||
expect(
|
||||
validateOpenApi(document).some((item) => item.level === "error"),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects dangerous YAML keys and alias expansion", () => {
|
||||
expect(() =>
|
||||
parseApiDocument("__proto__: { polluted: true }", "bad.yaml"),
|
||||
@@ -72,4 +94,68 @@ describe("OpenAPI parsing and local references", () => {
|
||||
});
|
||||
expect(sample.notices[0]).toMatch(/cycle/iu);
|
||||
});
|
||||
|
||||
it("inventories AsyncAPI 3.1 channels, operations, and local message samples", () => {
|
||||
const document = parseApiDocument(
|
||||
`asyncapi: 3.1.0
|
||||
info: { title: Events, version: '1' }
|
||||
defaultContentType: application/json
|
||||
servers:
|
||||
broker: { host: broker.example.test, protocol: mqtt }
|
||||
channels:
|
||||
signedUp:
|
||||
address: users.signed-up
|
||||
messages:
|
||||
user: { $ref: '#/components/messages/User' }
|
||||
operations:
|
||||
sendUser:
|
||||
action: send
|
||||
channel: { $ref: '#/channels/signedUp' }
|
||||
components:
|
||||
messages:
|
||||
User:
|
||||
name: UserSignedUp
|
||||
payload:
|
||||
type: object
|
||||
properties: { id: { type: string, example: user-1 } }
|
||||
`,
|
||||
"asyncapi.yaml",
|
||||
);
|
||||
expect(
|
||||
validateApiDescription(document).some((item) => item.level === "error"),
|
||||
).toBe(false);
|
||||
expect(collectAsyncOperations(createWorkspace(document))).toEqual([
|
||||
expect.objectContaining({
|
||||
operationId: "sendUser",
|
||||
action: "send",
|
||||
address: "users.signed-up",
|
||||
protocols: ["mqtt"],
|
||||
messages: [
|
||||
expect.objectContaining({
|
||||
name: "UserSignedUp",
|
||||
payload: { id: "user-1" },
|
||||
}),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("retains focused AsyncAPI 2.x publish/subscribe support", () => {
|
||||
const document = parseApiDocument(
|
||||
`asyncapi: 2.6.0
|
||||
info: { title: Legacy events, version: '1' }
|
||||
channels:
|
||||
users:
|
||||
publish:
|
||||
operationId: publishUser
|
||||
message: { payload: { type: string, example: hello } }
|
||||
`,
|
||||
);
|
||||
expect(collectAsyncOperations(createWorkspace(document))[0]).toMatchObject({
|
||||
action: "publish",
|
||||
address: "users",
|
||||
operationId: "publishUser",
|
||||
messages: [{ payload: "hello" }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user