|
| 1 | +import type { StandardSchemaV1 } from "@standard-schema/spec"; |
1 | 2 | import type { OpenAPI } from "openapi-types"; |
2 | | -import type { App, BasePath, SchemaAdapter } from "./types"; |
3 | 3 | import type { CreateAppOptions } from "./app"; |
4 | | -import type { StandardSchemaV1 } from "@standard-schema/spec"; |
5 | | -import { getHttpStatusName } from "./status"; |
| 4 | +import { getMeta } from "./meta"; |
6 | 5 | import { |
7 | 6 | ErrorResponseJsonSchema, |
8 | 7 | isZetaSchema, |
9 | 8 | type ZetaSchema, |
10 | 9 | } from "./schema"; |
11 | | -import { getMeta } from "./meta"; |
| 10 | +import { getHttpStatusName } from "./status"; |
| 11 | +import type { App, BasePath, SchemaAdapter } from "./types"; |
12 | 12 |
|
13 | 13 | export function buildOpenApiDocs( |
14 | 14 | options: CreateAppOptions<any> | undefined, |
@@ -146,19 +146,25 @@ export function buildScalarHtml( |
146 | 146 | function mapParameters( |
147 | 147 | adapter: SchemaAdapter, |
148 | 148 | schema: StandardSchemaV1 | undefined, |
149 | | - _in: "query" | "path" | "header", |
| 149 | + in_: "query" | "path" | "header", |
150 | 150 | ): OpenAPI.Parameters { |
151 | 151 | if (!schema) return []; |
152 | 152 |
|
153 | | - return adapter |
154 | | - .parseParamsRecord(schema) |
155 | | - .map(({ schema, optional, description, name }) => ({ |
| 153 | + const openApiSchema = adapter.toJsonSchema(schema); |
| 154 | + if (openApiSchema.type !== "object") |
| 155 | + throw Error( |
| 156 | + `Param in ${in_} must have { "type": "object", ... }, but got ${JSON.stringify(openApiSchema, null, 2)}`, |
| 157 | + ); |
| 158 | + |
| 159 | + return Object.entries(openApiSchema.properties).map( |
| 160 | + ([name, def]: [string, any]) => ({ |
156 | 161 | name, |
157 | | - in: _in, |
158 | | - description, |
159 | | - schema: adapter.toJsonSchema(schema), |
160 | | - required: !optional, |
161 | | - })); |
| 162 | + in: in_, |
| 163 | + description: def.description, |
| 164 | + schema: def, |
| 165 | + required: !!openApiSchema.required?.includes(name), |
| 166 | + }), |
| 167 | + ); |
162 | 168 | } |
163 | 169 |
|
164 | 170 | function buildResponse( |
|
0 commit comments