-
-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
When putting an object inside an union (or something similar to that), and setting unusedIO: 'input'
, it still results in an Output
type being generated.
Just having a top-level object
does not seem to have the same effect.
Tried to get rid of it, but got lost in the createComponents
-> createIOSchemas
-> createSchemas
call tree.
The Output
schema gets generated in createIOSchemas
-> renameComponents
when io: "output"
, but I could not find a way to prevent that since I did not figure out where the schema got there in the first place.
I tried adding ctx.io !== ...zodType.unusedIO
in various places (createComponents
, createIOSchemas
) but it still somehow got included...
Reproducer test (into document.test.ts
):
it('unusedIO input', () => {
const Obj = z
.object({
field: z.string(),
})
.meta({ id: 'Obj', unusedIO: 'input' });
const Union = z.union([Obj]).meta({ id: 'Union', unusedIO: 'input' });
const document = createDocument({
info: {
title: 'My API',
version: '1.0.0',
},
openapi: '3.1.0',
components: {
schemas: {
Union,
},
},
});
expect(document).toMatchInlineSnapshot(`
{
"components": {
"schemas": {
"Obj": {
"properties": {
"field": {
"type": "string",
},
},
"required": [
"field",
],
"type": "object",
},
"ObjOutput": {
"additionalProperties": false,
"properties": {
"field": {
"type": "string",
},
},
"required": [
"field",
],
"type": "object",
},
"Union": {
"anyOf": [
{
"$ref": "#/components/schemas/Obj",
},
],
},
},
},
"info": {
"title": "My API",
"version": "1.0.0",
},
"openapi": "3.1.0",
}
`);
});
samchungy
Metadata
Metadata
Assignees
Labels
No labels