Skip to content

Update an OpenAPI specification

Before you begin

Plan
Included in Free, Pro and Team. How plans and limits work
Role
Viewer or higher to read the contract and Editor or higher to update or delete it.
You need
  • A project with an OpenAPI contract

Import the new version of your API’s document to bring the project’s mocks up to date, without losing the changes you made to them since their import.

  1. Open your project’s OpenAPI tab and select Update the specification.

  2. Upload or paste the new version of the document, and select Continue.

  3. Under Choose responses, the responses you imported before are ticked. Tick any others the update should add, then select Review.

  4. Open What changed in the document: each operation Added, Removed or Changed, tagged Breaking, Potentially breaking or Non-breaking, with what changed in it.

  5. Read Mocks. Each mock is one operation, and its lines say what the update does to each of its responses, beside the mock’s Default response and its Activation:

    A line reads Means
    200 Order created Updated from specification The document changed it and you had not
    422 Invalid email Your edited Response body will be kept You changed it, and the document did not change that part
    404 Order missing New response The document has an example the mock has no response for yet
    Removed from specification; kept in the mock The document no longer has it; the response stays unless you delete it
    Default response Unchanged An update never moves the default on its own

    A response can be updated in one part and keep your edit in another, and the line says both.

  6. For each conflict, a part both you and the document changed, such as Response body: you and the specification both changed it., choose Keep my value or Use specification value, then select Update the preview. Open Details of the response to see Your current value beside Specification value.

  7. Under No longer in the document, tick Delete beside any response you no longer want, such as Delete Invalid email of Create order, then select Update the preview. A mock that holds nothing else, such as the mock of an operation the document dropped, is offered whole, such as Delete the mock GET /orders/me, which holds nothing else. When a response you delete is the default, choose the response that takes its place under Replacement default; the update cannot be applied until you do.

  8. Select Apply import. When the plan deletes mocks or responses, a dialog names them; select Apply and delete.

The OpenAPI tab shows Import applied: Applied revision with the new number, and lists the mocks under Created and Updated, with the number of responses each now holds and whether it is active, and which stayed as they were. An update keeps a mock’s activation as it is. Revisions lists the new revision as Active, and every earlier one your plan keeps.

A saved-but-not-synchronised update, shown as Saved. with a note that active mocks may answer the old way for a few seconds, is complete and is not applied again; it goes live by itself.

The update changes only what its preview showed. If the project, its contract or one of its mocks changed between the preview and the apply, nothing is applied and the page says Nothing was applied. Update the preview and apply again.

The preview checks each mock under Mocks against the new document as the update would leave it, your kept edits included, and tags it as in What the preview checks: Meets the document, Breaks the document, Not fully checked or Not checked.

Open Details of a response, or Details of the mock’s shared fields, to see each part the update changes, Now beside After the import, tagged with where the new value comes from. A long value is shown in part; the comparison and the check read it whole.

Mocks the import leaves as they are checks every other mock linked to an operation, those you linked by hand included, and counts how many meet the new document, break it, could not be checked in full or were not checked. It names each one that does not meet it, with its findings. As for an import, a mock that breaks the document, or one that could not be checked in full, needs its tick before Apply import.

To see how your traffic fares, open Check recorded responses against this document (optional) and select Check recent logs. The newest 10 logs are checked against the active revision and the new document, and a line says how the verdicts move, such as Against the second document: 2 now invalid, 0 now valid, 8 the same, 0 not comparable. See Check recorded responses first.

What changed in the document also lists each operation whose security requirements change, marked Security:, such as an operation that no longer needs a credential, or needs another scope. Each change says where the requirement is declared now (Declared at) and where it was (Was declared at), such as /security for the whole document or /paths/~1orders/get/security for one operation.

The contract describes authentication; nothing enforces it on requests to your mocks. Use a private project to require a key.

