|
1 | 1 | import { z } from 'zod'; |
2 | 2 | import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; |
3 | 3 | export const method = 'create-spec'; |
4 | | -export const description = "Creates an API specification in Postman's [Spec Hub](https://learning.postman.com/docs/design-apis/specifications/overview/).\n\n**Note:**\n- Postman supports OpenAPI 3.0 and AsyncAPI 2.0 specifications.\n- This endpoint does not yet support multiple files.\n"; |
| 4 | +export const description = "Creates an API specification in Postman's [Spec Hub](https://learning.postman.com/docs/design-apis/specifications/overview/). Specifications can be single or multi-file.\n\n**Note:**\n- Postman supports OpenAPI 3.0 and AsyncAPI 2.0 specifications.\n- If the file path contains a \\`/\\` (forward slash) character, then a folder is created. For example, if the path is the \\`components/schemas.json\\` value, then a \\`components\\` folder is created with the \\`schemas.json\\` file inside.\n- Multi-file specifications can only have one root file.\n- Files cannot exceed a maximum of 10 MB in size.\n"; |
5 | 5 | export const parameters = z.object({ |
6 | 6 | workspaceId: z.string().describe("The workspace's ID."), |
7 | 7 | name: z.string().describe("The specification's name."), |
8 | 8 | type: z.enum(['OPENAPI:3.0', 'ASYNCAPI:2.0']).describe("The specification's type."), |
9 | 9 | files: z |
10 | | - .array(z.object({ |
11 | | - path: z |
12 | | - .string() |
13 | | - .describe("The file's path. Accepts the `index.json` or `index.yaml` value."), |
14 | | - content: z.string().describe("The file's stringified contents."), |
| 10 | + .array(z.any().superRefine((x, ctx) => { |
| 11 | + const schemas = [ |
| 12 | + z.object({ |
| 13 | + path: z.string().describe("The file's path. Accepts JSON or YAML files."), |
| 14 | + content: z.string().describe("The file's stringified contents."), |
| 15 | + type: z |
| 16 | + .enum(['DEFAULT', 'ROOT']) |
| 17 | + .describe('The type of file. This property is required when creating multi-file specifications:\n- `ROOT` — The file containing the full OpenAPI structure. This serves as the entry point for the API spec and references other (`DEFAULT`) spec files. Multi-file specs can only have one root file.\n- `DEFAULT` — A file referenced by the `ROOT` file.\n'), |
| 18 | + }), |
| 19 | + z.object({ |
| 20 | + path: z.string().describe("The file's path. Accepts JSON or YAML files."), |
| 21 | + content: z.string().describe("The file's stringified contents."), |
| 22 | + }), |
| 23 | + ]; |
| 24 | + const errors = schemas.reduce((errors, schema) => ((result) => (result.error ? [...errors, result.error] : errors))(schema.safeParse(x)), []); |
| 25 | + if (schemas.length - errors.length !== 1) { |
| 26 | + ctx.addIssue({ |
| 27 | + path: ctx.path, |
| 28 | + code: 'invalid_union', |
| 29 | + unionErrors: errors, |
| 30 | + message: 'Invalid input: Should pass single schema', |
| 31 | + }); |
| 32 | + } |
15 | 33 | })) |
16 | 34 | .describe("A list of the specification's files and their contents."), |
17 | 35 | }); |
18 | 36 | export const annotations = { |
19 | | - title: "Creates an API specification in Postman's [Spec Hub](https://learning.postman.com/docs/design-apis/specifications/overview/).\n\n**Note:**\n- Postman supports OpenAPI 3.0 and AsyncAPI 2.0 specifications.\n- This endpoint does not yet support multiple files.\n", |
| 37 | + title: "Creates an API specification in Postman's [Spec Hub](https://learning.postman.com/docs/design-apis/specifications/overview/). Specifications can be single or multi-file.\n\n**Note:**\n- Postman supports OpenAPI 3.0 and AsyncAPI 2.0 specifications.\n- If the file path contains a \\`/\\` (forward slash) character, then a folder is created. For example, if the path is the \\`components/schemas.json\\` value, then a \\`components\\` folder is created with the \\`schemas.json\\` file inside.\n- Multi-file specifications can only have one root file.\n- Files cannot exceed a maximum of 10 MB in size.\n", |
20 | 38 | readOnlyHint: false, |
21 | 39 | destructiveHint: false, |
22 | 40 | idempotentHint: false, |
|
0 commit comments