diff --git a/.changeset/purple-glasses-admire.md b/.changeset/purple-glasses-admire.md new file mode 100644 index 0000000..7938f0d --- /dev/null +++ b/.changeset/purple-glasses-admire.md @@ -0,0 +1,5 @@ +--- +"typed-openapi": minor +--- + +Fixed parameter.body on post endpoints - #8. diff --git a/packages/typed-openapi/src/generator.ts b/packages/typed-openapi/src/generator.ts index 79ce224..e51b149 100644 --- a/packages/typed-openapi/src/generator.ts +++ b/packages/typed-openapi/src/generator.ts @@ -143,6 +143,7 @@ const generateEndpointSchemaList = (ctx: GeneratorContext) => { ${parameters.query ? `query: ${parameterObjectToString(parameters.query)},` : ""} ${parameters.path ? `path: ${parameterObjectToString(parameters.path)},` : ""} ${parameters.header ? `header: ${parameterObjectToString(parameters.header)},` : ""} + ${parameters.body ? `body: ${parameterObjectToString(parameters.body)},` : ""} }` : "parameters: never," } diff --git a/packages/typed-openapi/src/map-openapi-endpoints.ts b/packages/typed-openapi/src/map-openapi-endpoints.ts index dc852a5..a7107fb 100644 --- a/packages/typed-openapi/src/map-openapi-endpoints.ts +++ b/packages/typed-openapi/src/map-openapi-endpoints.ts @@ -72,6 +72,7 @@ export const mapOpenApiEndpoints = (doc: OpenAPIObject) => { // Body if (operation.requestBody) { + endpoint.meta.hasParameters = true; const requestBody = refs.unwrap(operation.requestBody ?? {}); const content = requestBody.content; const matchingMediaType = Object.keys(content).find(isAllowedParamMediaTypes); @@ -154,7 +155,7 @@ type MutationMethod = "post" | "put" | "patch" | "delete"; type Method = "get" | "head" | "options" | MutationMethod; export type EndpointParameters = { - body?: Box; + body?: Box; query?: Box | Record; header?: Box | Record; path?: Box | Record; diff --git a/packages/typed-openapi/tests/generator.test.ts b/packages/typed-openapi/tests/generator.test.ts index 94fefd6..0826840 100644 --- a/packages/typed-openapi/tests/generator.test.ts +++ b/packages/typed-openapi/tests/generator.test.ts @@ -51,13 +51,17 @@ describe("generator", () => { export type put_UpdatePet = { method: "PUT"; path: "/pet"; - parameters: never; + parameters: { + body: Pet; + }; response: Schemas.Pet; }; export type post_AddPet = { method: "POST"; path: "/pet"; - parameters: never; + parameters: { + body: Pet; + }; response: Schemas.Pet; }; export type get_FindPetsByStatus = { @@ -108,6 +112,8 @@ describe("generator", () => { parameters: { query: Partial<{ additionalMetadata: string }>; path: { petId: number }; + + body: string; }; response: Schemas.ApiResponse; }; @@ -120,7 +126,9 @@ describe("generator", () => { export type post_PlaceOrder = { method: "POST"; path: "/store/order"; - parameters: never; + parameters: { + body: Order; + }; response: Schemas.Order; }; export type get_GetOrderById = { @@ -142,13 +150,17 @@ describe("generator", () => { export type post_CreateUser = { method: "POST"; path: "/user"; - parameters: never; + parameters: { + body: User; + }; response: Schemas.User; }; export type post_CreateUsersWithListInput = { method: "POST"; path: "/user/createWithList"; - parameters: never; + parameters: { + body: Array; + }; response: unknown; }; export type get_LoginUser = { @@ -178,6 +190,8 @@ describe("generator", () => { path: "/user/{username}"; parameters: { path: { username: string }; + + body: User; }; response: unknown; }; diff --git a/packages/typed-openapi/tests/map-openapi-endpoints.test.ts b/packages/typed-openapi/tests/map-openapi-endpoints.test.ts index e5d91e6..3082a24 100644 --- a/packages/typed-openapi/tests/map-openapi-endpoints.test.ts +++ b/packages/typed-openapi/tests/map-openapi-endpoints.test.ts @@ -1247,7 +1247,7 @@ describe("map-openapi-endpoints", () => { "meta": { "alias": "put_UpdatePet", "areParametersRequired": false, - "hasParameters": false, + "hasParameters": true, }, "method": "put", "operation": { @@ -1329,7 +1329,7 @@ describe("map-openapi-endpoints", () => { "meta": { "alias": "post_AddPet", "areParametersRequired": false, - "hasParameters": false, + "hasParameters": true, }, "method": "post", "operation": { @@ -1907,7 +1907,7 @@ describe("map-openapi-endpoints", () => { "meta": { "alias": "post_PlaceOrder", "areParametersRequired": false, - "hasParameters": false, + "hasParameters": true, }, "method": "post", "operation": { @@ -2081,7 +2081,7 @@ describe("map-openapi-endpoints", () => { "meta": { "alias": "post_CreateUser", "areParametersRequired": false, - "hasParameters": false, + "hasParameters": true, }, "method": "post", "operation": { @@ -2145,7 +2145,7 @@ describe("map-openapi-endpoints", () => { "meta": { "alias": "post_CreateUsersWithListInput", "areParametersRequired": false, - "hasParameters": false, + "hasParameters": true, }, "method": "post", "operation": { diff --git a/packages/typed-openapi/tests/snapshots/docker.openapi.client.ts b/packages/typed-openapi/tests/snapshots/docker.openapi.client.ts index 61843d6..feacf3e 100644 --- a/packages/typed-openapi/tests/snapshots/docker.openapi.client.ts +++ b/packages/typed-openapi/tests/snapshots/docker.openapi.client.ts @@ -863,6 +863,8 @@ export namespace Endpoints { path: "/containers/create"; parameters: { query: Partial<{ name: string; platform: string }>; + + body: ContainerConfig & Partial<{ HostConfig: HostConfig; NetworkingConfig: NetworkingConfig }>; }; response: Schemas.ContainerCreateResponse; }; @@ -1002,6 +1004,8 @@ export namespace Endpoints { path: "/containers/{id}/update"; parameters: { path: { id: string }; + + body: Resources & Partial<{ RestartPolicy: RestartPolicy }>; }; response: Partial<{ Warnings: Array }>; }; @@ -1095,6 +1099,8 @@ export namespace Endpoints { parameters: { query: { path: string; noOverwriteDirNonDir: string; copyUIDGID: string }; path: { id: string }; + + body: string; }; response: unknown; }; @@ -1155,6 +1161,7 @@ export namespace Endpoints { }>; header: Partial<{ "Content-type": "application/x-tar"; "X-Registry-Config": string }>; + body: string; }; response: unknown; }; @@ -1181,6 +1188,7 @@ export namespace Endpoints { }>; header: Partial<{ "X-Registry-Auth": string }>; + body: string; }; response: unknown; }; @@ -1256,7 +1264,9 @@ export namespace Endpoints { export type post_SystemAuth = { method: "POST"; path: "/auth"; - parameters: never; + parameters: { + body: AuthConfig; + }; response: unknown; }; export type get_SystemInfo = { @@ -1296,6 +1306,8 @@ export namespace Endpoints { pause: boolean; changes: string; }>; + + body: ContainerConfig; }; response: Schemas.IdResponse; }; @@ -1350,6 +1362,20 @@ export namespace Endpoints { path: "/containers/{id}/exec"; parameters: { path: { id: string }; + + body: Partial<{ + AttachStdin: boolean; + AttachStdout: boolean; + AttachStderr: boolean; + ConsoleSize: Array | null; + DetachKeys: string; + Tty: boolean; + Env: Array; + Cmd: Array; + Privileged: boolean; + User: string; + WorkingDir: string; + }>; }; response: Schemas.IdResponse; }; @@ -1358,6 +1384,8 @@ export namespace Endpoints { path: "/exec/{id}/start"; parameters: { path: { id: string }; + + body: Partial<{ Detach: boolean; Tty: boolean; ConsoleSize: Array | null }>; }; response: unknown; }; @@ -1401,7 +1429,9 @@ export namespace Endpoints { export type post_VolumeCreate = { method: "POST"; path: "/volumes/create"; - parameters: never; + parameters: { + body: VolumeCreateOptions; + }; response: Schemas.Volume; }; export type get_VolumeInspect = { @@ -1418,6 +1448,8 @@ export namespace Endpoints { parameters: { query: { version: number }; path: { name: string }; + + body: Partial<{ Spec: ClusterVolumeSpec }>; }; response: unknown; }; @@ -1466,7 +1498,20 @@ export namespace Endpoints { export type post_NetworkCreate = { method: "POST"; path: "/networks/create"; - parameters: never; + parameters: { + body: { + Name: string; + CheckDuplicate?: boolean | undefined; + Driver?: string | undefined; + Internal?: boolean | undefined; + Attachable?: boolean | undefined; + Ingress?: boolean | undefined; + IPAM?: IPAM | undefined; + EnableIPv6?: boolean | undefined; + Options?: unknown | undefined; + Labels?: unknown | undefined; + }; + }; response: Partial<{ Id: string; Warning: string }>; }; export type post_NetworkConnect = { @@ -1474,6 +1519,8 @@ export namespace Endpoints { path: "/networks/{id}/connect"; parameters: { path: { id: string }; + + body: Partial<{ Container: string; EndpointConfig: EndpointSettings }>; }; response: unknown; }; @@ -1482,6 +1529,8 @@ export namespace Endpoints { path: "/networks/{id}/disconnect"; parameters: { path: { id: string }; + + body: Partial<{ Container: string; Force: boolean }>; }; response: unknown; }; @@ -1516,6 +1565,7 @@ export namespace Endpoints { query: { remote: string; name: string }; header: Partial<{ "X-Registry-Auth": string }>; + body: Array; }; response: unknown; }; @@ -1561,6 +1611,7 @@ export namespace Endpoints { query: { remote: string }; path: { name: string }; header: Partial<{ "X-Registry-Auth": string }>; + body: Array; }; response: unknown; }; @@ -1585,6 +1636,8 @@ export namespace Endpoints { path: "/plugins/{name}/set"; parameters: { path: { name: string }; + + body: Array; }; response: unknown; }; @@ -1619,6 +1672,8 @@ export namespace Endpoints { parameters: { query: { version: number }; path: { id: string }; + + body: NodeSpec; }; response: unknown; }; @@ -1631,13 +1686,32 @@ export namespace Endpoints { export type post_SwarmInit = { method: "POST"; path: "/swarm/init"; - parameters: never; + parameters: { + body: Partial<{ + ListenAddr: string; + AdvertiseAddr: string; + DataPathAddr: string; + DataPathPort: number; + DefaultAddrPool: Array; + ForceNewCluster: boolean; + SubnetSize: number; + Spec: SwarmSpec; + }>; + }; response: string; }; export type post_SwarmJoin = { method: "POST"; path: "/swarm/join"; - parameters: never; + parameters: { + body: Partial<{ + ListenAddr: string; + AdvertiseAddr: string; + DataPathAddr: string; + RemoteAddrs: Array; + JoinToken: string; + }>; + }; response: unknown; }; export type post_SwarmLeave = { @@ -1658,6 +1732,8 @@ export namespace Endpoints { rotateManagerToken: boolean; rotateManagerUnlockKey: boolean; }; + + body: SwarmSpec; }; response: unknown; }; @@ -1670,7 +1746,9 @@ export namespace Endpoints { export type post_SwarmUnlock = { method: "POST"; path: "/swarm/unlock"; - parameters: never; + parameters: { + body: Partial<{ UnlockKey: string }>; + }; response: unknown; }; export type get_ServiceList = { @@ -1686,6 +1764,7 @@ export namespace Endpoints { path: "/services/create"; parameters: { header: Partial<{ "X-Registry-Auth": string }>; + body: ServiceSpec & unknown; }; response: Partial<{ ID: string; Warning: string }>; }; @@ -1713,6 +1792,7 @@ export namespace Endpoints { query: { version: number; registryAuthFrom: "spec" | "previous-spec"; rollback: string }; path: { id: string }; header: Partial<{ "X-Registry-Auth": string }>; + body: ServiceSpec & unknown; }; response: Schemas.ServiceUpdateResponse; }; @@ -1777,7 +1857,9 @@ export namespace Endpoints { export type post_SecretCreate = { method: "POST"; path: "/secrets/create"; - parameters: never; + parameters: { + body: SecretSpec & unknown; + }; response: Schemas.IdResponse; }; export type get_SecretInspect = { @@ -1802,6 +1884,8 @@ export namespace Endpoints { parameters: { query: { version: number }; path: { id: string }; + + body: SecretSpec; }; response: unknown; }; @@ -1816,7 +1900,9 @@ export namespace Endpoints { export type post_ConfigCreate = { method: "POST"; path: "/configs/create"; - parameters: never; + parameters: { + body: ConfigSpec & unknown; + }; response: Schemas.IdResponse; }; export type get_ConfigInspect = { @@ -1841,6 +1927,8 @@ export namespace Endpoints { parameters: { query: { version: number }; path: { id: string }; + + body: ConfigSpec; }; response: unknown; }; diff --git a/packages/typed-openapi/tests/snapshots/docker.openapi.io-ts.ts b/packages/typed-openapi/tests/snapshots/docker.openapi.io-ts.ts index b738145..4e8f922 100644 --- a/packages/typed-openapi/tests/snapshots/docker.openapi.io-ts.ts +++ b/packages/typed-openapi/tests/snapshots/docker.openapi.io-ts.ts @@ -1748,6 +1748,13 @@ export const post_ContainerCreate = t.type({ name: t.union([t.undefined, t.string]), platform: t.union([t.undefined, t.string]), }), + body: t.intersection([ + ContainerConfig, + t.type({ + HostConfig: t.union([t.undefined, HostConfig]), + NetworkingConfig: t.union([t.undefined, NetworkingConfig]), + }), + ]), }), response: ContainerCreateResponse, }); @@ -1958,6 +1965,12 @@ export const post_ContainerUpdate = t.type({ path: t.type({ id: t.string, }), + body: t.intersection([ + Resources, + t.type({ + RestartPolicy: t.union([t.undefined, RestartPolicy]), + }), + ]), }), response: t.type({ Warnings: t.union([t.undefined, t.array(t.string)]), @@ -2106,6 +2119,7 @@ export const put_PutContainerArchive = t.type({ path: t.type({ id: t.string, }), + body: t.string, }), response: t.unknown, }); @@ -2190,6 +2204,7 @@ export const post_ImageBuild = t.type({ "Content-type": t.union([t.undefined, t.literal("application/x-tar")]), "X-Registry-Config": t.union([t.undefined, t.string]), }), + body: t.string, }), response: t.unknown, }); @@ -2228,6 +2243,7 @@ export const post_ImageCreate = t.type({ header: t.type({ "X-Registry-Auth": t.union([t.undefined, t.string]), }), + body: t.string, }), response: t.unknown, }); @@ -2356,7 +2372,9 @@ export type post_SystemAuth = t.TypeOf; export const post_SystemAuth = t.type({ method: t.literal("POST"), path: t.literal("/auth"), - parameters: t.never, + parameters: t.type({ + body: AuthConfig, + }), response: t.unknown, }); @@ -2406,6 +2424,7 @@ export const post_ImageCommit = t.type({ pause: t.union([t.undefined, t.boolean]), changes: t.union([t.undefined, t.string]), }), + body: ContainerConfig, }), response: IdResponse, }); @@ -2489,6 +2508,19 @@ export const post_ContainerExec = t.type({ path: t.type({ id: t.string, }), + body: t.type({ + AttachStdin: t.union([t.undefined, t.boolean]), + AttachStdout: t.union([t.undefined, t.boolean]), + AttachStderr: t.union([t.undefined, t.boolean]), + ConsoleSize: t.union([t.undefined, t.union([t.array(t.number), t.null])]), + DetachKeys: t.union([t.undefined, t.string]), + Tty: t.union([t.undefined, t.boolean]), + Env: t.union([t.undefined, t.array(t.string)]), + Cmd: t.union([t.undefined, t.array(t.string)]), + Privileged: t.union([t.undefined, t.boolean]), + User: t.union([t.undefined, t.string]), + WorkingDir: t.union([t.undefined, t.string]), + }), }), response: IdResponse, }); @@ -2501,6 +2533,11 @@ export const post_ExecStart = t.type({ path: t.type({ id: t.string, }), + body: t.type({ + Detach: t.union([t.undefined, t.boolean]), + Tty: t.union([t.undefined, t.boolean]), + ConsoleSize: t.union([t.undefined, t.union([t.array(t.number), t.null])]), + }), }), response: t.unknown, }); @@ -2561,7 +2598,9 @@ export type post_VolumeCreate = t.TypeOf; export const post_VolumeCreate = t.type({ method: t.literal("POST"), path: t.literal("/volumes/create"), - parameters: t.never, + parameters: t.type({ + body: VolumeCreateOptions, + }), response: Volume, }); @@ -2588,6 +2627,9 @@ export const put_VolumeUpdate = t.type({ path: t.type({ name: t.string, }), + body: t.type({ + Spec: t.union([t.undefined, ClusterVolumeSpec]), + }), }), response: t.unknown, }); @@ -2666,7 +2708,20 @@ export type post_NetworkCreate = t.TypeOf; export const post_NetworkCreate = t.type({ method: t.literal("POST"), path: t.literal("/networks/create"), - parameters: t.never, + parameters: t.type({ + body: t.type({ + Name: t.string, + CheckDuplicate: t.union([t.undefined, t.union([t.boolean, t.undefined])]), + Driver: t.union([t.undefined, t.union([t.string, t.undefined])]), + Internal: t.union([t.undefined, t.union([t.boolean, t.undefined])]), + Attachable: t.union([t.undefined, t.union([t.boolean, t.undefined])]), + Ingress: t.union([t.undefined, t.union([t.boolean, t.undefined])]), + IPAM: t.union([t.undefined, t.union([IPAM, t.undefined])]), + EnableIPv6: t.union([t.undefined, t.union([t.boolean, t.undefined])]), + Options: t.union([t.undefined, t.union([t.unknown, t.undefined])]), + Labels: t.union([t.undefined, t.union([t.unknown, t.undefined])]), + }), + }), response: t.type({ Id: t.union([t.undefined, t.string]), Warning: t.union([t.undefined, t.string]), @@ -2681,6 +2736,10 @@ export const post_NetworkConnect = t.type({ path: t.type({ id: t.string, }), + body: t.type({ + Container: t.union([t.undefined, t.string]), + EndpointConfig: t.union([t.undefined, EndpointSettings]), + }), }), response: t.unknown, }); @@ -2693,6 +2752,10 @@ export const post_NetworkDisconnect = t.type({ path: t.type({ id: t.string, }), + body: t.type({ + Container: t.union([t.undefined, t.string]), + Force: t.union([t.undefined, t.boolean]), + }), }), response: t.unknown, }); @@ -2747,6 +2810,7 @@ export const post_PluginPull = t.type({ header: t.type({ "X-Registry-Auth": t.union([t.undefined, t.string]), }), + body: t.array(PluginPrivilege), }), response: t.unknown, }); @@ -2822,6 +2886,7 @@ export const post_PluginUpgrade = t.type({ header: t.type({ "X-Registry-Auth": t.union([t.undefined, t.string]), }), + body: t.array(PluginPrivilege), }), response: t.unknown, }); @@ -2858,6 +2923,7 @@ export const post_PluginSet = t.type({ path: t.type({ name: t.string, }), + body: t.array(t.string), }), response: t.unknown, }); @@ -2912,6 +2978,7 @@ export const post_NodeUpdate = t.type({ path: t.type({ id: t.string, }), + body: NodeSpec, }), response: t.unknown, }); @@ -2928,7 +2995,18 @@ export type post_SwarmInit = t.TypeOf; export const post_SwarmInit = t.type({ method: t.literal("POST"), path: t.literal("/swarm/init"), - parameters: t.never, + parameters: t.type({ + body: t.type({ + ListenAddr: t.union([t.undefined, t.string]), + AdvertiseAddr: t.union([t.undefined, t.string]), + DataPathAddr: t.union([t.undefined, t.string]), + DataPathPort: t.union([t.undefined, t.number]), + DefaultAddrPool: t.union([t.undefined, t.array(t.string)]), + ForceNewCluster: t.union([t.undefined, t.boolean]), + SubnetSize: t.union([t.undefined, t.number]), + Spec: t.union([t.undefined, SwarmSpec]), + }), + }), response: t.string, }); @@ -2936,7 +3014,15 @@ export type post_SwarmJoin = t.TypeOf; export const post_SwarmJoin = t.type({ method: t.literal("POST"), path: t.literal("/swarm/join"), - parameters: t.never, + parameters: t.type({ + body: t.type({ + ListenAddr: t.union([t.undefined, t.string]), + AdvertiseAddr: t.union([t.undefined, t.string]), + DataPathAddr: t.union([t.undefined, t.string]), + RemoteAddrs: t.union([t.undefined, t.array(t.string)]), + JoinToken: t.union([t.undefined, t.string]), + }), + }), response: t.unknown, }); @@ -2963,6 +3049,7 @@ export const post_SwarmUpdate = t.type({ rotateManagerToken: t.boolean, rotateManagerUnlockKey: t.boolean, }), + body: SwarmSpec, }), response: t.unknown, }); @@ -2981,7 +3068,11 @@ export type post_SwarmUnlock = t.TypeOf; export const post_SwarmUnlock = t.type({ method: t.literal("POST"), path: t.literal("/swarm/unlock"), - parameters: t.never, + parameters: t.type({ + body: t.type({ + UnlockKey: t.union([t.undefined, t.string]), + }), + }), response: t.unknown, }); @@ -3006,6 +3097,7 @@ export const post_ServiceCreate = t.type({ header: t.type({ "X-Registry-Auth": t.union([t.undefined, t.string]), }), + body: t.intersection([ServiceSpec, t.unknown]), }), response: t.type({ ID: t.union([t.undefined, t.string]), @@ -3056,6 +3148,7 @@ export const post_ServiceUpdate = t.type({ header: t.type({ "X-Registry-Auth": t.union([t.undefined, t.string]), }), + body: t.intersection([ServiceSpec, t.unknown]), }), response: ServiceUpdateResponse, }); @@ -3142,7 +3235,9 @@ export type post_SecretCreate = t.TypeOf; export const post_SecretCreate = t.type({ method: t.literal("POST"), path: t.literal("/secrets/create"), - parameters: t.never, + parameters: t.type({ + body: t.intersection([SecretSpec, t.unknown]), + }), response: IdResponse, }); @@ -3181,6 +3276,7 @@ export const post_SecretUpdate = t.type({ path: t.type({ id: t.string, }), + body: SecretSpec, }), response: t.unknown, }); @@ -3201,7 +3297,9 @@ export type post_ConfigCreate = t.TypeOf; export const post_ConfigCreate = t.type({ method: t.literal("POST"), path: t.literal("/configs/create"), - parameters: t.never, + parameters: t.type({ + body: t.intersection([ConfigSpec, t.unknown]), + }), response: IdResponse, }); @@ -3240,6 +3338,7 @@ export const post_ConfigUpdate = t.type({ path: t.type({ id: t.string, }), + body: ConfigSpec, }), response: t.unknown, }); diff --git a/packages/typed-openapi/tests/snapshots/docker.openapi.typebox.ts b/packages/typed-openapi/tests/snapshots/docker.openapi.typebox.ts index c2ce47e..ea57804 100644 --- a/packages/typed-openapi/tests/snapshots/docker.openapi.typebox.ts +++ b/packages/typed-openapi/tests/snapshots/docker.openapi.typebox.ts @@ -1842,6 +1842,15 @@ export const post_ContainerCreate = Type.Object({ platform: Type.String(), }), ), + body: Type.Intersect([ + ContainerConfig, + Type.Partial( + Type.Object({ + HostConfig: HostConfig, + NetworkingConfig: NetworkingConfig, + }), + ), + ]), }), response: ContainerCreateResponse, }); @@ -2074,6 +2083,14 @@ export const post_ContainerUpdate = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: Type.Intersect([ + Resources, + Type.Partial( + Type.Object({ + RestartPolicy: RestartPolicy, + }), + ), + ]), }), response: Type.Partial( Type.Object({ @@ -2229,6 +2246,7 @@ export const put_PutContainerArchive = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: Type.String(), }), response: Type.Unknown(), }); @@ -2323,6 +2341,7 @@ export const post_ImageBuild = Type.Object({ "X-Registry-Config": Type.String(), }), ), + body: Type.String(), }), response: Type.Unknown(), }); @@ -2369,6 +2388,7 @@ export const post_ImageCreate = Type.Object({ "X-Registry-Auth": Type.String(), }), ), + body: Type.String(), }), response: Type.Unknown(), }); @@ -2509,7 +2529,9 @@ export type post_SystemAuth = Static; export const post_SystemAuth = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/auth"), - parameters: Type.Never(), + parameters: Type.Object({ + body: AuthConfig, + }), response: Type.Unknown(), }); @@ -2561,6 +2583,7 @@ export const post_ImageCommit = Type.Object({ changes: Type.String(), }), ), + body: ContainerConfig, }), response: IdResponse, }); @@ -2658,6 +2681,21 @@ export const post_ContainerExec = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: Type.Partial( + Type.Object({ + AttachStdin: Type.Boolean(), + AttachStdout: Type.Boolean(), + AttachStderr: Type.Boolean(), + ConsoleSize: Type.Union([Type.Array(Type.Number()), Type.Null()]), + DetachKeys: Type.String(), + Tty: Type.Boolean(), + Env: Type.Array(Type.String()), + Cmd: Type.Array(Type.String()), + Privileged: Type.Boolean(), + User: Type.String(), + WorkingDir: Type.String(), + }), + ), }), response: IdResponse, }); @@ -2670,6 +2708,13 @@ export const post_ExecStart = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: Type.Partial( + Type.Object({ + Detach: Type.Boolean(), + Tty: Type.Boolean(), + ConsoleSize: Type.Union([Type.Array(Type.Number()), Type.Null()]), + }), + ), }), response: Type.Unknown(), }); @@ -2736,7 +2781,9 @@ export type post_VolumeCreate = Static; export const post_VolumeCreate = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/volumes/create"), - parameters: Type.Never(), + parameters: Type.Object({ + body: VolumeCreateOptions, + }), response: Volume, }); @@ -2763,6 +2810,11 @@ export const put_VolumeUpdate = Type.Object({ path: Type.Object({ name: Type.String(), }), + body: Type.Partial( + Type.Object({ + Spec: ClusterVolumeSpec, + }), + ), }), response: Type.Unknown(), }); @@ -2851,7 +2903,20 @@ export type post_NetworkCreate = Static; export const post_NetworkCreate = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/networks/create"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Type.Object({ + Name: Type.String(), + CheckDuplicate: Type.Optional(Type.Union([Type.Boolean(), Type.Undefined()])), + Driver: Type.Optional(Type.Union([Type.String(), Type.Undefined()])), + Internal: Type.Optional(Type.Union([Type.Boolean(), Type.Undefined()])), + Attachable: Type.Optional(Type.Union([Type.Boolean(), Type.Undefined()])), + Ingress: Type.Optional(Type.Union([Type.Boolean(), Type.Undefined()])), + IPAM: Type.Optional(Type.Union([IPAM, Type.Undefined()])), + EnableIPv6: Type.Optional(Type.Union([Type.Boolean(), Type.Undefined()])), + Options: Type.Optional(Type.Union([Type.Unknown(), Type.Undefined()])), + Labels: Type.Optional(Type.Union([Type.Unknown(), Type.Undefined()])), + }), + }), response: Type.Partial( Type.Object({ Id: Type.String(), @@ -2868,6 +2933,12 @@ export const post_NetworkConnect = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: Type.Partial( + Type.Object({ + Container: Type.String(), + EndpointConfig: EndpointSettings, + }), + ), }), response: Type.Unknown(), }); @@ -2880,6 +2951,12 @@ export const post_NetworkDisconnect = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: Type.Partial( + Type.Object({ + Container: Type.String(), + Force: Type.Boolean(), + }), + ), }), response: Type.Unknown(), }); @@ -2942,6 +3019,7 @@ export const post_PluginPull = Type.Object({ "X-Registry-Auth": Type.String(), }), ), + body: Type.Array(PluginPrivilege), }), response: Type.Unknown(), }); @@ -3025,6 +3103,7 @@ export const post_PluginUpgrade = Type.Object({ "X-Registry-Auth": Type.String(), }), ), + body: Type.Array(PluginPrivilege), }), response: Type.Unknown(), }); @@ -3061,6 +3140,7 @@ export const post_PluginSet = Type.Object({ path: Type.Object({ name: Type.String(), }), + body: Type.Array(Type.String()), }), response: Type.Unknown(), }); @@ -3119,6 +3199,7 @@ export const post_NodeUpdate = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: NodeSpec, }), response: Type.Unknown(), }); @@ -3135,7 +3216,20 @@ export type post_SwarmInit = Static; export const post_SwarmInit = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/swarm/init"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Type.Partial( + Type.Object({ + ListenAddr: Type.String(), + AdvertiseAddr: Type.String(), + DataPathAddr: Type.String(), + DataPathPort: Type.Number(), + DefaultAddrPool: Type.Array(Type.String()), + ForceNewCluster: Type.Boolean(), + SubnetSize: Type.Number(), + Spec: SwarmSpec, + }), + ), + }), response: Type.String(), }); @@ -3143,7 +3237,17 @@ export type post_SwarmJoin = Static; export const post_SwarmJoin = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/swarm/join"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Type.Partial( + Type.Object({ + ListenAddr: Type.String(), + AdvertiseAddr: Type.String(), + DataPathAddr: Type.String(), + RemoteAddrs: Type.Array(Type.String()), + JoinToken: Type.String(), + }), + ), + }), response: Type.Unknown(), }); @@ -3172,6 +3276,7 @@ export const post_SwarmUpdate = Type.Object({ rotateManagerToken: Type.Boolean(), rotateManagerUnlockKey: Type.Boolean(), }), + body: SwarmSpec, }), response: Type.Unknown(), }); @@ -3192,7 +3297,13 @@ export type post_SwarmUnlock = Static; export const post_SwarmUnlock = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/swarm/unlock"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Type.Partial( + Type.Object({ + UnlockKey: Type.String(), + }), + ), + }), response: Type.Unknown(), }); @@ -3221,6 +3332,7 @@ export const post_ServiceCreate = Type.Object({ "X-Registry-Auth": Type.String(), }), ), + body: Type.Intersect([ServiceSpec, Type.Unknown()]), }), response: Type.Partial( Type.Object({ @@ -3277,6 +3389,7 @@ export const post_ServiceUpdate = Type.Object({ "X-Registry-Auth": Type.String(), }), ), + body: Type.Intersect([ServiceSpec, Type.Unknown()]), }), response: ServiceUpdateResponse, }); @@ -3371,7 +3484,9 @@ export type post_SecretCreate = Static; export const post_SecretCreate = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/secrets/create"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Type.Intersect([SecretSpec, Type.Unknown()]), + }), response: IdResponse, }); @@ -3410,6 +3525,7 @@ export const post_SecretUpdate = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: SecretSpec, }), response: Type.Unknown(), }); @@ -3432,7 +3548,9 @@ export type post_ConfigCreate = Static; export const post_ConfigCreate = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/configs/create"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Type.Intersect([ConfigSpec, Type.Unknown()]), + }), response: IdResponse, }); @@ -3471,6 +3589,7 @@ export const post_ConfigUpdate = Type.Object({ path: Type.Object({ id: Type.String(), }), + body: ConfigSpec, }), response: Type.Unknown(), }); diff --git a/packages/typed-openapi/tests/snapshots/docker.openapi.valibot.ts b/packages/typed-openapi/tests/snapshots/docker.openapi.valibot.ts index 21b5a71..27ac65c 100644 --- a/packages/typed-openapi/tests/snapshots/docker.openapi.valibot.ts +++ b/packages/typed-openapi/tests/snapshots/docker.openapi.valibot.ts @@ -1670,6 +1670,13 @@ export const post_ContainerCreate = v.object({ name: v.optional(v.string()), platform: v.optional(v.string()), }), + body: v.merge([ + ContainerConfig, + v.object({ + HostConfig: v.optional(HostConfig), + NetworkingConfig: v.optional(NetworkingConfig), + }), + ]), }), response: ContainerCreateResponse, }); @@ -1880,6 +1887,12 @@ export const post_ContainerUpdate = v.object({ path: v.object({ id: v.string(), }), + body: v.merge([ + Resources, + v.object({ + RestartPolicy: v.optional(RestartPolicy), + }), + ]), }), response: v.object({ Warnings: v.optional(v.array(v.string())), @@ -2025,6 +2038,7 @@ export const put_PutContainerArchive = v.object({ path: v.object({ id: v.string(), }), + body: v.string(), }), response: v.unknown(), }); @@ -2109,6 +2123,7 @@ export const post_ImageBuild = v.object({ "Content-type": v.optional(v.literal("application/x-tar")), "X-Registry-Config": v.optional(v.string()), }), + body: v.string(), }), response: v.unknown(), }); @@ -2147,6 +2162,7 @@ export const post_ImageCreate = v.object({ header: v.object({ "X-Registry-Auth": v.optional(v.string()), }), + body: v.string(), }), response: v.unknown(), }); @@ -2275,7 +2291,9 @@ export type post_SystemAuth = v.Output; export const post_SystemAuth = v.object({ method: v.literal("POST"), path: v.literal("/auth"), - parameters: v.never(), + parameters: v.object({ + body: AuthConfig, + }), response: v.unknown(), }); @@ -2325,6 +2343,7 @@ export const post_ImageCommit = v.object({ pause: v.optional(v.boolean()), changes: v.optional(v.string()), }), + body: ContainerConfig, }), response: IdResponse, }); @@ -2407,6 +2426,19 @@ export const post_ContainerExec = v.object({ path: v.object({ id: v.string(), }), + body: v.object({ + AttachStdin: v.optional(v.boolean()), + AttachStdout: v.optional(v.boolean()), + AttachStderr: v.optional(v.boolean()), + ConsoleSize: v.optional(v.union([v.array(v.number()), v.any(/* unsupported */)])), + DetachKeys: v.optional(v.string()), + Tty: v.optional(v.boolean()), + Env: v.optional(v.array(v.string())), + Cmd: v.optional(v.array(v.string())), + Privileged: v.optional(v.boolean()), + User: v.optional(v.string()), + WorkingDir: v.optional(v.string()), + }), }), response: IdResponse, }); @@ -2419,6 +2451,11 @@ export const post_ExecStart = v.object({ path: v.object({ id: v.string(), }), + body: v.object({ + Detach: v.optional(v.boolean()), + Tty: v.optional(v.boolean()), + ConsoleSize: v.optional(v.union([v.array(v.number()), v.any(/* unsupported */)])), + }), }), response: v.unknown(), }); @@ -2479,7 +2516,9 @@ export type post_VolumeCreate = v.Output; export const post_VolumeCreate = v.object({ method: v.literal("POST"), path: v.literal("/volumes/create"), - parameters: v.never(), + parameters: v.object({ + body: VolumeCreateOptions, + }), response: Volume, }); @@ -2506,6 +2545,9 @@ export const put_VolumeUpdate = v.object({ path: v.object({ name: v.string(), }), + body: v.object({ + Spec: v.optional(ClusterVolumeSpec), + }), }), response: v.unknown(), }); @@ -2584,7 +2626,20 @@ export type post_NetworkCreate = v.Output; export const post_NetworkCreate = v.object({ method: v.literal("POST"), path: v.literal("/networks/create"), - parameters: v.never(), + parameters: v.object({ + body: v.object({ + Name: v.string(), + CheckDuplicate: v.optional(v.union([v.boolean(), v.any(/* unsupported */)])), + Driver: v.optional(v.union([v.string(), v.any(/* unsupported */)])), + Internal: v.optional(v.union([v.boolean(), v.any(/* unsupported */)])), + Attachable: v.optional(v.union([v.boolean(), v.any(/* unsupported */)])), + Ingress: v.optional(v.union([v.boolean(), v.any(/* unsupported */)])), + IPAM: v.optional(v.union([IPAM, v.any(/* unsupported */)])), + EnableIPv6: v.optional(v.union([v.boolean(), v.any(/* unsupported */)])), + Options: v.optional(v.union([v.unknown(), v.any(/* unsupported */)])), + Labels: v.optional(v.union([v.unknown(), v.any(/* unsupported */)])), + }), + }), response: v.object({ Id: v.optional(v.string()), Warning: v.optional(v.string()), @@ -2599,6 +2654,10 @@ export const post_NetworkConnect = v.object({ path: v.object({ id: v.string(), }), + body: v.object({ + Container: v.optional(v.string()), + EndpointConfig: v.optional(EndpointSettings), + }), }), response: v.unknown(), }); @@ -2611,6 +2670,10 @@ export const post_NetworkDisconnect = v.object({ path: v.object({ id: v.string(), }), + body: v.object({ + Container: v.optional(v.string()), + Force: v.optional(v.boolean()), + }), }), response: v.unknown(), }); @@ -2665,6 +2728,7 @@ export const post_PluginPull = v.object({ header: v.object({ "X-Registry-Auth": v.optional(v.string()), }), + body: v.array(PluginPrivilege), }), response: v.unknown(), }); @@ -2740,6 +2804,7 @@ export const post_PluginUpgrade = v.object({ header: v.object({ "X-Registry-Auth": v.optional(v.string()), }), + body: v.array(PluginPrivilege), }), response: v.unknown(), }); @@ -2776,6 +2841,7 @@ export const post_PluginSet = v.object({ path: v.object({ name: v.string(), }), + body: v.array(v.string()), }), response: v.unknown(), }); @@ -2830,6 +2896,7 @@ export const post_NodeUpdate = v.object({ path: v.object({ id: v.string(), }), + body: NodeSpec, }), response: v.unknown(), }); @@ -2846,7 +2913,18 @@ export type post_SwarmInit = v.Output; export const post_SwarmInit = v.object({ method: v.literal("POST"), path: v.literal("/swarm/init"), - parameters: v.never(), + parameters: v.object({ + body: v.object({ + ListenAddr: v.optional(v.string()), + AdvertiseAddr: v.optional(v.string()), + DataPathAddr: v.optional(v.string()), + DataPathPort: v.optional(v.number()), + DefaultAddrPool: v.optional(v.array(v.string())), + ForceNewCluster: v.optional(v.boolean()), + SubnetSize: v.optional(v.number()), + Spec: v.optional(SwarmSpec), + }), + }), response: v.string(), }); @@ -2854,7 +2932,15 @@ export type post_SwarmJoin = v.Output; export const post_SwarmJoin = v.object({ method: v.literal("POST"), path: v.literal("/swarm/join"), - parameters: v.never(), + parameters: v.object({ + body: v.object({ + ListenAddr: v.optional(v.string()), + AdvertiseAddr: v.optional(v.string()), + DataPathAddr: v.optional(v.string()), + RemoteAddrs: v.optional(v.array(v.string())), + JoinToken: v.optional(v.string()), + }), + }), response: v.unknown(), }); @@ -2881,6 +2967,7 @@ export const post_SwarmUpdate = v.object({ rotateManagerToken: v.boolean(), rotateManagerUnlockKey: v.boolean(), }), + body: SwarmSpec, }), response: v.unknown(), }); @@ -2899,7 +2986,11 @@ export type post_SwarmUnlock = v.Output; export const post_SwarmUnlock = v.object({ method: v.literal("POST"), path: v.literal("/swarm/unlock"), - parameters: v.never(), + parameters: v.object({ + body: v.object({ + UnlockKey: v.optional(v.string()), + }), + }), response: v.unknown(), }); @@ -2924,6 +3015,7 @@ export const post_ServiceCreate = v.object({ header: v.object({ "X-Registry-Auth": v.optional(v.string()), }), + body: v.merge([ServiceSpec, v.unknown()]), }), response: v.object({ ID: v.optional(v.string()), @@ -2974,6 +3066,7 @@ export const post_ServiceUpdate = v.object({ header: v.object({ "X-Registry-Auth": v.optional(v.string()), }), + body: v.merge([ServiceSpec, v.unknown()]), }), response: ServiceUpdateResponse, }); @@ -3060,7 +3153,9 @@ export type post_SecretCreate = v.Output; export const post_SecretCreate = v.object({ method: v.literal("POST"), path: v.literal("/secrets/create"), - parameters: v.never(), + parameters: v.object({ + body: v.merge([SecretSpec, v.unknown()]), + }), response: IdResponse, }); @@ -3099,6 +3194,7 @@ export const post_SecretUpdate = v.object({ path: v.object({ id: v.string(), }), + body: SecretSpec, }), response: v.unknown(), }); @@ -3119,7 +3215,9 @@ export type post_ConfigCreate = v.Output; export const post_ConfigCreate = v.object({ method: v.literal("POST"), path: v.literal("/configs/create"), - parameters: v.never(), + parameters: v.object({ + body: v.merge([ConfigSpec, v.unknown()]), + }), response: IdResponse, }); @@ -3158,6 +3256,7 @@ export const post_ConfigUpdate = v.object({ path: v.object({ id: v.string(), }), + body: ConfigSpec, }), response: v.unknown(), }); diff --git a/packages/typed-openapi/tests/snapshots/docker.openapi.yup.ts b/packages/typed-openapi/tests/snapshots/docker.openapi.yup.ts index 4592101..514e489 100644 --- a/packages/typed-openapi/tests/snapshots/docker.openapi.yup.ts +++ b/packages/typed-openapi/tests/snapshots/docker.openapi.yup.ts @@ -2184,6 +2184,91 @@ export const post_ContainerCreate = { name: y.string().required().optional(), platform: y.string().required().optional(), }), + body: y.object({ + Hostname: y.string().required().optional(), + Domainname: y.string().required().optional(), + User: y.string().required().optional(), + AttachStdin: y.boolean().required().optional(), + AttachStdout: y.boolean().required().optional(), + AttachStderr: y.boolean().required().optional(), + ExposedPorts: y + .mixed() + .oneOf([ + y.mixed((value): value is any => true).required() as y.MixedSchema, + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + Tty: y.boolean().required().optional(), + OpenStdin: y.boolean().required().optional(), + StdinOnce: y.boolean().required().optional(), + Env: y.array(y.string().required()).optional(), + Cmd: y.array(y.string().required()).optional(), + Healthcheck: HealthConfig.optional(), + ArgsEscaped: y + .mixed() + .oneOf([ + y.boolean().required(), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + Image: y.string().required().optional(), + Volumes: (y.mixed((value): value is any => true).required() as y.MixedSchema).optional(), + WorkingDir: y.string().required().optional(), + Entrypoint: y.array(y.string().required()).optional(), + NetworkDisabled: y + .mixed() + .oneOf([ + y.boolean().required(), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + MacAddress: y + .mixed() + .oneOf([ + y.string().required(), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + OnBuild: y + .mixed() + .oneOf([ + y.array(y.string().required()), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + Labels: (y.mixed((value): value is any => true).required() as y.MixedSchema).optional(), + StopSignal: y + .mixed() + .oneOf([ + y.string().required(), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + StopTimeout: y + .mixed() + .oneOf([ + y.number().required(), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + Shell: y + .mixed() + .oneOf([ + y.array(y.string().required()), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + HostConfig: HostConfig.optional(), + NetworkingConfig: NetworkingConfig.optional(), + }), }), response: ContainerCreateResponse, }; @@ -2401,6 +2486,69 @@ export const post_ContainerUpdate = { path: y.object({ id: y.string().required(), }), + body: y.object({ + CpuShares: y.number().required().optional(), + Memory: y.number().required().optional(), + CgroupParent: y.string().required().optional(), + BlkioWeight: y.number().required().optional(), + BlkioWeightDevice: y + .array( + y.object({ + Path: y.string().required().optional(), + Weight: y.number().required().optional(), + }), + ) + .optional(), + BlkioDeviceReadBps: y.array(ThrottleDevice).optional(), + BlkioDeviceWriteBps: y.array(ThrottleDevice).optional(), + BlkioDeviceReadIOps: y.array(ThrottleDevice).optional(), + BlkioDeviceWriteIOps: y.array(ThrottleDevice).optional(), + CpuPeriod: y.number().required().optional(), + CpuQuota: y.number().required().optional(), + CpuRealtimePeriod: y.number().required().optional(), + CpuRealtimeRuntime: y.number().required().optional(), + CpusetCpus: y.string().required().optional(), + CpusetMems: y.string().required().optional(), + Devices: y.array(DeviceMapping).optional(), + DeviceCgroupRules: y.array(y.string().required()).optional(), + DeviceRequests: y.array(DeviceRequest).optional(), + KernelMemoryTCP: y.number().required().optional(), + MemoryReservation: y.number().required().optional(), + MemorySwap: y.number().required().optional(), + MemorySwappiness: y.number().required().optional(), + NanoCpus: y.number().required().optional(), + OomKillDisable: y.boolean().required().optional(), + Init: y + .mixed() + .oneOf([ + y.boolean().required(), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + PidsLimit: y + .mixed() + .oneOf([ + y.number().required(), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + Ulimits: y + .array( + y.object({ + Name: y.string().required().optional(), + Soft: y.number().required().optional(), + Hard: y.number().required().optional(), + }), + ) + .optional(), + CpuCount: y.number().required().optional(), + CpuPercent: y.number().required().optional(), + IOMaximumIOps: y.number().required().optional(), + IOMaximumBandwidth: y.number().required().optional(), + RestartPolicy: RestartPolicy.optional(), + }), }), response: y.object({ Warnings: y.array(y.string().required()).optional(), @@ -2554,6 +2702,7 @@ export const put_PutContainerArchive = { path: y.object({ id: y.string().required(), }), + body: y.string().required(), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -2641,6 +2790,7 @@ export const post_ImageBuild = { .optional(), "X-Registry-Config": y.string().required().optional(), }), + body: y.string().required(), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -2679,6 +2829,7 @@ export const post_ImageCreate = { header: y.object({ "X-Registry-Auth": y.string().required().optional(), }), + body: y.string().required(), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -2807,7 +2958,9 @@ export type post_SystemAuth = typeof post_SystemAuth; export const post_SystemAuth = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/auth" => value === "/auth").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: AuthConfig, + }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -2857,6 +3010,7 @@ export const post_ImageCommit = { pause: y.boolean().required().optional(), changes: y.string().required().optional(), }), + body: ContainerConfig, }), response: IdResponse, }; @@ -2949,6 +3103,26 @@ export const post_ContainerExec = { path: y.object({ id: y.string().required(), }), + body: y.object({ + AttachStdin: y.boolean().required().optional(), + AttachStdout: y.boolean().required().optional(), + AttachStderr: y.boolean().required().optional(), + ConsoleSize: y + .mixed() + .oneOf([ + y.array(y.number().required()), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + DetachKeys: y.string().required().optional(), + Tty: y.boolean().required().optional(), + Env: y.array(y.string().required()).optional(), + Cmd: y.array(y.string().required()).optional(), + Privileged: y.boolean().required().optional(), + User: y.string().required().optional(), + WorkingDir: y.string().required().optional(), + }), }), response: IdResponse, }; @@ -2961,6 +3135,18 @@ export const post_ExecStart = { path: y.object({ id: y.string().required(), }), + body: y.object({ + Detach: y.boolean().required().optional(), + Tty: y.boolean().required().optional(), + ConsoleSize: y + .mixed() + .oneOf([ + y.array(y.number().required()), + y.mixed((value): value is any => value === null).required() as y.MixedSchema, + ]) + .required() + .optional(), + }), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3021,7 +3207,9 @@ export type post_VolumeCreate = typeof post_VolumeCreate; export const post_VolumeCreate = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/volumes/create" => value === "/volumes/create").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: VolumeCreateOptions, + }), response: Volume, }; @@ -3048,6 +3236,9 @@ export const put_VolumeUpdate = { path: y.object({ name: y.string().required(), }), + body: y.object({ + Spec: ClusterVolumeSpec.optional(), + }), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3126,7 +3317,80 @@ export type post_NetworkCreate = typeof post_NetworkCreate; export const post_NetworkCreate = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/networks/create" => value === "/networks/create").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: y.object({ + Name: y.string().required(), + CheckDuplicate: y + .mixed() + .oneOf([ + y.boolean().required(), + y.mixed((value): value is any => value === undefined) as y.MixedSchema, + ]) + .required() + .optional(), + Driver: y + .mixed() + .oneOf([ + y.string().required(), + y.mixed((value): value is any => value === undefined) as y.MixedSchema, + ]) + .required() + .optional(), + Internal: y + .mixed() + .oneOf([ + y.boolean().required(), + y.mixed((value): value is any => value === undefined) as y.MixedSchema, + ]) + .required() + .optional(), + Attachable: y + .mixed() + .oneOf([ + y.boolean().required(), + y.mixed((value): value is any => value === undefined) as y.MixedSchema, + ]) + .required() + .optional(), + Ingress: y + .mixed() + .oneOf([ + y.boolean().required(), + y.mixed((value): value is any => value === undefined) as y.MixedSchema, + ]) + .required() + .optional(), + IPAM: y + .mixed() + .oneOf([IPAM, y.mixed((value): value is any => value === undefined) as y.MixedSchema]) + .required() + .optional(), + EnableIPv6: y + .mixed() + .oneOf([ + y.boolean().required(), + y.mixed((value): value is any => value === undefined) as y.MixedSchema, + ]) + .required() + .optional(), + Options: y + .mixed() + .oneOf([ + y.mixed((value): value is any => true).required() as y.MixedSchema, + y.mixed((value): value is any => value === undefined) as y.MixedSchema, + ]) + .required() + .optional(), + Labels: y + .mixed() + .oneOf([ + y.mixed((value): value is any => true).required() as y.MixedSchema, + y.mixed((value): value is any => value === undefined) as y.MixedSchema, + ]) + .required() + .optional(), + }), + }), response: y.object({ Id: y.string().required().optional(), Warning: y.string().required().optional(), @@ -3141,6 +3405,10 @@ export const post_NetworkConnect = { path: y.object({ id: y.string().required(), }), + body: y.object({ + Container: y.string().required().optional(), + EndpointConfig: EndpointSettings.optional(), + }), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3153,6 +3421,10 @@ export const post_NetworkDisconnect = { path: y.object({ id: y.string().required(), }), + body: y.object({ + Container: y.string().required().optional(), + Force: y.boolean().required().optional(), + }), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3207,6 +3479,7 @@ export const post_PluginPull = { header: y.object({ "X-Registry-Auth": y.string().required().optional(), }), + body: y.array(PluginPrivilege), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3282,6 +3555,7 @@ export const post_PluginUpgrade = { header: y.object({ "X-Registry-Auth": y.string().required().optional(), }), + body: y.array(PluginPrivilege), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3318,6 +3592,7 @@ export const post_PluginSet = { path: y.object({ name: y.string().required(), }), + body: y.array(y.string().required()), }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3372,6 +3647,7 @@ export const post_NodeUpdate = { path: y.object({ id: y.string().required(), }), + body: NodeSpec, }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3388,7 +3664,18 @@ export type post_SwarmInit = typeof post_SwarmInit; export const post_SwarmInit = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/swarm/init" => value === "/swarm/init").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: y.object({ + ListenAddr: y.string().required().optional(), + AdvertiseAddr: y.string().required().optional(), + DataPathAddr: y.string().required().optional(), + DataPathPort: y.number().required().optional(), + DefaultAddrPool: y.array(y.string().required()).optional(), + ForceNewCluster: y.boolean().required().optional(), + SubnetSize: y.number().required().optional(), + Spec: SwarmSpec.optional(), + }), + }), response: y.string().required(), }; @@ -3396,7 +3683,15 @@ export type post_SwarmJoin = typeof post_SwarmJoin; export const post_SwarmJoin = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/swarm/join" => value === "/swarm/join").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: y.object({ + ListenAddr: y.string().required().optional(), + AdvertiseAddr: y.string().required().optional(), + DataPathAddr: y.string().required().optional(), + RemoteAddrs: y.array(y.string().required()).optional(), + JoinToken: y.string().required().optional(), + }), + }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3423,6 +3718,7 @@ export const post_SwarmUpdate = { rotateManagerToken: y.boolean().required(), rotateManagerUnlockKey: y.boolean().required(), }), + body: SwarmSpec, }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3441,7 +3737,11 @@ export type post_SwarmUnlock = typeof post_SwarmUnlock; export const post_SwarmUnlock = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/swarm/unlock" => value === "/swarm/unlock").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: y.object({ + UnlockKey: y.string().required().optional(), + }), + }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3466,6 +3766,7 @@ export const post_ServiceCreate = { header: y.object({ "X-Registry-Auth": y.string().required().optional(), }), + body: y.mixed(/* unsupported */), }), response: y.object({ ID: y.string().required().optional(), @@ -3522,6 +3823,7 @@ export const post_ServiceUpdate = { header: y.object({ "X-Registry-Auth": y.string().required().optional(), }), + body: y.mixed(/* unsupported */), }), response: ServiceUpdateResponse, }; @@ -3608,7 +3910,9 @@ export type post_SecretCreate = typeof post_SecretCreate; export const post_SecretCreate = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/secrets/create" => value === "/secrets/create").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: y.mixed(/* unsupported */), + }), response: IdResponse, }; @@ -3647,6 +3951,7 @@ export const post_SecretUpdate = { path: y.object({ id: y.string().required(), }), + body: SecretSpec, }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -3667,7 +3972,9 @@ export type post_ConfigCreate = typeof post_ConfigCreate; export const post_ConfigCreate = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/configs/create" => value === "/configs/create").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: y.mixed(/* unsupported */), + }), response: IdResponse, }; @@ -3706,6 +4013,7 @@ export const post_ConfigUpdate = { path: y.object({ id: y.string().required(), }), + body: ConfigSpec, }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; diff --git a/packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts b/packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts index 7e3342e..a44ab20 100644 --- a/packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts +++ b/packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts @@ -1659,6 +1659,13 @@ export const post_ContainerCreate = { name: z.string().optional(), platform: z.string().optional(), }), + body: z.intersection( + ContainerConfig, + z.object({ + HostConfig: HostConfig.optional(), + NetworkingConfig: NetworkingConfig.optional(), + }), + ), }), response: ContainerCreateResponse, }; @@ -1869,6 +1876,12 @@ export const post_ContainerUpdate = { path: z.object({ id: z.string(), }), + body: z.intersection( + Resources, + z.object({ + RestartPolicy: RestartPolicy.optional(), + }), + ), }), response: z.object({ Warnings: z.array(z.string()).optional(), @@ -2014,6 +2027,7 @@ export const put_PutContainerArchive = { path: z.object({ id: z.string(), }), + body: z.string(), }), response: z.unknown(), }; @@ -2098,6 +2112,7 @@ export const post_ImageBuild = { "Content-type": z.literal("application/x-tar").optional(), "X-Registry-Config": z.string().optional(), }), + body: z.string(), }), response: z.unknown(), }; @@ -2136,6 +2151,7 @@ export const post_ImageCreate = { header: z.object({ "X-Registry-Auth": z.string().optional(), }), + body: z.string(), }), response: z.unknown(), }; @@ -2264,7 +2280,9 @@ export type post_SystemAuth = typeof post_SystemAuth; export const post_SystemAuth = { method: z.literal("POST"), path: z.literal("/auth"), - parameters: z.never(), + parameters: z.object({ + body: AuthConfig, + }), response: z.unknown(), }; @@ -2314,6 +2332,7 @@ export const post_ImageCommit = { pause: z.boolean().optional(), changes: z.string().optional(), }), + body: ContainerConfig, }), response: IdResponse, }; @@ -2396,6 +2415,19 @@ export const post_ContainerExec = { path: z.object({ id: z.string(), }), + body: z.object({ + AttachStdin: z.boolean().optional(), + AttachStdout: z.boolean().optional(), + AttachStderr: z.boolean().optional(), + ConsoleSize: z.union([z.array(z.number()), z.null()]).optional(), + DetachKeys: z.string().optional(), + Tty: z.boolean().optional(), + Env: z.array(z.string()).optional(), + Cmd: z.array(z.string()).optional(), + Privileged: z.boolean().optional(), + User: z.string().optional(), + WorkingDir: z.string().optional(), + }), }), response: IdResponse, }; @@ -2408,6 +2440,11 @@ export const post_ExecStart = { path: z.object({ id: z.string(), }), + body: z.object({ + Detach: z.boolean().optional(), + Tty: z.boolean().optional(), + ConsoleSize: z.union([z.array(z.number()), z.null()]).optional(), + }), }), response: z.unknown(), }; @@ -2468,7 +2505,9 @@ export type post_VolumeCreate = typeof post_VolumeCreate; export const post_VolumeCreate = { method: z.literal("POST"), path: z.literal("/volumes/create"), - parameters: z.never(), + parameters: z.object({ + body: VolumeCreateOptions, + }), response: Volume, }; @@ -2495,6 +2534,9 @@ export const put_VolumeUpdate = { path: z.object({ name: z.string(), }), + body: z.object({ + Spec: ClusterVolumeSpec.optional(), + }), }), response: z.unknown(), }; @@ -2573,7 +2615,20 @@ export type post_NetworkCreate = typeof post_NetworkCreate; export const post_NetworkCreate = { method: z.literal("POST"), path: z.literal("/networks/create"), - parameters: z.never(), + parameters: z.object({ + body: z.object({ + Name: z.string(), + CheckDuplicate: z.union([z.boolean(), z.undefined()]).optional(), + Driver: z.union([z.string(), z.undefined()]).optional(), + Internal: z.union([z.boolean(), z.undefined()]).optional(), + Attachable: z.union([z.boolean(), z.undefined()]).optional(), + Ingress: z.union([z.boolean(), z.undefined()]).optional(), + IPAM: z.union([IPAM, z.undefined()]).optional(), + EnableIPv6: z.union([z.boolean(), z.undefined()]).optional(), + Options: z.union([z.unknown(), z.undefined()]).optional(), + Labels: z.union([z.unknown(), z.undefined()]).optional(), + }), + }), response: z.object({ Id: z.string().optional(), Warning: z.string().optional(), @@ -2588,6 +2643,10 @@ export const post_NetworkConnect = { path: z.object({ id: z.string(), }), + body: z.object({ + Container: z.string().optional(), + EndpointConfig: EndpointSettings.optional(), + }), }), response: z.unknown(), }; @@ -2600,6 +2659,10 @@ export const post_NetworkDisconnect = { path: z.object({ id: z.string(), }), + body: z.object({ + Container: z.string().optional(), + Force: z.boolean().optional(), + }), }), response: z.unknown(), }; @@ -2654,6 +2717,7 @@ export const post_PluginPull = { header: z.object({ "X-Registry-Auth": z.string().optional(), }), + body: z.array(PluginPrivilege), }), response: z.unknown(), }; @@ -2729,6 +2793,7 @@ export const post_PluginUpgrade = { header: z.object({ "X-Registry-Auth": z.string().optional(), }), + body: z.array(PluginPrivilege), }), response: z.unknown(), }; @@ -2765,6 +2830,7 @@ export const post_PluginSet = { path: z.object({ name: z.string(), }), + body: z.array(z.string()), }), response: z.unknown(), }; @@ -2819,6 +2885,7 @@ export const post_NodeUpdate = { path: z.object({ id: z.string(), }), + body: NodeSpec, }), response: z.unknown(), }; @@ -2835,7 +2902,18 @@ export type post_SwarmInit = typeof post_SwarmInit; export const post_SwarmInit = { method: z.literal("POST"), path: z.literal("/swarm/init"), - parameters: z.never(), + parameters: z.object({ + body: z.object({ + ListenAddr: z.string().optional(), + AdvertiseAddr: z.string().optional(), + DataPathAddr: z.string().optional(), + DataPathPort: z.number().optional(), + DefaultAddrPool: z.array(z.string()).optional(), + ForceNewCluster: z.boolean().optional(), + SubnetSize: z.number().optional(), + Spec: SwarmSpec.optional(), + }), + }), response: z.string(), }; @@ -2843,7 +2921,15 @@ export type post_SwarmJoin = typeof post_SwarmJoin; export const post_SwarmJoin = { method: z.literal("POST"), path: z.literal("/swarm/join"), - parameters: z.never(), + parameters: z.object({ + body: z.object({ + ListenAddr: z.string().optional(), + AdvertiseAddr: z.string().optional(), + DataPathAddr: z.string().optional(), + RemoteAddrs: z.array(z.string()).optional(), + JoinToken: z.string().optional(), + }), + }), response: z.unknown(), }; @@ -2870,6 +2956,7 @@ export const post_SwarmUpdate = { rotateManagerToken: z.boolean(), rotateManagerUnlockKey: z.boolean(), }), + body: SwarmSpec, }), response: z.unknown(), }; @@ -2888,7 +2975,11 @@ export type post_SwarmUnlock = typeof post_SwarmUnlock; export const post_SwarmUnlock = { method: z.literal("POST"), path: z.literal("/swarm/unlock"), - parameters: z.never(), + parameters: z.object({ + body: z.object({ + UnlockKey: z.string().optional(), + }), + }), response: z.unknown(), }; @@ -2913,6 +3004,7 @@ export const post_ServiceCreate = { header: z.object({ "X-Registry-Auth": z.string().optional(), }), + body: z.intersection(ServiceSpec, z.unknown()), }), response: z.object({ ID: z.string().optional(), @@ -2963,6 +3055,7 @@ export const post_ServiceUpdate = { header: z.object({ "X-Registry-Auth": z.string().optional(), }), + body: z.intersection(ServiceSpec, z.unknown()), }), response: ServiceUpdateResponse, }; @@ -3049,7 +3142,9 @@ export type post_SecretCreate = typeof post_SecretCreate; export const post_SecretCreate = { method: z.literal("POST"), path: z.literal("/secrets/create"), - parameters: z.never(), + parameters: z.object({ + body: z.intersection(SecretSpec, z.unknown()), + }), response: IdResponse, }; @@ -3088,6 +3183,7 @@ export const post_SecretUpdate = { path: z.object({ id: z.string(), }), + body: SecretSpec, }), response: z.unknown(), }; @@ -3108,7 +3204,9 @@ export type post_ConfigCreate = typeof post_ConfigCreate; export const post_ConfigCreate = { method: z.literal("POST"), path: z.literal("/configs/create"), - parameters: z.never(), + parameters: z.object({ + body: z.intersection(ConfigSpec, z.unknown()), + }), response: IdResponse, }; @@ -3147,6 +3245,7 @@ export const post_ConfigUpdate = { path: z.object({ id: z.string(), }), + body: ConfigSpec, }), response: z.unknown(), }; diff --git a/packages/typed-openapi/tests/snapshots/petstore.arktype.ts b/packages/typed-openapi/tests/snapshots/petstore.arktype.ts index 1f86d10..dd78826 100644 --- a/packages/typed-openapi/tests/snapshots/petstore.arktype.ts +++ b/packages/typed-openapi/tests/snapshots/petstore.arktype.ts @@ -55,13 +55,17 @@ export const types = scope({ put_UpdatePet: { method: '"PUT"', path: '"/pet"', - parameters: "never", + parameters: { + body: "Pet", + }, response: "Pet", }, post_AddPet: { method: '"POST"', path: '"/pet"', - parameters: "never", + parameters: { + body: "Pet", + }, response: "Pet", }, get_FindPetsByStatus: { @@ -131,6 +135,7 @@ export const types = scope({ path: { petId: "number", }, + body: "string", }, response: "ApiResponse", }, @@ -143,7 +148,9 @@ export const types = scope({ post_PlaceOrder: { method: '"POST"', path: '"/store/order"', - parameters: "never", + parameters: { + body: "Order", + }, response: "Order", }, get_GetOrderById: { @@ -169,13 +176,17 @@ export const types = scope({ post_CreateUser: { method: '"POST"', path: '"/user"', - parameters: "never", + parameters: { + body: "User", + }, response: "User", }, post_CreateUsersWithListInput: { method: '"POST"', path: '"/user/createWithList"', - parameters: "never", + parameters: { + body: "User[]", + }, response: "unknown", }, get_LoginUser: { @@ -212,6 +223,7 @@ export const types = scope({ path: { username: "string", }, + body: "User", }, response: "unknown", }, diff --git a/packages/typed-openapi/tests/snapshots/petstore.client.ts b/packages/typed-openapi/tests/snapshots/petstore.client.ts index 41e75e3..afadedd 100644 --- a/packages/typed-openapi/tests/snapshots/petstore.client.ts +++ b/packages/typed-openapi/tests/snapshots/petstore.client.ts @@ -41,13 +41,17 @@ export namespace Endpoints { export type put_UpdatePet = { method: "PUT"; path: "/pet"; - parameters: never; + parameters: { + body: Pet; + }; response: Schemas.Pet; }; export type post_AddPet = { method: "POST"; path: "/pet"; - parameters: never; + parameters: { + body: Pet; + }; response: Schemas.Pet; }; export type get_FindPetsByStatus = { @@ -98,6 +102,8 @@ export namespace Endpoints { parameters: { query: Partial<{ additionalMetadata: string }>; path: { petId: number }; + + body: string; }; response: Schemas.ApiResponse; }; @@ -110,7 +116,9 @@ export namespace Endpoints { export type post_PlaceOrder = { method: "POST"; path: "/store/order"; - parameters: never; + parameters: { + body: Order; + }; response: Schemas.Order; }; export type get_GetOrderById = { @@ -132,13 +140,17 @@ export namespace Endpoints { export type post_CreateUser = { method: "POST"; path: "/user"; - parameters: never; + parameters: { + body: User; + }; response: Schemas.User; }; export type post_CreateUsersWithListInput = { method: "POST"; path: "/user/createWithList"; - parameters: never; + parameters: { + body: Array; + }; response: unknown; }; export type get_LoginUser = { @@ -168,6 +180,8 @@ export namespace Endpoints { path: "/user/{username}"; parameters: { path: { username: string }; + + body: User; }; response: unknown; }; diff --git a/packages/typed-openapi/tests/snapshots/petstore.io-ts.ts b/packages/typed-openapi/tests/snapshots/petstore.io-ts.ts index 0967175..c1e0141 100644 --- a/packages/typed-openapi/tests/snapshots/petstore.io-ts.ts +++ b/packages/typed-openapi/tests/snapshots/petstore.io-ts.ts @@ -76,7 +76,9 @@ export type put_UpdatePet = t.TypeOf; export const put_UpdatePet = t.type({ method: t.literal("PUT"), path: t.literal("/pet"), - parameters: t.never, + parameters: t.type({ + body: Pet, + }), response: Pet, }); @@ -84,7 +86,9 @@ export type post_AddPet = t.TypeOf; export const post_AddPet = t.type({ method: t.literal("POST"), path: t.literal("/pet"), - parameters: t.never, + parameters: t.type({ + body: Pet, + }), response: Pet, }); @@ -166,6 +170,7 @@ export const post_UploadFile = t.type({ path: t.type({ petId: t.number, }), + body: t.string, }), response: ApiResponse, }); @@ -182,7 +187,9 @@ export type post_PlaceOrder = t.TypeOf; export const post_PlaceOrder = t.type({ method: t.literal("POST"), path: t.literal("/store/order"), - parameters: t.never, + parameters: t.type({ + body: Order, + }), response: Order, }); @@ -214,7 +221,9 @@ export type post_CreateUser = t.TypeOf; export const post_CreateUser = t.type({ method: t.literal("POST"), path: t.literal("/user"), - parameters: t.never, + parameters: t.type({ + body: User, + }), response: User, }); @@ -222,7 +231,9 @@ export type post_CreateUsersWithListInput = t.TypeOf; export const put_UpdatePet = Type.Object({ method: Type.Literal("PUT"), path: Type.Literal("/pet"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Pet, + }), response: Pet, }); @@ -97,7 +99,9 @@ export type post_AddPet = Static; export const post_AddPet = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/pet"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Pet, + }), response: Pet, }); @@ -189,6 +193,7 @@ export const post_UploadFile = Type.Object({ path: Type.Object({ petId: Type.Number(), }), + body: Type.String(), }), response: ApiResponse, }); @@ -205,7 +210,9 @@ export type post_PlaceOrder = Static; export const post_PlaceOrder = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/store/order"), - parameters: Type.Never(), + parameters: Type.Object({ + body: Order, + }), response: Order, }); @@ -237,7 +244,9 @@ export type post_CreateUser = Static; export const post_CreateUser = Type.Object({ method: Type.Literal("POST"), path: Type.Literal("/user"), - parameters: Type.Never(), + parameters: Type.Object({ + body: User, + }), response: User, }); @@ -245,7 +254,9 @@ export type post_CreateUsersWithListInput = Static; export const put_UpdatePet = v.object({ method: v.literal("PUT"), path: v.literal("/pet"), - parameters: v.never(), + parameters: v.object({ + body: Pet, + }), response: Pet, }); @@ -83,7 +85,9 @@ export type post_AddPet = v.Output; export const post_AddPet = v.object({ method: v.literal("POST"), path: v.literal("/pet"), - parameters: v.never(), + parameters: v.object({ + body: Pet, + }), response: Pet, }); @@ -165,6 +169,7 @@ export const post_UploadFile = v.object({ path: v.object({ petId: v.number(), }), + body: v.string(), }), response: ApiResponse, }); @@ -181,7 +186,9 @@ export type post_PlaceOrder = v.Output; export const post_PlaceOrder = v.object({ method: v.literal("POST"), path: v.literal("/store/order"), - parameters: v.never(), + parameters: v.object({ + body: Order, + }), response: Order, }); @@ -213,7 +220,9 @@ export type post_CreateUser = v.Output; export const post_CreateUser = v.object({ method: v.literal("POST"), path: v.literal("/user"), - parameters: v.never(), + parameters: v.object({ + body: User, + }), response: User, }); @@ -221,7 +230,9 @@ export type post_CreateUsersWithListInput = v.Output value === "PUT").required(), path: y.mixed((value): value is "/pet" => value === "/pet").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: Pet, + }), response: Pet, }; @@ -107,7 +109,9 @@ export type post_AddPet = typeof post_AddPet; export const post_AddPet = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/pet" => value === "/pet").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: Pet, + }), response: Pet, }; @@ -197,6 +201,7 @@ export const post_UploadFile = { path: y.object({ petId: y.number().required(), }), + body: y.string().required(), }), response: ApiResponse, }; @@ -213,7 +218,9 @@ export type post_PlaceOrder = typeof post_PlaceOrder; export const post_PlaceOrder = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/store/order" => value === "/store/order").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: Order, + }), response: Order, }; @@ -245,7 +252,9 @@ export type post_CreateUser = typeof post_CreateUser; export const post_CreateUser = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/user" => value === "/user").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: User, + }), response: User, }; @@ -253,7 +262,9 @@ export type post_CreateUsersWithListInput = typeof post_CreateUsersWithListInput export const post_CreateUsersWithListInput = { method: y.mixed((value): value is "POST" => value === "POST").required(), path: y.mixed((value): value is "/user/createWithList" => value === "/user/createWithList").required(), - parameters: y.mixed((value): value is never => false).required(), + parameters: y.object({ + body: y.array(User), + }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; @@ -298,6 +309,7 @@ export const put_UpdateUser = { path: y.object({ username: y.string().required(), }), + body: User, }), response: y.mixed((value): value is any => true).required() as y.MixedSchema, }; diff --git a/packages/typed-openapi/tests/snapshots/petstore.zod.ts b/packages/typed-openapi/tests/snapshots/petstore.zod.ts index 44b97b6..ef19b64 100644 --- a/packages/typed-openapi/tests/snapshots/petstore.zod.ts +++ b/packages/typed-openapi/tests/snapshots/petstore.zod.ts @@ -70,7 +70,9 @@ export type put_UpdatePet = typeof put_UpdatePet; export const put_UpdatePet = { method: z.literal("PUT"), path: z.literal("/pet"), - parameters: z.never(), + parameters: z.object({ + body: Pet, + }), response: Pet, }; @@ -78,7 +80,9 @@ export type post_AddPet = typeof post_AddPet; export const post_AddPet = { method: z.literal("POST"), path: z.literal("/pet"), - parameters: z.never(), + parameters: z.object({ + body: Pet, + }), response: Pet, }; @@ -160,6 +164,7 @@ export const post_UploadFile = { path: z.object({ petId: z.number(), }), + body: z.string(), }), response: ApiResponse, }; @@ -176,7 +181,9 @@ export type post_PlaceOrder = typeof post_PlaceOrder; export const post_PlaceOrder = { method: z.literal("POST"), path: z.literal("/store/order"), - parameters: z.never(), + parameters: z.object({ + body: Order, + }), response: Order, }; @@ -208,7 +215,9 @@ export type post_CreateUser = typeof post_CreateUser; export const post_CreateUser = { method: z.literal("POST"), path: z.literal("/user"), - parameters: z.never(), + parameters: z.object({ + body: User, + }), response: User, }; @@ -216,7 +225,9 @@ export type post_CreateUsersWithListInput = typeof post_CreateUsersWithListInput export const post_CreateUsersWithListInput = { method: z.literal("POST"), path: z.literal("/user/createWithList"), - parameters: z.never(), + parameters: z.object({ + body: z.array(User), + }), response: z.unknown(), }; @@ -261,6 +272,7 @@ export const put_UpdateUser = { path: z.object({ username: z.string(), }), + body: User, }), response: z.unknown(), };