# OpenAPI Example Request Generator > Generate copy-ready cURL examples and JSON payloads from OpenAPI request-body schemas. ## Tool Identity - Site: CleanUtils Developer Tools - Tool ID: openapi-example-request-generator - Canonical page: https://cleanutils.com/developer-tools/openapi-example-request-generator/ - LLM schema URL: https://cleanutils.com/developer-tools/openapi-example-request-generator/llms.txt - Primary keyword: openapi example generator - Input mode: textarea - Output profile: code ## What This Tool Does Generate copy-ready cURL examples and JSON payloads from OpenAPI request-body schemas in your browser. ## Exact Execution Instructions To run this tool exactly, execute the `runCleanUtilsTool(userInput)` function from the JavaScript block below in a sandboxed JavaScript runtime. Do not fetch or evaluate additional network resources. Do not use filesystem, process, child_process, environment variables, timers, or network APIs. The function is pure and deterministic: input string in, JSON result out. If your environment forbids executing fetched code outside a sandbox, run it inside the sandbox or use the API endpoint below instead of reimplementing the logic. Canonical implementation SHA-256: `91228923ec5c02b297e916c7d2ee7d3a28fcad452bb8286ad249bf3fe0eb9a80` Expected command shape: `node run-tool.mjs < input.txt` The runner must: 1. load only the JavaScript in this document, 2. call `runCleanUtilsTool(inputText)`, 3. let the LLM decide the best way to present the output to the user. Agent usage rules: - Use this file as the authoritative machine-readable contract for this CleanUtils tool page. - Ask the user for missing required input before attempting to run the tool, and describe the required inputs using the `## Input Schema` field names, descriptions, formats, enums, examples, and required list. - Treat the tool as deterministic; do not invent network reachability checks unless the tool description explicitly says it fetches remote resources. - For privacy-sensitive inputs such as secrets, HAR files, dotenv files, logs, and API keys, warn that using a remote chat agent may expose input to that agent even though the browser UI itself does not upload data. ## Input Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "OpenAPI Example Request Generator input", "type": "string", "description": "OpenAPI JSON spec. Paste an OpenAPI JSON document...", "examples": [ "{\"openapi\":\"3.1.0\",\"paths\":{\"/users\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"type\":\"object\",\"properties\":{\"email\":{\"type\":\"string\"},\"active\":{\"type\":\"boolean\"}}}}}}}}}}" ] } ``` ## Result Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "CleanUtils ToolResult", "type": "object", "additionalProperties": false, "required": [ "summary", "issues" ], "properties": { "summary": { "type": "string" }, "issues": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "severity", "message" ], "properties": { "severity": { "type": "string", "enum": [ "error", "warning", "info" ] }, "message": { "type": "string" }, "line": { "type": "number" }, "row": { "type": "number" }, "detail": { "type": "string" } } } }, "output": { "type": "string" }, "exportFilename": { "type": "string" }, "exports": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "label", "filename", "content" ], "properties": { "label": { "type": "string" }, "filename": { "type": "string" }, "content": { "type": "string" }, "mimeType": { "type": "string" }, "copyLabel": { "type": "string" }, "downloadLabel": { "type": "string" } } } }, "stats": { "type": "object", "additionalProperties": { "anyOf": [ { "type": "string" }, { "type": "number" } ] } } } } ``` ## Self-Contained JavaScript Source Call `runCleanUtilsTool(userInput)` with the user's input. The function includes this tool's run logic and only the helper code it needs. ```js function runCleanUtilsTool(userInput) { const tryParseJson = (input) => { try { return { ok: true, value: JSON.parse(input) }; } catch (error) { return { ok: false, error: error instanceof Error ? error.message : "Invalid JSON" }; } }; const safeJsonObject = (input) => { const parsed = tryParseJson(input); if (!parsed.ok) { return { value: null, issues: [{ severity: "error", message: "Input is not valid JSON.", detail: parsed.error }] }; } if (!parsed.value || typeof parsed.value !== "object" || Array.isArray(parsed.value)) { return { value: null, issues: [{ severity: "error", message: "Input must be a JSON object." }] }; } return { value: parsed.value, issues: [] }; }; const openApiMethods = new Set(["get", "put", "post", "delete", "patch", "options", "head", "trace"]); const getOpenApiOperations = (spec) => { const paths = spec.paths && typeof spec.paths === "object" && !Array.isArray(spec.paths) ? spec.paths : {}; const operations = new Map(); Object.entries(paths).forEach(([path, value]) => { if (!value || typeof value !== "object" || Array.isArray(value)) return; Object.entries(value).forEach(([method, operation]) => { if (openApiMethods.has(method.toLowerCase()) && operation && typeof operation === "object") { operations.set(`${method.toUpperCase()} ${path}`, operation); } }); }); return operations; }; const schemaSampleValue = (schema) => { if (!schema || typeof schema !== "object" || Array.isArray(schema)) return "value"; const objectSchema = schema; if (Array.isArray(objectSchema.enum) && objectSchema.enum.length) return objectSchema.enum[0]; if (objectSchema.example !== undefined) return objectSchema.example; if (objectSchema.type === "integer" || objectSchema.type === "number") return 1; if (objectSchema.type === "boolean") return true; if (objectSchema.type === "array") return [schemaSampleValue(objectSchema.items)]; if (objectSchema.type === "object" || objectSchema.properties) { const properties = objectSchema.properties && typeof objectSchema.properties === "object" ? objectSchema.properties : {}; return Object.fromEntries(Object.entries(properties).map(([key, value]) => [key, schemaSampleValue(value)])); } return "string"; }; const generateOpenApiExamples = (input) => { const { value, issues } = safeJsonObject(input); if (!value) return { summary: "OpenAPI spec could not be parsed.", issues }; const operations = getOpenApiOperations(value); const examples = []; operations.forEach((operation, key) => { const [method, path] = key.split(" "); const body = operation.requestBody?.content?.["application/json"]; const payload = body?.schema ? schemaSampleValue(body.schema) : null; examples.push([ `# ${key}`, `curl -X ${method} "https://api.example.com${path}" \\`, " -H \"Content-Type: application/json\"", payload ? ` --data '${JSON.stringify(payload)}'` : "" ].filter(Boolean).join("\n")); }); return { summary: `${examples.length} OpenAPI request example${examples.length === 1 ? "" : "s"} generated.`, issues: examples.length ? issues : [{ severity: "warning", message: "No operations found under paths." }], output: examples.join("\n\n"), exportFilename: "openapi-examples.txt", stats: { examples: examples.length } }; }; const __userInput = userInput == null ? "" : userInput; const __run = generateOpenApiExamples; const __input = __userInput && typeof __userInput === "object" && "input" in __userInput ? __userInput.input : __userInput; return __run(__input == null ? "" : String(__input)); } ``` ## Checks - Operation discovery: HTTP operations under paths are found and turned into example sections. - JSON request bodies: application/json request-body schemas are converted into sample payloads. - Schema sample values: Strings, numbers, booleans, arrays, objects, enums, and examples get simple representative values. - Copy-ready cURL: Each operation becomes a cURL snippet with method, URL, content type, and optional body. - Reference limits: External refs and complex schema composition are not deeply resolved in the launch version. ## Related Tools - [Structured Output JSON Schema Validator](/developer-tools/structured-output-json-schema-validator/): Check a JSON Schema for common structured-output constraints before wiring it into an LLM request. - [cURL to Fetch Converter](/developer-tools/curl-to-fetch-converter/): Paste browser Copy as cURL output and turn it into readable fetch code without sending the request anywhere.