Skip to content
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
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
coverage/
dist/
flake.lock
packages/openapi-generator/test/
21 changes: 17 additions & 4 deletions packages/openapi-generator/test/codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ export const FOO = t.union([t.string, t.number]);
testCase('union type is parsed', UNION, {
FOO: {
type: 'union',
schemas: [{ type: 'string', primitive: true }, { type: 'number', primitive: true }],
schemas: [
{ type: 'string', primitive: true },
{ type: 'number', primitive: true },
],
},
});

Expand All @@ -235,7 +238,10 @@ export const FOO = t.union([...common, t.number]);
testCase('union type with spread is parsed', UNION_SPREAD, {
FOO: {
type: 'union',
schemas: [{ type: 'string', primitive: true }, { type: 'number', primitive: true }],
schemas: [
{ type: 'string', primitive: true },
{ type: 'number', primitive: true },
],
},
common: {
type: 'tuple',
Expand All @@ -252,7 +258,10 @@ export const FOO = t.union([...[t.string], t.number]);
testCase('union type with inline spread is parsed', UNION_INLINE_SPREAD, {
FOO: {
type: 'union',
schemas: [{ type: 'string', primitive: true }, { type: 'number', primitive: true }],
schemas: [
{ type: 'string', primitive: true },
{ type: 'number', primitive: true },
],
},
});

Expand Down Expand Up @@ -285,7 +294,11 @@ export const FOO = t.record(t.string, t.number);
`;

testCase('record type is parsed', RECORD, {
FOO: { type: 'record', domain: {type: 'string', primitive: true}, codomain: { type: 'number', primitive: true } },
FOO: {
type: 'record',
domain: { type: 'string', primitive: true },
codomain: { type: 'number', primitive: true },
},
});

const ENUM = `
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-generator/test/externalModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function testCase(
for (const path of Object.keys(expected)) {
const resolvedPath = p.resolve(path);
const sourceFile = project.get(resolvedPath);

if (sourceFile === undefined) {
throw new Error(`Source file ${path} not found`);
}
Expand Down
143 changes: 74 additions & 69 deletions packages/openapi-generator/test/externalModuleApiSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async function testCase(
const codecE = parseCodecInitializer(project, newSourceFile, init);
if (E.isLeft(codecE)) {
errors.push(
`Could not parse codec '${ref.name}' in '${ref.location}': ${codecE.left}`,
`Could not parse codec '${ref.name}' in '${ref.location}': ${codecE.left}`,
);
break;
}
Expand All @@ -117,15 +117,15 @@ async function testCase(
const openapi = convertRoutesToOpenAPI(
{
title: name,
version: "1.0.0",
version: '1.0.0',
description,
},
[],
apiSpec,
components,
);

assert.deepStrictEqual(errors, expectedErrors);
assert.deepStrictEqual(errors, expectedErrors);
assert.deepStrictEqual(openapi, expected);
});
}
Expand Down Expand Up @@ -275,91 +275,96 @@ testCase(
'simple api spec with exported union type',
'test/sample-types/apiSpecWithUnion.ts',
{
openapi: "3.0.3",
openapi: '3.0.3',
info: {
title: "simple api spec with exported union type",
version: "1.0.0",
description: "simple api spec with exported union type"
title: 'simple api spec with exported union type',
version: '1.0.0',
description: 'simple api spec with exported union type',
},
paths: {
"/test": {
'/test': {
get: {
parameters: [],
responses: {
200: {
description: "OK",
description: 'OK',
content: {
'application/json': {
schema: {
$ref: "#/components/schemas/SampleUnion"
}
}
}
}
}
}
}
$ref: '#/components/schemas/SampleUnion',
},
},
},
},
},
},
},
},
components: {
schemas: {
SampleUnion: {
title: "SampleUnion",
title: 'SampleUnion',
oneOf: [
{
type: "string"
type: 'string',
},
{
type: "number"
}
]
}
}
}
type: 'number',
},
],
},
},
},
},
[]
)
[],
);

testCase("simple api spec with custom codec", "test/sample-types/apiSpecWithCustomCodec.ts", {
openapi: "3.0.3",
info: {
title: "simple api spec with custom codec",
version: "1.0.0",
description: "simple api spec with custom codec"
},
paths: {
"/test": {
get: {
parameters: [],
responses: {
200: {
description: "OK",
content: {
'application/json': {
schema: {
type: 'string',
description: 'Sample custom codec',
example: 'sample',
format: 'sample'
}
}
}
testCase(
'simple api spec with custom codec',
'test/sample-types/apiSpecWithCustomCodec.ts',
{
openapi: '3.0.3',
info: {
title: 'simple api spec with custom codec',
version: '1.0.0',
description: 'simple api spec with custom codec',
},
paths: {
'/test': {
get: {
parameters: [],
responses: {
200: {
description: 'OK',
content: {
'application/json': {
schema: {
type: 'string',
description: 'Sample custom codec',
example: 'sample',
format: 'sample',
},
},
},
},
201: {
description: 'Created',
content: {
'application/json': {
schema: {
type: 'number',
description: 'Another sample codec',
},
},
},
},
},
201: {
description: 'Created',
content: {
'application/json': {
schema: {
type: 'number',
description: 'Another sample codec',
}
}
}
}
}
}
}
},
},
},
components: {
schemas: {},
},
},
components: {
schemas: {}
}
}, []);
[],
);
Loading