Skip to main content

OpenAPI JSON Spec

Endpoint Mock

Incolla una spec OpenAPI e clicca Genera Mock

Come utilizzare API Mock from OpenAPI Spec

Attach the specific OpenAPI 3.0 in JSON format

Copy the content of your openapi.json (or swagger.json) file and paste it into the text area. The format must be valid JSON and follow the OpenAPI 3.0 standard with a "paths" section present.

Analyze reported endpoints

After parsing, the tool shows all endpoints of the specific API with HTTP method, path and description. Each endpoint has a mock response generated automatically based on the defined schema.

Copy mock JSON for testing

For each endpoint, click the "Copy" button to copy the JSON mock into your notes. Use the mock as a simulated response in your unit tests, local development server, or in collections like Postman/Insomnia.

Suggerimenti

  • If your spec uses the "$ref" section for reusable components, ensure all references are inline in the spec (or resolved) before pasting it. External file references are not resolved.
  • Use generated mocks as fixtures in Jest or Vitest tests: import the JSON as a constant in the test and use it as the return value of the HTTP service mock for deterministic and fast tests.
  • Tools like Prism (Stoplight) or MSW (Mock Service Worker) can use your spec directly OpenAPI to create a full mock server: ideal for local development when the backend isn't available yet.

Domande frequenti

What is a mock response in an API?

A mock response is a simulated JSON data that represents how the real API response would be without actually calling the server. It's useful for testing the frontend in isolation, developing functionality before the backend is ready, and writing deterministic unit tests.

Does the tool support OpenAPI 2.0 (Swagger)?

The tool is optimized for OpenAPI 3.0. OpenAPI 2.0 (Swagger) has a different structure and may not be parsed correctly. To use it with an OpenAPI 2.0 spec, first convert the spec to 3.0 format using tools like swagger2openapi or Swagger Editor's online converter.

How are values generated in mocks?

Values are generated deterministically from schema definition in the spec. Strings, numbers, booleans, and arrays are populated with plausible example values based on type and constraints (minLength, minimum, enum, etc.). Values are static, non-random, to ensure reproducibility of tests.

Are data being sent to a server?

No, the entire process occurs in the browser (client-side). The attached OpenAPI spec is not sent to any server. Parsing and generating mocks happen through JavaScript in your browser.