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

chore: add fixtures to OpenApi Parser v2 #2036

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 @@ -45,6 +45,7 @@ export class XFernGlobalHeadersConverterNode extends BaseOpenApiV3_1ConverterNod
context: this.context,
accessPath: this.accessPath,
pathId: this.pathId,
seenSchemas: new Set(),
}),
];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("ExampleObjectConverterNode", () => {
fields: {
file: { multipartType: "file" },
},
} as RequestMediaTypeObjectConverterNode,
} as unknown as RequestMediaTypeObjectConverterNode,
responseBody: undefined,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("MultipartFormDataPropertySchemaConverterNode", () => {
context: mockContext,
accessPath: [],
pathId: "test",
seenSchemas: new Set(),
});

expect(converter.multipartType).toBe("file");
Expand All @@ -38,6 +39,7 @@ describe("MultipartFormDataPropertySchemaConverterNode", () => {
context: mockContext,
accessPath: [],
pathId: "test",
seenSchemas: new Set(),
});

expect(converter.multipartType).toBe("files");
Expand All @@ -55,6 +57,7 @@ describe("MultipartFormDataPropertySchemaConverterNode", () => {
context: mockContext,
accessPath: [],
pathId: "test",
seenSchemas: new Set(),
});

expect(converter.multipartType).toBe("property");
Expand All @@ -80,6 +83,7 @@ describe("MultipartFormDataPropertySchemaConverterNode", () => {
context: mockContext,
accessPath: [],
pathId: "test",
seenSchemas: new Set(),
});

expect(converter.multipartType).toBe("file");
Expand All @@ -99,6 +103,7 @@ describe("MultipartFormDataPropertySchemaConverterNode", () => {
context: mockContext,
accessPath: [],
pathId: "test",
seenSchemas: new Set(),
});

expect(converter.multipartType).toBeUndefined();
Expand All @@ -118,6 +123,7 @@ describe("MultipartFormDataPropertySchemaConverterNode", () => {
context: mockContext,
accessPath: [],
pathId: "test",
seenSchemas: new Set(),
});

const result = converter.convert();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ describe("ResponseMediaTypeObjectConverterNode", () => {
pathId: "test",
},
"application/json",
undefined
undefined,
"test",
200,
[],
{}
);

expect(converter.contentType).toBe("application/json");
Expand All @@ -48,7 +52,11 @@ describe("ResponseMediaTypeObjectConverterNode", () => {
pathId: "test",
},
"application/octet-stream",
undefined
undefined,
"test",
200,
[],
{}
);

expect(converter.contentType).toBe("application/octet-stream");
Expand All @@ -73,7 +81,11 @@ describe("ResponseMediaTypeObjectConverterNode", () => {
pathId: "test",
},
"application/json",
"json"
"json",
"test",
200,
[],
{}
);

expect(converter.contentType).toBe("application/json");
Expand All @@ -92,7 +104,11 @@ describe("ResponseMediaTypeObjectConverterNode", () => {
pathId: "test",
},
"text/event-stream",
"sse"
"sse",
"test",
200,
[],
{}
);

const result = converter.convert();
Expand All @@ -110,7 +126,11 @@ describe("ResponseMediaTypeObjectConverterNode", () => {
pathId: "test",
},
"application/json",
undefined
undefined,
"test",
200,
[],
{}
);

expect(mockContext.errors.error).toHaveBeenCalledWith({
Expand Down Expand Up @@ -144,7 +164,11 @@ describe("ResponseMediaTypeObjectConverterNode", () => {
pathId: "test",
},
"application/json",
undefined
undefined,
"test",
200,
[],
{}
);

expect(converter.schema).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ describe("ResponseObjectConverterNode", () => {
},
};

const converter = new ResponseObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const converter = new ResponseObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
200,
[],
{}
);

expect(converter.description).toBe("Success response");
expect(converter.responses).toBeDefined();
Expand All @@ -44,12 +50,18 @@ describe("ResponseObjectConverterNode", () => {
},
};

const converter = new ResponseObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const converter = new ResponseObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
200,
[],
{}
);

expect(converter.headers).toBeDefined();
expect(converter.headers?.["X-Rate-Limit"]).toBeDefined();
Expand All @@ -74,12 +86,18 @@ describe("ResponseObjectConverterNode", () => {
},
};

const converter = new ResponseObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const converter = new ResponseObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
200,
[],
{}
);

expect(converter.responses).toBeDefined();
expect(converter.responses?.length).toBe(1);
Expand All @@ -90,12 +108,18 @@ describe("ResponseObjectConverterNode", () => {
$ref: "#/components/responses/NonExistent",
};

new ResponseObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
new ResponseObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
200,
[],
{}
);

expect(mockContext.errors.error).toHaveBeenCalledWith({
message: "Undefined reference: #/components/responses/NonExistent",
Expand Down Expand Up @@ -124,12 +148,18 @@ describe("ResponseObjectConverterNode", () => {
},
};

const converter = new ResponseObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const converter = new ResponseObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
200,
[],
{}
);

const shapes = converter.convert();
expect(shapes).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ describe("ResponsesObjectConverterNode", () => {
},
};

const converter = new ResponsesObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const converter = new ResponsesObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
[],
{}
);

const result = converter.convert();
expect(result?.responses).toBeDefined();
Expand Down Expand Up @@ -60,7 +65,8 @@ describe("ResponsesObjectConverterNode", () => {
pathId: "test",
},
"testpath",
undefined
[],
{}
);

const result = converter.convert();
Expand Down Expand Up @@ -90,12 +96,17 @@ describe("ResponsesObjectConverterNode", () => {
},
};

const converter = new ResponsesObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const converter = new ResponsesObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
[],
{}
);

const result = converter.convert();
expect(result?.responses[0]?.headers).toBeDefined();
Expand All @@ -118,12 +129,17 @@ describe("ResponsesObjectConverterNode", () => {
},
};

const converter = new ResponsesObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const converter = new ResponsesObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
[],
{}
);

const result = converter.convert();
expect(result?.responses).toBeDefined();
Expand All @@ -132,12 +148,17 @@ describe("ResponsesObjectConverterNode", () => {
it("should handle empty responses", () => {
const input: OpenAPIV3_1.ResponsesObject = {};

const converter = new ResponsesObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const converter = new ResponsesObjectConverterNode(
{
input,
context: mockContext,
accessPath: [],
pathId: "test",
},
"test",
[],
{}
);

const result = converter.convert();
expect(result?.responses).toEqual([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class ParameterBaseObjectConverterNode extends BaseOpenApiV3_1ConverterNo
context: this.context,
accessPath: this.accessPath,
pathId: "schema",
seenSchemas: new Set(),
});

// TODO: support multiple examples
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This is not a real OAS type, it is used to encapsulate a large amount of logic

import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1ConverterNodeConstructorArgs } from "../../../BaseOpenApiV3_1Converter.node";
import { BaseOpenApiV3_1ConverterNodeWithTrackingConstructorArgs } from "../../../BaseOpenApiV3_1Converter.node";
import {
ConstArrayToType,
SUPPORTED_MULTIPART_TYPES,
Expand All @@ -17,7 +17,7 @@ export class MultipartFormDataPropertySchemaConverterNode extends SchemaConverte
contentType: string | undefined;

constructor(
args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.SchemaObject>
args: BaseOpenApiV3_1ConverterNodeWithTrackingConstructorArgs<OpenAPIV3_1.SchemaObject>
) {
super(args);
this.safeParse();
Expand Down
Loading
Loading