8000 fix(OpenAPI): Don't extract entire parameter object to · aklinker1/zeta@0cdb0e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cdb0e3

Browse files
committed
fix(OpenAPI): Don't extract entire parameter object to
`#components/schema`, just the schema
1 parent f821372 commit 0cdb0e3

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎example.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import { version } from "./package.json" with { type: "json" };
99
import { z } from "zod/v4";
1010
import { zodSchemaAdapter } from "./src/adapters/zod-schema-adapter";
1111

12+
const EntryId = z.coerce.number().int().min(0).meta({ ref: "EntryId" });
13+
type EntryId = z.infer<typeof EntryId>;
14+
1215
const Entry = z
1316
.object({
14-
id: z.number(),
17+
id: EntryId,
1518
text: z.string(),
1619
})
1720
.meta({
@@ -84,10 +87,15 @@ const app = createApp({
8487
description: "Create a new entry",
8588
tags: ["Entries"],
8689
body: Entry,
90+
responses: {
91+
[HttpStatus.Accepted]: NoResponse.meta({
92+
responseDescription: "Entry created",
93+
}),
94+
},
8795
},
88-
({ body, set }) => {
96+
({ body, status }) => {
8997
entries.push(body);
90-
set.status = HttpStatus.Accepted;
98+
return status(HttpStatus.Accepted, undefined);
9199
},
92100
)
93101
.get(
@@ -97,7 +105,7 @@ const app = createApp({
97105
summary: "Get entry by ID",
98106
description: "Get an entry by ID",
99107
tags: ["Entries"],
100-
params: z.object({ id: z.coerce.number() }),
108+
params: z.object({ id: EntryId }),
101109
responses: {
102110
[HttpStatus.Ok]: Entry,
103111
[HttpStatus.NotFound]: ErrorResponse,
@@ -117,7 +125,7 @@ const app = createApp({
117125
operationId: "deleteEntry",
118126
summary: "Delete Entry",
119127
tags: ["Entries"],
120-
params: z.object({ id: z.coerce.number() }),
128+
params: z.object({ id: EntryId }),
121129
responses: {
122130
[HttpStatus.NoContent]: NoResponse.meta({
123131
responseDescription: "Entry deleted",

‎src/open-api.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ function mapParameters(
143143

144144
return adapter
145145
.parseParamsRecord(schema)
146-
.map(({ schema, optional, ...param }) => ({
147-
...param,
146+
.map(({ schema, optional, description, name }) => ({
147+
name,
148148
in: _in,
149+
description,
149150
schema: adapter.toJsonSchema(schema),
150151
required: !optional,
151152
}));

0 commit comments

Comments
 (0)
0