import { u as FieldOverride, w as SchemaMeta } from "../types-BBQaEPfE.mjs"; import { r as DiagnosticSink } from "../diagnostics-mftUZI7c.mjs"; import { d as WidgetMap } from "../renderer-ab9E52Bp.mjs"; import { a as InferParameterOverrides, l as OpenAPIRequestBodyType, o as InferRequestBodyFields, s as InferResponseFields, u as OpenAPIResponseType } from "../typeInference-Y8tNEQJk.mjs"; import { ReactNode } from "react"; //#region src/openapi/components.d.ts /** * The canonical set of HTTP method strings recognised by OpenAPI 3.x. * Used to constrain `Method` generics so autocomplete on typed * documents only suggests methods the path item actually declares, * not arbitrary string keys. */ type HttpMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace"; /** * Extract the literal path keys from a document type, or the broad * `string` fallback when the document is untyped at compile time. * * For OpenAPI 3.1 documents the union includes keys from `webhooks` * alongside `paths`, because `` / `` / * `` resolve webhook names through the same code path as * paths (see `lookupPathItem` in `openapi/resolve.ts`). Without the * webhook keys, a typed `as const` 3.1 document that declares only * webhooks would reject every `path` prop value at compile time * ("Type 'string' is not assignable to type 'never'") despite working * at runtime. * * When the document declares neither a `paths` nor a `webhooks` map * the union falls back to `string` so untyped/foreign inputs keep * working — the constraint is informational, not gating. * * The `string extends keyof P` guard distinguishes a typed `as const` * document (whose `paths` map has literal keys) from a runtime * `Record` document (whose `keyof` collapses to * `string`). For the runtime case we surface `string` so callers pass * arbitrary path values without losing the existing freedom. */ type PathKeysOf = HasPathsOrWebhooks extends true ? PathsKey | WebhooksKey : string; /** * `true` when `D` declares either a `paths` or a `webhooks` object, * so the `PathKeysOf` union can be derived from real document keys * instead of falling back to `string`. */ type HasPathsOrWebhooks = D extends { paths: Record; } ? true : D extends { webhooks: Record; } ? true : false; /** * Literal `paths` keys, or `never` when the document does not declare * a `paths` object. Runtime documents (whose `keyof` collapses to * `string`) widen to `string` so callers retain prior freedom. */ type PathsKey = D extends { paths: infer P; } ? P extends Record ? string extends keyof P ? string : Extract : never : never; /** * Literal `webhooks` keys, or `never` when the document does not * declare a `webhooks` object (OpenAPI 3.1 only). Runtime documents * widen to `string`. */ type WebhooksKey = D extends { webhooks: infer W; } ? W extends Record ? string extends keyof W ? string : Extract : never : never; /** * Extract the methods declared on a specific path or webhook item, * restricted to the OpenAPI-recognised method set so non-method * extension keys (e.g. `summary`, `description`, `parameters`) do not * pollute the autocomplete. * * Runtime documents (typed `Record`) widen back to * `string` so callers retain the freedom to pass arbitrary method * strings without surfacing an `HttpMethod` constraint at runtime * call sites. Untyped documents (`unknown`) also widen to `string` so * consumers with no static doc info can supply extension methods — * the canonical `HttpMethod` set is informational, not gating, when * the document carries no structural information at all. * * When the document declares `paths` or `webhooks` but not the * specific entry `P`, the union falls back to `HttpMethod` so callers * can still target an authored operation that compile-time inference * happens to miss (e.g. behind a deferred conditional type). */ type MethodKeysOf = IsRuntimeDoc extends true ? string : unknown extends D ? string : HasPathsOrWebhooks extends true ? MethodKeysWithFallback : HttpMethod; /** * Union of literal methods extracted from `paths[P]` and `webhooks[P]`, * falling back to the canonical `HttpMethod` set when neither map * declares the requested entry. */ type MethodKeysWithFallback = [MethodKeysFromPaths | MethodKeysFromWebhooks] extends [never] ? HttpMethod : MethodKeysFromPaths | MethodKeysFromWebhooks; /** * Methods declared on `paths[P]`, restricted to `HttpMethod`. * Returns `never` when the document has no matching path entry. */ type MethodKeysFromPaths = D extends { paths: infer Paths; } ? Paths extends Record ? P extends keyof Paths ? Extract : never : never : never; /** * Methods declared on `webhooks[P]`, restricted to `HttpMethod`. * Returns `never` when the document has no matching webhook entry. */ type MethodKeysFromWebhooks = D extends { webhooks: infer Webhooks; } ? Webhooks extends Record ? P extends keyof Webhooks ? Extract : never : never : never; /** * True for the runtime-document sentinel — a `Record` * (or wider) where `keyof` collapses to `string`. Used to drop * narrow-constraint defaults so runtime callers retain the prior * freedom to pass arbitrary path/method/status values. */ type IsRuntimeDoc = D extends Record ? string extends keyof D ? true : false : false; /** * Generic "operation under a given map" extractor used by every * downstream `xxKeysOf` helper. Returns the Operation Object for the * given path-or-webhook name and method, or `never` when no such * entry exists. */ type OperationAt = Map_ extends Record ? P extends keyof Map_ ? Map_[P] extends Record ? M extends keyof Map_[P] ? Map_[P][M] : never : never : never : never; /** * Locate the Operation Object for `path`/`method` across both `paths` * and `webhooks`. The OpenAPI 3.1 spec assigns webhooks the same * Path Item shape as `paths` entries, so structural inference is * identical once the operation is resolved. */ type ResolveOperation = (D extends { paths: infer Paths; } ? OperationAt : never) | (D extends { webhooks: infer Webhooks; } ? OperationAt : never); /** * Extract the status-code keys declared by an operation's `responses` * map. Includes class wildcards (`2XX`, etc.) and the `default` * sentinel; runtime documents widen to `string`. */ type StatusKeysOf = ResolveOperation extends { responses: infer R; } ? R extends Record ? string extends keyof R ? string : Extract : string : string; /** * Extract the content-type keys declared on a request body's * `content` map for the given path and method. Runtime documents * widen to `string`. */ type RequestContentTypesOf = ResolveOperation extends { requestBody: { content: infer C; }; } ? C extends Record ? string extends keyof C ? string : Extract : string : string; /** * Extract the content-type keys declared on a response entry's * `content` map for the given path, method, and status. Runtime * documents widen to `string`. */ type ResponseContentTypesOf = ResolveOperation extends { responses: infer R; } ? R extends Record ? S extends keyof R ? R[S] extends { content: infer C; } ? C extends Record ? string extends keyof C ? string : Extract : string : string : string : string : string; /** * Diagnostics props accepted by every top-level OpenAPI component. * * `onDiagnostic` is the sink invoked for each event surfaced by the * normalisation pipeline (duplicate body parameter, dropped Swagger * feature, divisible-by conflict, unknown JSON Schema dialect, * relative-ref resolved, etc.). `strict` converts every emitted * diagnostic into a thrown `SchemaNormalisationError`. */ interface ApiDiagnosticsProps { onDiagnostic?: DiagnosticSink; strict?: boolean; } /** * Props accepted by {@link ApiOperation}. * * @group OpenAPI */ interface ApiOperationProps = PathKeysOf, Method extends MethodKeysOf = MethodKeysOf, ContentType extends RequestContentTypesOf = RequestContentTypesOf, ResponseStatus extends StatusKeysOf = StatusKeysOf, ResponseContentType extends ResponseContentTypesOf = ResponseContentTypesOf> extends ApiDiagnosticsProps { schema: Doc; path: Path; method: Method; /** * Current request body value. Inferred from the operation's * request body schema via {@link OpenAPIRequestBodyType} so a * typed `schema` argument drives the rendered value's shape. */ requestBodyValue?: OpenAPIRequestBodyType; /** * Called when the request body value changes. Parameter type * mirrors {@link ApiOperationProps.requestBodyValue}. */ onRequestBodyChange?: (value: OpenAPIRequestBodyType) => void; /** * Current response value. Inferred via {@link OpenAPIResponseType} * from the operation's response schema for the supplied * `responseStatus` (defaulting to the union of declared statuses) * and `responseContentType` (defaulting to the union of declared * media types). The same value is rendered against every response * card the component emits. */ responseValue?: OpenAPIResponseType; meta?: SchemaMeta; /** * Media type whose request body schema drives `requestBodyFields` * inference. Defaults to the union of declared content types so * callers can omit it; supply explicitly to narrow inference to a * specific media type. Mirrors {@link ApiRequestBodyProps.contentType} * so `` can target non-JSON request bodies with the * same precision as ``. */ requestBodyContentType?: ContentType; /** * Status code whose response schema drives `responseValue` * inference. Defaults to the union of declared statuses so * callers can omit it; supply explicitly to narrow inference to * a specific response (e.g. `"200"`). */ responseStatus?: ResponseStatus; /** * Media type whose response schema drives `responseValue` * inference. Defaults to the union of declared content types so * callers can omit it; supply explicitly to narrow inference to * a specific media type. */ responseContentType?: ResponseContentType; requestBodyFields?: Doc extends Record ? InferRequestBodyFields : Record; /** Instance-scoped widgets. */ widgets?: WidgetMap; } /** * Render a single OpenAPI operation — header, parameters, request body, * responses, callbacks, security, and external docs — picked out of a * supplied document by `path` and `method`. * * When `schema` is typed `as const`, `requestBodyFields` autocomplete * resolves from the operation's request body schema. The component * works with OpenAPI 2.0, 3.0, and 3.1 inputs (Swagger 2.0 documents * are normalised to 3.1 internally) and also resolves OpenAPI 3.1 * webhooks under the same code path. * * @group OpenAPI * @example * ```tsx * import { ApiOperation } from "schema-components/openapi/components"; * * * ``` */ declare function ApiOperation = PathKeysOf, Method extends MethodKeysOf = MethodKeysOf, ContentType extends RequestContentTypesOf = RequestContentTypesOf, ResponseStatus extends StatusKeysOf = StatusKeysOf, ResponseContentType extends ResponseContentTypesOf = ResponseContentTypesOf>({ schema: doc, path, method, requestBodyValue, onRequestBodyChange, responseValue, meta, requestBodyFields, widgets, onDiagnostic, strict }: ApiOperationProps): ReactNode; /** * Props accepted by {@link ApiParameters}. * * @group OpenAPI */ interface ApiParametersProps = PathKeysOf, Method extends MethodKeysOf = MethodKeysOf> extends ApiDiagnosticsProps { schema: Doc; path: Path; method: Method; meta?: SchemaMeta; overrides?: Doc extends Record ? InferParameterOverrides : Record; /** Instance-scoped widgets. */ widgets?: WidgetMap; } /** * Render the `parameters` of a single OpenAPI operation — path, query, * header, and cookie parameters — picked out of `schema` by `path` and * `method`. When the document is typed `as const`, the `overrides` prop * autocompletes on each parameter name. * * @group OpenAPI */ declare function ApiParameters = PathKeysOf, Method extends MethodKeysOf = MethodKeysOf>({ schema: doc, path, method, meta, overrides, widgets, onDiagnostic, strict }: ApiParametersProps): ReactNode; /** * Props accepted by {@link ApiRequestBody}. * * @group OpenAPI */ interface ApiRequestBodyProps = PathKeysOf, Method extends MethodKeysOf = MethodKeysOf, ContentType extends RequestContentTypesOf = RequestContentTypesOf> extends ApiDiagnosticsProps { schema: Doc; path: Path; method: Method; /** * Media type whose schema should be rendered for the request body. * Defaults to the union of declared content types so callers can * omit it; supply explicitly to narrow `fields` inference to a * specific media type via {@link InferRequestBodyFields}. */ contentType?: ContentType; value?: unknown; onChange?: (value: unknown) => void; meta?: SchemaMeta; fields?: Doc extends Record ? InferRequestBodyFields : Record; /** Instance-scoped widgets. */ widgets?: WidgetMap; } /** * Render the request body of a single OpenAPI operation, picked out of * `schema` by `path` and `method`. Returns `null` when the operation * declares no request body or no resolvable schema. * * When `schema` is typed `as const`, `fields` autocomplete resolves * from the request body schema; pass `contentType` to narrow inference * to a specific media type. * * @group OpenAPI */ declare function ApiRequestBody = PathKeysOf, Method extends MethodKeysOf = MethodKeysOf, ContentType extends RequestContentTypesOf = RequestContentTypesOf>({ schema: doc, path, method, value, onChange, meta, fields, widgets, onDiagnostic, strict }: ApiRequestBodyProps): ReactNode; /** * Props accepted by {@link ApiResponse}. * * @group OpenAPI */ interface ApiResponseProps = PathKeysOf, Method extends MethodKeysOf = MethodKeysOf, Status extends StatusKeysOf = StatusKeysOf, ContentType extends ResponseContentTypesOf = ResponseContentTypesOf> extends ApiDiagnosticsProps { schema: Doc; path: Path; method: Method; status: Status; /** * Media type whose schema should be rendered. Defaults to the * union of declared content types so callers can omit it; * supply explicitly to narrow `fields` inference via * {@link InferResponseFields}. */ contentType?: ContentType; value?: unknown; meta?: SchemaMeta; fields?: Doc extends Record ? InferResponseFields : Record; /** Instance-scoped widgets. */ widgets?: WidgetMap; } /** * Render the response schema for a single OpenAPI operation status — * picked out of `schema` by `path`, `method`, and `status`. * * Status resolution follows the OpenAPI priority order: concrete code * (e.g. `"200"`) \> class wildcard (e.g. `"2XX"`) \> `"default"`. When * `schema` is typed `as const`, `fields` autocomplete resolves from * the response schema; pass `contentType` to narrow inference to a * specific media type. * * @group OpenAPI */ declare function ApiResponse = PathKeysOf, Method extends MethodKeysOf = MethodKeysOf, Status extends StatusKeysOf = StatusKeysOf, ContentType extends ResponseContentTypesOf = ResponseContentTypesOf>({ schema: doc, path, method, status, value, meta, fields, widgets, onDiagnostic, strict }: ApiResponseProps): ReactNode; /** * Props accepted by {@link ApiWebhook}. * * @group OpenAPI */ interface ApiWebhookProps extends ApiDiagnosticsProps { schema: unknown; /** Webhook name (key under the document's `webhooks` map). */ name: string; /** Instance-scoped widgets, forwarded to each rendered operation. */ widgets?: WidgetMap; meta?: SchemaMeta; } /** * Render a single OpenAPI 3.1 webhook by name. A webhook is a Path Item * Object under the document's top-level `webhooks` map; once resolved, * its operations are structurally identical to operations under `paths`. * * Delegates to {@link ApiOperation} for each method present on the * webhook's Path Item Object — the parser's `lookupPathItem` resolves * webhook names through the same code path as paths, so `ApiOperation` * works for both with no special-casing in the renderer. * * @group OpenAPI */ declare function ApiWebhook({ schema: doc, name, widgets, meta, onDiagnostic, strict }: ApiWebhookProps): ReactNode; /** * Props accepted by {@link ApiWebhooks}. * * @group OpenAPI */ interface ApiWebhooksProps extends ApiDiagnosticsProps { schema: unknown; widgets?: WidgetMap; meta?: SchemaMeta; } /** * Render every OpenAPI 3.1 webhook declared on the document, one * `` per entry. Returns `null` when the document has no * `webhooks` map or the map is empty. * * @group OpenAPI */ declare function ApiWebhooks({ schema: doc, widgets, meta, onDiagnostic, strict }: ApiWebhooksProps): ReactNode; //#endregion export { ApiOperation, ApiOperationProps, ApiParameters, ApiParametersProps, ApiRequestBody, ApiRequestBodyProps, ApiResponse, ApiResponseProps, ApiWebhook, ApiWebhookProps, ApiWebhooks, ApiWebhooksProps };