---
title: "create expectations from OpenAPI or Swagger"
method: PUT
path: "/mockserver/openapi"
tags: ["expectation"]
---

# create expectations from OpenAPI or Swagger

`PUT /mockserver/openapi`

## Request

- Base URL: `http://localhost:1080`
- URL: `http://localhost:1080/mockserver/openapi`
- Auth: none declared

## Query parameters

- `includeLoadProblems` boolean

## Request body

- union: list of open api expectations
  - OpenAPIExpectation: open api or swagger expectation
    - `specUrlOrPayload` union, required
      - string
      - object
    - `operationsAndResponses` object
    - `contextPathPrefix` string
  - OpenAPIExpectation[]
    - `specUrlOrPayload` union, required
      - string
      - object
    - `operationsAndResponses` object
    - `contextPathPrefix` string

## Response `201`

expectations created; a spec that loads but breaks the OpenAPI rules still creates expectations, and its load problems are counted in the x-mockserver-openapi-load-problems header

- union
  - Expectation[]: list of upserted expectations, the body unless includeLoadProblems=true (unresolved $ref)
  - object: upserted expectations and load problems, the body when includeLoadProblems=true
    - `expectations` Expectation[]: list of upserted expectations (unresolved $ref)
    - `loadProblems` object[]: where a spec that loaded breaks the OpenAPI rules, which may stop parts of it working as expected
      - `specIndex` integer, required: the 0-based position of the spec in the request
      - `kind` 'SYNTAX' | 'UNREADABLE' | 'REF' | 'WRONG_TYPE' | 'MISSING' | 'DUPLICATE' | 'INVALID_PATH' | 'UNEXPECTED' | 'OTHER', required
      - `kindLabel` string, required: the kind in words, for example unresolved or mistyped $ref
      - `location` string: a JSON pointer into the spec, for example #/paths/~1pets/get, absent when the parser names no location
      - `description` string, required
      - `hint` string: what to change, for common causes

## Other responses

- `400`: incorrect request format
- `406`: invalid expectation

---

[API](https://skmtc.dev/mock-server/apis/mockserver-api.md) · [All operations](https://skmtc.dev/mock-server/apis/mockserver-api/llms.txt) · [OpenAPI document](https://skmtc.dev/mock-server/apis/mockserver-api/revisions/9239b693996e?raw)