For a field’s history, open Previous generated, current and incoming values in its details. The three values show what the last import generated, what is saved now, and what the new specification generates. Long values are marked as shown in part; decisions compare their complete contents.

  • New examples are not imported by default: an update takes the examples you imported before. Add others under Choose responses, or one at a time from the mock.
  • An operation new in the document gets no mock by default. Choose responses says how many are new, such as 2 operations are new in this document and get no mock unless you add them.; select Add them to pick each one’s default response. From the CLI, --new-operations does the same, but only on the run that first brings the document: once an import is applied, its operations are no longer new, and a second run with the flag adds nothing. After that, create the mock of one operation from the OpenAPI tab.
  • The default stays as you set it. A new success example that ranks higher does not replace it, and an update never changes it unless you ask, by deleting it and choosing a Replacement default.
  • A response you added by hand to an imported mock is never changed or deleted. A response whose example is gone stays, unchanged and marked as no longer in the document, until you delete it; a later document that has the example again updates it.
  • An example that changes identity, such as an example renamed in the document, is a new response and a removed one, never a rename: MockHub does not guess from equal bodies.
  • A mock whose operation is gone stays, unchanged, until you delete it. Its link to the removed operation stays too, shown as not in the active revision, and comes back if a later version restores the operation.
  • A renamed path parameter, such as {id} to {orderId}, is the same operation. Its mocks keep their links and your edits.
  • A mock you wrote by hand and linked to an operation is never changed or deleted.
  • Keep my value keeps your value for that part. A later update treats it as your edit, so the same conflict does not come back unless the document changes the part again.
  • An update leaves the tags of existing mocks as they are, so a tag you removed does not come back. Mocks the update creates are tagged with their operation’s tags.
  • The Base path starts as the one the active revision’s mocks are served under, so an update leaves them where they are. Empty it to serve them under their operations’ server paths.

A response the operation offers and its mock does not hold, such as a 409 an import left out, can be added to the mock without importing the document again. It comes from the active revision and stays linked to it, so a later update updates it like the mock’s other imported responses.

  1. Open the mock. Save or discard any edits first: adding a response writes the saved mock.

  2. Select Response, and under From the contract select the response, such as 409 ISBN already exists.

  3. Read Add “409 ISBN already exists” from the contract: its status code, headers and body, and whether the mock with it meets the document.

  4. Select Add response.

The mock opens on the new response, tagged From the contract. The mock’s default and its other responses stay as they are.

The OpenAPI tab offers the same: select Responses beside an operation, and under The contract offers these too; the mock does not hold them: select the response.

Only a mock an import made from the operation can take one; a mock you linked by hand is offered none. When adding the response would change more than this mock, the panel says so and applies nothing; use Update the specification instead, where the whole plan is shown.

Create a mock for an operation without one

Section titled “Create a mock for an operation without one”

An operation of the active revision with no mock linked, such as one a later document added, offers Create mock on the OpenAPI tab, in Operations and in Coverage. Its panel, Create a mock for GET /customers, names the mock, the response it answers with and whether it meets the document. Select Create mock to create it.

The mock starts inactive, answers with the operation’s default response and stays linked to the document, so a later update updates it. For an operation with no example the import can use, or a method a mock cannot answer, Operations offers no Create mock and the panel opened from Coverage says an import would not create one. When creating it would change more than this mock, the panel says so and applies nothing; use Update the specification instead.

To see what the active revision changed from an earlier one, select Compare with active beside the earlier one under Revisions. The changes are listed as under What changed in the document.

To make an earlier revision active again:

  1. Select Restore beside it under Revisions. The import opens as Restore revision with its number.

  2. Select Continue, then Review.

  3. Read Your customized mocks. Your edits stay: names each mock and part you changed that the restore leaves alone. A part you and that revision both changed is a conflict under Mocks: choose Keep my value or Use specification value, then select Update the preview.

  4. Under Imported after revision, tick Delete beside any response you no longer want, then select Update the preview.

  5. Select Apply restore.

The restore is a new revision, listed under Revisions with Restored from revision and the number. Only the document comes back: mocks imported after that revision stay unless you delete them, and mocks you deleted since come back only if you choose them under Choose responses. The new revision downloads as JSON.

Select Delete contract, and confirm. Every revision is deleted, and the mocks lose their links and their import history. The mocks themselves stay, including any served as written.

  • A mock that answers with a sequence keeps it: an update changes the responses its steps name but never the steps, and a response a step names cannot be deleted until the steps no longer name it.
  • Consolidating older mocks that one operation was imported into several times is covered in Import an OpenAPI specification. Until it is settled, or the mocks are set to stop being managed by imports, the operation is not updated.
  • A mock a webhook fires on cannot be deleted by an update, as it cannot be deleted on its own. Change the webhook first.
  • The Breaking tags follow what a document can show, such as a removed operation or a new required parameter. Every schema change is Potentially breaking, because whether a caller still works depends on what it sends.
  • Callbacks and links are not compared. Security requirements are compared as written: the alternatives, the schemes each needs and their scopes, in any order. A requirement whose scheme cannot be found on one side says Its security could not be compared in full: and why, never that nothing changed.

Report a problem with this page