--- title: OpenAPI & WSDL description: Generate mock expectations from OpenAPI v3 or WSDL (SOAP) specifications; use OpenAPI request matchers for verification, clearing, and log retrieval. shortTitle: OpenAPI & WSDL layout: page pageOrder: 5 section: 'Creating Mocks' subsection: true sitemap: priority: 0.8 changefreq: 'monthly' lastmod: 2026-06-11T00:00:00+00:00 keywords: OpenAPI, Swagger, OpenAPI v3, WSDL, SOAP, generate mock expectations, spec-driven mocking, OpenAPI request matcher, WSDL mock, SOAP mock ---
MockServer can generate mock expectations automatically from two types of API specification:
OpenAPI specifications can be used in request matchers for:
OpenAPI specifications can also be used to generate expectations with example responses. For SOAP services, see Generate Expectations From WSDL (SOAP).
Two features make the OpenAPI workflow especially useful for testing pipelines:
The table below shows which operations are available for each specification format. OpenAPI supports the full feature set; WSDL is limited to generating mock expectations.
| Capability | OpenAPI v3 | WSDL 1.1 (SOAP) |
|---|---|---|
| Generate mock expectations | Yes | Yes |
| Use as a request matcher | Yes | No |
| Verify received requests | Yes | No |
| Clear / filter the request log | Yes | No |
| Contract testing against a live service | Yes | No |
| Idempotent incremental re-import | Yes | No |
If you only need a single response with a realistic, type-correct body — and do not want to attach a whole OpenAPI specification — a response can carry a plain JSON Schema directly using the generateFromSchema field. At response time MockServer generates a schema-valid JSON body from it, using the same example generator as the OpenAPI path, so the generated body honours type, required, enum, default, arrays and nested objects.
This is only used when the response has no explicit body — an explicit body always takes precedence — and a schema that cannot be parsed simply leaves the body unset (and is logged) rather than failing the request.
The generateFromSchema field takes the JSON Schema as a string. The Java, .NET and Rust clients expose a typed setter (withGenerateFromSchema / the GenerateFromSchema property / generate_from_schema); JavaScript submits the raw expectation JSON directly; the remaining clients (Python, Ruby, Go, PHP) have no typed setter, so they submit the same expectation as raw JSON via the PUT /mockserver/expectation REST endpoint.
new MockServerClient("localhost", 1080)
.when(
request()
.withPath("/users/1")
)
.respond(
response()
.withStatusCode(200)
.withGenerateFromSchema("{" +
"\"type\":\"object\"," +
"\"required\":[\"id\",\"status\"]," +
"\"properties\":{" +
"\"id\":{\"type\":\"integer\"}," +
"\"status\":{\"type\":\"string\",\"enum\":[\"ACTIVE\",\"DISABLED\"]}," +
"\"tags\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}" +
"}}")
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).mockAnyResponse({
"httpRequest": {
"path": "/users/1"
},
"httpResponse": {
"statusCode": 200,
"generateFromSchema": "{\"type\":\"object\",\"required\":[\"id\",\"status\"],\"properties\":{\"id\":{\"type\":\"integer\"},\"status\":{\"type\":\"string\",\"enum\":[\"ACTIVE\",\"DISABLED\"]},\"tags\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}}"
}
}).then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
import json
import requests
# The Python client's HttpResponse has no typed generateFromSchema setter,
# so submit the same expectation as raw JSON via the REST API.
schema = json.dumps({
"type": "object",
"required": ["id", "status"],
"properties": {
"id": {"type": "integer"},
"status": {"type": "string", "enum": ["ACTIVE", "DISABLED"]},
"tags": {"type": "array", "items": {"type": "string"}},
},
})
requests.put(
"http://localhost:1080/mockserver/expectation",
json={
"httpRequest": {"path": "/users/1"},
"httpResponse": {"statusCode": 200, "generateFromSchema": schema},
},
)
require 'json'
require 'net/http'
# The Ruby client's HttpResponse has no typed generateFromSchema setter,
# so submit the same expectation as raw JSON via the REST API.
schema = JSON.generate({
'type' => 'object',
'required' => %w[id status],
'properties' => {
'id' => { 'type' => 'integer' },
'status' => { 'type' => 'string', 'enum' => %w[ACTIVE DISABLED] },
'tags' => { 'type' => 'array', 'items' => { 'type' => 'string' } }
}
})
uri = URI('http://localhost:1080/mockserver/expectation')
Net::HTTP.start(uri.host, uri.port) do |http|
request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
request.body = JSON.generate(
'httpRequest' => { 'path' => '/users/1' },
'httpResponse' => { 'statusCode' => 200, 'generateFromSchema' => schema }
)
http.request(request)
end
import (
"bytes"
"encoding/json"
"net/http"
)
// The Go client's HttpResponse has no GenerateFromSchema field, so submit the
// same expectation as raw JSON via the REST API.
schema, _ := json.Marshal(map[string]interface{}{
"type": "object",
"required": []string{"id", "status"},
"properties": map[string]interface{}{
"id": map[string]string{"type": "integer"},
"status": map[string]interface{}{"type": "string", "enum": []string{"ACTIVE", "DISABLED"}},
"tags": map[string]interface{}{"type": "array", "items": map[string]string{"type": "string"}},
},
})
payload, _ := json.Marshal(map[string]interface{}{
"httpRequest": map[string]string{"path": "/users/1"},
"httpResponse": map[string]interface{}{"statusCode": 200, "generateFromSchema": string(schema)},
})
req, _ := http.NewRequest("PUT", "http://localhost:1080/mockserver/expectation", bytes.NewReader(payload))
req.Header.Set("Content-Type", "application/json")
http.DefaultClient.Do(req)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.When(
HttpRequest.Request().WithPath("/users/1")
).Respond(new HttpResponse
{
StatusCode = 200,
GenerateFromSchema =
"{\"type\":\"object\"," +
"\"required\":[\"id\",\"status\"]," +
"\"properties\":{" +
"\"id\":{\"type\":\"integer\"}," +
"\"status\":{\"type\":\"string\",\"enum\":[\"ACTIVE\",\"DISABLED\"]}," +
"\"tags\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}" +
"}}"
});
use mockserver_client::{ClientBuilder, HttpRequest, HttpResponse};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.when(HttpRequest::new().path("/users/1"))
.respond(
HttpResponse::new()
.status_code(200)
.generate_from_schema(
r#"{"type":"object","required":["id","status"],"properties":{"id":{"type":"integer"},"status":{"type":"string","enum":["ACTIVE","DISABLED"]},"tags":{"type":"array","items":{"type":"string"}}}}"#,
),
)
.unwrap();
// The PHP client's HttpResponse has no generateFromSchema setter, so submit the
// same expectation as raw JSON via the REST API.
$schema = json_encode([
'type' => 'object',
'required' => ['id', 'status'],
'properties' => [
'id' => ['type' => 'integer'],
'status' => ['type' => 'string', 'enum' => ['ACTIVE', 'DISABLED']],
'tags' => ['type' => 'array', 'items' => ['type' => 'string']],
],
]);
$ch = curl_init('http://localhost:1080/mockserver/expectation');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
CURLOPT_POSTFIELDS => json_encode([
'httpRequest' => ['path' => '/users/1'],
'httpResponse' => ['statusCode' => 200, 'generateFromSchema' => $schema],
]),
CURLOPT_RETURNTRANSFER => true,
]);
curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/expectation" -d '{
"httpRequest" : {
"path" : "/users/1"
},
"httpResponse" : {
"statusCode" : 200,
"generateFromSchema" : "{\"type\":\"object\",\"required\":[\"id\",\"status\"],\"properties\":{\"id\":{\"type\":\"integer\"},\"status\":{\"type\":\"string\",\"enum\":[\"ACTIVE\",\"DISABLED\"]},\"tags\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}}"
}
}'
See REST API for full JSON specification
MockServer supports open api expectations containing the following fields:
For each open api expectations MockServer creates multiple request matcher expectations as follows:
If an OpenAPI specification is submitted with operation filtering as follows:
{
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
"operationsAndResponses": {
"showPetById": "200",
"createPets": "500"
}
}
Then the following expectations are created:
{
"priority": 0,
"httpRequest": {
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
},
"httpResponse": {
"statusCode": 200,
"headers": {
"content-type": [
"application/json"
]
},
"body": {
"id": 0,
"name": "some_string_value",
"tag": "some_string_value"
}
},
"times": {
"unlimited": true
},
"timeToLive": {
"unlimited": true
}
}
{
"priority": 0,
"httpRequest": {
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "createPets"
},
"httpResponse": {
"statusCode": 500,
"headers": {
"content-type": [
"application/json"
]
},
"body": {
"code": 0,
"message": "some_string_value"
}
},
"times": {
"unlimited": true
},
"timeToLive": {
"unlimited": true
}
}
new MockServerClient("localhost", 1080)
.upsert(
openAPIExpectation(
"https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).openAPIExpectation({
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
}).then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver import MockServerClient, OpenAPIExpectation
client = MockServerClient("localhost", 1080)
client.open_api_expectation(OpenAPIExpectation(
spec_url_or_payload="https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
))
require 'mockserver-client'
include MockServer
client = MockServer::Client.new('localhost', 1080)
client.open_api_expectation(OpenAPIExpectation.new(
spec_url_or_payload: 'https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json'
))
import (
"bytes"
"net/http"
)
// Go client submits OpenAPI expectations as raw JSON via the REST API
body := []byte(`{
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
}`)
resp, err := http.DefaultClient.Do(
must(http.NewRequest("PUT", "http://localhost:1080/mockserver/openapi", bytes.NewReader(body))),
)
using System.Net.Http;
using System.Text;
// .NET client submits OpenAPI expectations as raw JSON via the REST API
using var httpClient = new HttpClient();
var json = @"{
""specUrlOrPayload"": ""https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json""
}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/openapi",
new StringContent(json, Encoding.UTF8, "application/json")
);
// Rust client submits OpenAPI expectations as raw JSON via the REST API
let client = reqwest::blocking::Client::new();
client.put("http://localhost:1080/mockserver/openapi")
.header("Content-Type", "application/json")
.body(r#"{
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
}"#)
.send()
.unwrap();
// PHP client submits OpenAPI expectations as raw JSON via the REST API
$ch = curl_init('http://localhost:1080/mockserver/openapi');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
CURLOPT_POSTFIELDS => json_encode([
'specUrlOrPayload' => 'https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/openapi" -d '{
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
}'
See REST API for full JSON specification
Map<String, String> operationsAndResponses = new HashMap<>();
operationsAndResponses.put("showPetById", "200");
operationsAndResponses.put("createPets", "500");
new MockServerClient("localhost", 1080)
.upsert(
openAPIExpectationWithStringResponses(
"https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
operationsAndResponses
)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).openAPIExpectation({
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
"operationsAndResponses": {
"showPetById": "200",
"createPets": "500"
}
}).then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver import MockServerClient, OpenAPIExpectation
client = MockServerClient("localhost", 1080)
client.open_api_expectation(OpenAPIExpectation(
spec_url_or_payload="https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
operations_and_responses={
"showPetById": "200",
"createPets": "500"
}
))
require 'mockserver-client'
include MockServer
client = MockServer::Client.new('localhost', 1080)
client.open_api_expectation(OpenAPIExpectation.new(
spec_url_or_payload: 'https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json',
operations_and_responses: {
'showPetById' => '200',
'createPets' => '500'
}
))
import (
"bytes"
"net/http"
)
// Go client submits OpenAPI expectations as raw JSON via the REST API
body := []byte(`{
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
"operationsAndResponses": {
"showPetById": "200",
"createPets": "500"
}
}`)
resp, err := http.DefaultClient.Do(
must(http.NewRequest("PUT", "http://localhost:1080/mockserver/openapi", bytes.NewReader(body))),
)
using System.Net.Http;
using System.Text;
// .NET client submits OpenAPI expectations as raw JSON via the REST API
using var httpClient = new HttpClient();
var json = @"{
""specUrlOrPayload"": ""https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"",
""operationsAndResponses"": {
""showPetById"": ""200"",
""createPets"": ""500""
}
}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/openapi",
new StringContent(json, Encoding.UTF8, "application/json")
);
// Rust client submits OpenAPI expectations as raw JSON via the REST API
let client = reqwest::blocking::Client::new();
client.put("http://localhost:1080/mockserver/openapi")
.header("Content-Type", "application/json")
.body(r#"{
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
"operationsAndResponses": {
"showPetById": "200",
"createPets": "500"
}
}"#)
.send()
.unwrap();
// PHP client submits OpenAPI expectations as raw JSON via the REST API
$ch = curl_init('http://localhost:1080/mockserver/openapi');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
CURLOPT_POSTFIELDS => json_encode([
'specUrlOrPayload' => 'https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json',
'operationsAndResponses' => [
'showPetById' => '200',
'createPets' => '500',
],
]),
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/openapi" -d '{
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
"operationsAndResponses": {
"showPetById": "200",
"createPets": "500"
}
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.upsert(
openAPIExpectation(
"file:/path/to/openapi_petstore_example.json"
)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).openAPIExpectation({
"specUrlOrPayload": "file:/path/to/openapi_petstore_example.json"
}).then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver import MockServerClient, OpenAPIExpectation
client = MockServerClient("localhost", 1080)
client.open_api_expectation(OpenAPIExpectation(
spec_url_or_payload="file:/path/to/openapi_petstore_example.json"
))
require 'mockserver-client'
include MockServer
client = MockServer::Client.new('localhost', 1080)
client.open_api_expectation(OpenAPIExpectation.new(
spec_url_or_payload: 'file:/path/to/openapi_petstore_example.json'
))
import (
"bytes"
"net/http"
)
body := []byte(`{
"specUrlOrPayload": "file:/path/to/openapi_petstore_example.json"
}`)
resp, err := http.DefaultClient.Do(
must(http.NewRequest("PUT", "http://localhost:1080/mockserver/openapi", bytes.NewReader(body))),
)
using System.Net.Http;
using System.Text;
using var httpClient = new HttpClient();
var json = @"{
""specUrlOrPayload"": ""file:/path/to/openapi_petstore_example.json""
}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/openapi",
new StringContent(json, Encoding.UTF8, "application/json")
);
let client = reqwest::blocking::Client::new();
client.put("http://localhost:1080/mockserver/openapi")
.header("Content-Type", "application/json")
.body(r#"{
"specUrlOrPayload": "file:/path/to/openapi_petstore_example.json"
}"#)
.send()
.unwrap();
$ch = curl_init('http://localhost:1080/mockserver/openapi');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
CURLOPT_POSTFIELDS => json_encode([
'specUrlOrPayload' => 'file:/path/to/openapi_petstore_example.json',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/openapi" -d '{
"specUrlOrPayload": "file:/path/to/openapi_petstore_example.json"
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.upsert(
openAPIExpectation("org/mockserver/openapi/openapi_petstore_example.json")
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).openAPIExpectation({
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json"
}).then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver import MockServerClient, OpenAPIExpectation
client = MockServerClient("localhost", 1080)
client.open_api_expectation(OpenAPIExpectation(
spec_url_or_payload="org/mockserver/openapi/openapi_petstore_example.json"
))
Note: classpath locations are resolved by the server-side JVM; the Python client sends the string as-is.
require 'mockserver-client'
include MockServer
client = MockServer::Client.new('localhost', 1080)
client.open_api_expectation(OpenAPIExpectation.new(
spec_url_or_payload: 'org/mockserver/openapi/openapi_petstore_example.json'
))
Note: classpath locations are resolved by the server-side JVM; the Ruby client sends the string as-is.
import (
"bytes"
"net/http"
)
// Classpath locations are resolved by the server-side JVM
body := []byte(`{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json"
}`)
resp, err := http.DefaultClient.Do(
must(http.NewRequest("PUT", "http://localhost:1080/mockserver/openapi", bytes.NewReader(body))),
)
using System.Net.Http;
using System.Text;
// Classpath locations are resolved by the server-side JVM
using var httpClient = new HttpClient();
var json = @"{
""specUrlOrPayload"": ""org/mockserver/openapi/openapi_petstore_example.json""
}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/openapi",
new StringContent(json, Encoding.UTF8, "application/json")
);
// Classpath locations are resolved by the server-side JVM
let client = reqwest::blocking::Client::new();
client.put("http://localhost:1080/mockserver/openapi")
.header("Content-Type", "application/json")
.body(r#"{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json"
}"#)
.send()
.unwrap();
// Classpath locations are resolved by the server-side JVM; the PHP client sends the string as-is
$ch = curl_init('http://localhost:1080/mockserver/openapi');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
CURLOPT_POSTFIELDS => json_encode([
'specUrlOrPayload' => 'org/mockserver/openapi/openapi_petstore_example.json',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($ch);
curl_close($ch);
Note: classpath locations are resolved by the server-side JVM; the PHP client sends the string as-is.
curl -v -X PUT "http://localhost:1080/mockserver/openapi" -d '{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json"
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.upsert(
openAPIExpectation(FileReader.readFileFromClassPathOrPath("org/mockserver/openapi/openapi_petstore_example.json"))
);
var fs = require('fs');
try {
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).openAPIExpectation({
"specUrlOrPayload": fs.readFileSync("/path/to/openapi_petstore_example.json", "utf8")
}).then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
} catch (e) {
console.log('Error:', e.stack);
}
See REST API for full JSON specification
import json
from mockserver import MockServerClient, OpenAPIExpectation
with open("/path/to/openapi_petstore_example.json") as f:
spec_content = f.read()
client = MockServerClient("localhost", 1080)
client.open_api_expectation(OpenAPIExpectation(
spec_url_or_payload=spec_content
))
require 'mockserver-client'
include MockServer
spec_content = File.read('/path/to/openapi_petstore_example.json')
client = MockServer::Client.new('localhost', 1080)
client.open_api_expectation(OpenAPIExpectation.new(
spec_url_or_payload: spec_content
))
import (
"bytes"
"encoding/json"
"net/http"
"os"
)
specContent, err := os.ReadFile("/path/to/openapi_petstore_example.json")
if err != nil {
log.Fatal(err)
}
payload, _ := json.Marshal(map[string]string{
"specUrlOrPayload": string(specContent),
})
resp, err := http.DefaultClient.Do(
must(http.NewRequest("PUT", "http://localhost:1080/mockserver/openapi", bytes.NewReader(payload))),
)
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
var specContent = File.ReadAllText("/path/to/openapi_petstore_example.json");
var payload = JsonSerializer.Serialize(new { specUrlOrPayload = specContent });
using var httpClient = new HttpClient();
await httpClient.PutAsync(
"http://localhost:1080/mockserver/openapi",
new StringContent(payload, Encoding.UTF8, "application/json")
);
use std::fs;
let spec_content = fs::read_to_string("/path/to/openapi_petstore_example.json").unwrap();
let payload = serde_json::json!({ "specUrlOrPayload": spec_content });
let client = reqwest::blocking::Client::new();
client.put("http://localhost:1080/mockserver/openapi")
.header("Content-Type", "application/json")
.json(&payload)
.send()
.unwrap();
$specContent = file_get_contents('/path/to/openapi_petstore_example.json');
$ch = curl_init('http://localhost:1080/mockserver/openapi');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
CURLOPT_POSTFIELDS => json_encode([
'specUrlOrPayload' => $specContent,
]),
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/openapi" -d "{
\"specUrlOrPayload\": `cat /path/to/openapi_petstore_example.json`
}"
See REST API for full JSON specification
The spec payload can be supplied inline as a YAML string instead of JSON — the client call is identical to the inline JSON specification above; only the spec string changes from JSON to YAML. The clients that expose a typed OpenAPI method (Java, JavaScript, Python, Ruby) pass the YAML directly as specUrlOrPayload; the remaining clients submit the same YAML as raw JSON via the PUT /mockserver/openapi REST endpoint.
new MockServerClient("localhost", 1080)
.upsert(
openAPIExpectation("---\n" +
"openapi: 3.0.0\n" +
"info:\n" +
" version: 1.0.0\n" +
" title: Swagger Petstore\n" +
"servers:\n" +
" - url: http://petstore.swagger.io/v1\n" +
"paths:\n" +
" /pets:\n" +
" get:\n" +
" summary: List all pets\n" +
" operationId: listPets\n" +
" responses:\n" +
" '200':\n" +
" description: A paged array of pets\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/Pets'\n" +
"components:\n" +
" schemas:\n" +
" Pet:\n" +
" type: object\n" +
" required:\n" +
" - id\n" +
" - name\n" +
" properties:\n" +
" id:\n" +
" type: integer\n" +
" format: int64\n" +
" name:\n" +
" type: string\n" +
" Pets:\n" +
" type: array\n" +
" items:\n" +
" $ref: '#/components/schemas/Pet'\n")
);
var mockServerClient = require('mockserver-client').mockServerClient;
var spec = `---
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
`;
mockServerClient("localhost", 1080).openAPIExpectation({
"specUrlOrPayload": spec
}).then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver import MockServerClient, OpenAPIExpectation
spec = """---
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
"""
client = MockServerClient("localhost", 1080)
client.open_api_expectation(OpenAPIExpectation(
spec_url_or_payload=spec
))
require 'mockserver-client'
include MockServer
spec = <<~YAML
---
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
YAML
client = MockServer::Client.new('localhost', 1080)
client.open_api_expectation(OpenAPIExpectation.new(
spec_url_or_payload: spec
))
import (
"bytes"
"encoding/json"
"net/http"
)
// Go client submits the inline YAML spec as raw JSON via the REST API
spec := `---
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
`
payload, _ := json.Marshal(map[string]string{
"specUrlOrPayload": spec,
})
resp, err := http.DefaultClient.Do(
must(http.NewRequest("PUT", "http://localhost:1080/mockserver/openapi", bytes.NewReader(payload))),
)
using System.Net.Http;
using System.Text;
using System.Text.Json;
// .NET client submits the inline YAML spec as raw JSON via the REST API
var spec = @"---
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
";
var payload = JsonSerializer.Serialize(new { specUrlOrPayload = spec });
using var httpClient = new HttpClient();
await httpClient.PutAsync(
"http://localhost:1080/mockserver/openapi",
new StringContent(payload, Encoding.UTF8, "application/json")
);
// Rust client submits the inline YAML spec as raw JSON via the REST API
let spec = r#"---
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
"#;
let payload = serde_json::json!({ "specUrlOrPayload": spec });
let client = reqwest::blocking::Client::new();
client.put("http://localhost:1080/mockserver/openapi")
.header("Content-Type", "application/json")
.json(&payload)
.send()
.unwrap();
// PHP client submits the inline YAML spec as raw JSON via the REST API
$spec = <<<YAML
---
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
\$ref: '#/components/schemas/Pets'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Pets:
type: array
items:
\$ref: '#/components/schemas/Pet'
YAML;
$ch = curl_init('http://localhost:1080/mockserver/openapi');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
CURLOPT_POSTFIELDS => json_encode([
'specUrlOrPayload' => $spec,
]),
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/openapi" -d '{
"specUrlOrPayload": "---\nopenapi: 3.0.0\ninfo:\n version: 1.0.0\n title: Swagger Petstore\nservers:\n - url: http://petstore.swagger.io/v1\npaths:\n /pets:\n get:\n summary: List all pets\n operationId: listPets\n responses:\n '\''200'\'':\n description: A paged array of pets\n content:\n application/json:\n schema:\n $ref: '\''#/components/schemas/Pets'\''\ncomponents:\n schemas:\n Pet:\n type: object\n required:\n - id\n - name\n properties:\n id:\n type: integer\n format: int64\n name:\n type: string\n Pets:\n type: array\n items:\n $ref: '\''#/components/schemas/Pet'\''\n"
}'
See REST API for full JSON specification
For the complete Petstore specification used by the examples on this page, see openapi_petstore_example.json in the MockServer repository.
Calling PUT /mockserver/openapi with a spec you have already imported is safe and idempotent. MockServer performs an incremental sync rather than duplicating expectations:
Incremental sync is scoped by spec identity. MockServer assigns each OpenAPI-generated expectation a stable id of the form openapi:<specKey>:<operationId>, where specKey is derived from the spec title (lowercased, non-alphanumeric characters replaced with _) or, when no title is present, from an 8-character hash of the spec URL or payload. Re-importing a spec with the same title updates exactly those expectations; importing a differently titled spec creates a separate namespace of expectations and does not affect the first.
This means you can safely call PUT /mockserver/openapi on every test run or CI build — you will always end up with a consistent set of mock expectations matching the current spec, with no stale duplicates.
MockServer can run an OpenAPI specification as a set of contract tests against a real, running service. For each operation in the spec, MockServer builds a representative example request (using path, query, header, and body examples from the spec), sends it to the target service, and validates the response against the spec. This is useful for confirming that a deployed service still conforms to the contract its consumers rely on.
Submit the request to the PUT /mockserver/contractTest endpoint with a JSON body containing:
Example request body:
{
"spec": "https://petstore.swagger.io/v2/swagger.json",
"baseUrl": "http://localhost:8080",
"operationId": "listPets"
}
MockServer returns HTTP 200 with a structured pass/fail-per-operation report:
{
"baseUrl": "http://localhost:8080",
"totalOperations": 3,
"passed": 2,
"failed": 1,
"allPassed": false,
"results": [
{
"operationId": "listPets",
"method": "get",
"path": "/pets",
"statusCodeReceived": 200,
"passed": true,
"validationErrors": []
},
{
"operationId": "showPetById",
"method": "get",
"path": "/pets/{petId}",
"statusCodeReceived": 200,
"passed": false,
"validationErrors": ["Object instance has properties which are not allowed by the schema: [\"extra\"]"]
}
]
}
Each result reports the operation tested, the status code received, whether the response conformed to the spec, and any validation errors. The target host is subject to the same SSRF protection as the forward and replay paths — see forwardProxyBlockPrivateNetworks.
When an OpenAPI specification includes callbacks on an operation, MockServer automatically generates webhook expectations that send HTTP requests to the callback URLs after the main response is returned. This allows you to simulate webhook-style interactions where an API notifies the client asynchronously after processing a request.
The callback URL, method, and request body are derived from the OpenAPI callback definition. OpenAPI runtime expressions (such as {$request.body#/callbackUrl}) are resolved at callback fire-time using values from the triggering request. Supported expressions:
{$request.body#/<json-pointer>} — extracts a value from the triggering request body using a JSON Pointer{$request.query.<name>} — query parameter value from the triggering request{$request.header.<name>} — header value from the triggering request{$request.path.<name>} — path parameter value (best-effort){$request.method} — HTTP method of the triggering request{$url} — reconstructed URL of the triggering requestExpressions that cannot be resolved (unknown format, missing values) are replaced with an empty string. Response-based expressions ({$response.body#/...}) are not currently supported because the response is not available at after-action dispatch time.
For example, given the following OpenAPI specification with a callback:
paths:
/subscribe:
post:
operationId: createSubscription
requestBody:
content:
application/json:
schema:
type: object
properties:
callbackUrl:
type: string
format: uri
responses:
'201':
description: Subscription created
content:
application/json:
schema:
type: object
properties:
id:
type: string
callbacks:
onEvent:
'{$request.body#/callbackUrl}':
post:
requestBody:
content:
application/json:
schema:
type: object
properties:
event:
type: string
subscriptionId:
type: string
responses:
'200':
description: Callback acknowledged
MockServer will create:
POST /subscribe that returns a 201 response with an auto-generated bodyPOST request to the callback URL with an auto-generated request body based on the callback schemaThis feature works automatically when loading OpenAPI specifications via any method (REST API, Java client, initializer file, or classpath). No additional configuration is required.
MockServer supports WSDL 1.1 documents for generating SOAP mock expectations. Submitting a WSDL to the PUT /mockserver/wsdl endpoint causes MockServer to create one expectation per SOAP operation found across all service/port bindings in the document.
Both SOAP 1.1 and SOAP 1.2 bindings are supported. Each generated expectation:
The WSDL document is parsed with XXE protections (DOCTYPE and external entity resolution disabled), so importing an untrusted WSDL cannot trigger an XML External Entity (XXE) attack.
Unlike OpenAPI, WSDL import has no dedicated typed client method — all language clients submit the raw WSDL XML directly to the REST endpoint PUT /mockserver/wsdl. MockServer returns HTTP 201 with the created expectations as JSON.
For example, given this minimal WSDL for a WeatherService:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather"
name="WeatherService">
<message name="GetWeatherRequest"/>
<message name="GetWeatherResponse"/>
<portType name="WeatherPortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherBinding" type="tns:WeatherPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/GetWeather"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="tns:WeatherBinding">
<soap:address location="http://localhost/ws/weather"/>
</port>
</service>
</definitions>
MockServer generates an expectation that matches POST /ws/weather with SOAPAction: "http://example.com/GetWeather" and returns a skeleton SOAP response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tns="http://example.com/weather">
<soapenv:Body>
<tns:GetWeatherResponse/>
</soapenv:Body>
</soapenv:Envelope>
// The Java client has no dedicated WSDL method; use an HTTP client to call the REST endpoint directly
import java.nio.file.Files;
import java.nio.file.Paths;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
byte[] wsdlBytes = Files.readAllBytes(Paths.get("/path/to/my-service.wsdl"));
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:1080/mockserver/wsdl"))
.header("Content-Type", "text/xml")
.PUT(HttpRequest.BodyPublishers.ofByteArray(wsdlBytes))
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// response.statusCode() == 201; response.body() contains the generated expectations as JSON
const fs = require('fs');
const fetch = require('node-fetch'); // or use the built-in fetch in Node 18+
const wsdl = fs.readFileSync('/path/to/my-service.wsdl', 'utf8');
const response = await fetch('http://localhost:1080/mockserver/wsdl', {
method: 'PUT',
headers: { 'Content-Type': 'text/xml' },
body: wsdl,
});
// response.status === 201; response.json() returns the generated expectations
import requests
with open('/path/to/my-service.wsdl', 'rb') as f:
wsdl = f.read()
response = requests.put(
'http://localhost:1080/mockserver/wsdl',
data=wsdl,
headers={'Content-Type': 'text/xml'},
)
# response.status_code == 201; response.json() returns the generated expectations
require 'net/http'
wsdl = File.read('/path/to/my-service.wsdl')
uri = URI('http://localhost:1080/mockserver/wsdl')
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Put.new(uri.path, 'Content-Type' => 'text/xml')
request.body = wsdl
response = http.request(request)
# response.code == '201'; JSON.parse(response.body) returns the generated expectations
import (
"bytes"
"net/http"
"os"
)
wsdl, err := os.ReadFile("/path/to/my-service.wsdl")
if err != nil {
log.Fatal(err)
}
req, _ := http.NewRequest("PUT", "http://localhost:1080/mockserver/wsdl", bytes.NewReader(wsdl))
req.Header.Set("Content-Type", "text/xml")
resp, err := http.DefaultClient.Do(req)
// resp.StatusCode == 201; decode resp.Body as JSON to read the generated expectations
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
var wsdl = File.ReadAllBytes("/path/to/my-service.wsdl");
using var httpClient = new HttpClient();
var content = new ByteArrayContent(wsdl);
content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
var response = await httpClient.PutAsync("http://localhost:1080/mockserver/wsdl", content);
// response.StatusCode == HttpStatusCode.Created (201)
// await response.Content.ReadAsStringAsync() returns the generated expectations as JSON
let wsdl = std::fs::read("/path/to/my-service.wsdl").unwrap();
let client = reqwest::blocking::Client::new();
let response = client.put("http://localhost:1080/mockserver/wsdl")
.header("Content-Type", "text/xml")
.body(wsdl)
.send()
.unwrap();
// response.status() == 201; response.text() contains the generated expectations as JSON
$wsdl = file_get_contents('/path/to/my-service.wsdl');
$ch = curl_init('http://localhost:1080/mockserver/wsdl');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Content-Type: text/xml'],
CURLOPT_POSTFIELDS => $wsdl,
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
// $info['http_code'] == 201; $result contains the generated expectations as JSON
curl -v -X PUT "http://localhost:1080/mockserver/wsdl" \
-H "Content-Type: text/xml" \
--data-binary @my-service.wsdl
The request body must be a raw WSDL 1.1 XML document. MockServer returns 201 Created with the generated expectations as JSON.
Each client exposes a typed wsdlExpectation(wsdl) method (wsdl_expectation in Python and Ruby, WsdlExpectation in Go and .NET) that takes the WSDL XML, submits it to the PUT /mockserver/wsdl endpoint with Content-Type: text/xml, and returns the generated (upserted) expectations. The only difference from the WSDL file example above is that the WSDL is held as an inline string rather than read from a file.
import org.mockserver.client.MockServerClient;
import org.mockserver.mock.Expectation;
String wsdl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<definitions xmlns=\"http://schemas.xmlsoap.org/wsdl/\"\n"
+ " xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"\n"
+ " xmlns:tns=\"http://example.com/weather\"\n"
+ " targetNamespace=\"http://example.com/weather\"\n"
+ " name=\"WeatherService\">\n"
+ " <message name=\"GetWeatherRequest\"/>\n"
+ " <message name=\"GetWeatherResponse\"/>\n"
+ " <portType name=\"WeatherPortType\">\n"
+ " <operation name=\"GetWeather\">\n"
+ " <input message=\"tns:GetWeatherRequest\"/>\n"
+ " <output message=\"tns:GetWeatherResponse\"/>\n"
+ " </operation>\n"
+ " </portType>\n"
+ " <binding name=\"WeatherBinding\" type=\"tns:WeatherPortType\">\n"
+ " <soap:binding style=\"document\" transport=\"http://schemas.xmlsoap.org/soap/http\"/>\n"
+ " <operation name=\"GetWeather\">\n"
+ " <soap:operation soapAction=\"http://example.com/GetWeather\"/>\n"
+ " <input><soap:body use=\"literal\"/></input>\n"
+ " <output><soap:body use=\"literal\"/></output>\n"
+ " </operation>\n"
+ " </binding>\n"
+ " <service name=\"WeatherService\">\n"
+ " <port name=\"WeatherPort\" binding=\"tns:WeatherBinding\">\n"
+ " <soap:address location=\"http://localhost/ws/weather\"/>\n"
+ " </port>\n"
+ " </service>\n"
+ "</definitions>";
Expectation[] expectations = new MockServerClient("localhost", 1080)
.wsdlExpectation(wsdl);
// expectations contains the generated (upserted) expectations
var mockServerClient = require('mockserver-client').mockServerClient;
const wsdl = `<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather"
name="WeatherService">
<message name="GetWeatherRequest"/>
<message name="GetWeatherResponse"/>
<portType name="WeatherPortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherBinding" type="tns:WeatherPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/GetWeather"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="tns:WeatherBinding">
<soap:address location="http://localhost/ws/weather"/>
</port>
</service>
</definitions>`;
mockServerClient("localhost", 1080)
.wsdlExpectation(wsdl)
.then(function (expectations) {
console.log("created " + expectations.length + " expectations");
});
from mockserver.client import MockServerClient
wsdl = """<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather"
name="WeatherService">
<message name="GetWeatherRequest"/>
<message name="GetWeatherResponse"/>
<portType name="WeatherPortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherBinding" type="tns:WeatherPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/GetWeather"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="tns:WeatherBinding">
<soap:address location="http://localhost/ws/weather"/>
</port>
</service>
</definitions>"""
client = MockServerClient("localhost", 1080)
expectations = client.wsdl_expectation(wsdl)
# expectations is the list of generated (upserted) expectations
require 'mockserver-client'
wsdl = <<~XML
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather"
name="WeatherService">
<message name="GetWeatherRequest"/>
<message name="GetWeatherResponse"/>
<portType name="WeatherPortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherBinding" type="tns:WeatherPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/GetWeather"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="tns:WeatherBinding">
<soap:address location="http://localhost/ws/weather"/>
</port>
</service>
</definitions>
XML
client = MockServer::Client.new('localhost', 1080)
expectations = client.wsdl_expectation(wsdl)
# expectations is the array of generated (upserted) expectations
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"
wsdl := `<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather"
name="WeatherService">
<message name="GetWeatherRequest"/>
<message name="GetWeatherResponse"/>
<portType name="WeatherPortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherBinding" type="tns:WeatherPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/GetWeather"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="tns:WeatherBinding">
<soap:address location="http://localhost/ws/weather"/>
</port>
</service>
</definitions>`
client := mockserver.New("localhost", 1080)
expectations, err := client.WsdlExpectation(wsdl)
// expectations holds the generated (upserted) expectations
using MockServer.Client;
using MockServer.Client.Models;
var wsdl = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<definitions xmlns=""http://schemas.xmlsoap.org/wsdl/""
xmlns:soap=""http://schemas.xmlsoap.org/wsdl/soap/""
xmlns:tns=""http://example.com/weather""
targetNamespace=""http://example.com/weather""
name=""WeatherService"">
<message name=""GetWeatherRequest""/>
<message name=""GetWeatherResponse""/>
<portType name=""WeatherPortType"">
<operation name=""GetWeather"">
<input message=""tns:GetWeatherRequest""/>
<output message=""tns:GetWeatherResponse""/>
</operation>
</portType>
<binding name=""WeatherBinding"" type=""tns:WeatherPortType"">
<soap:binding style=""document"" transport=""http://schemas.xmlsoap.org/soap/http""/>
<operation name=""GetWeather"">
<soap:operation soapAction=""http://example.com/GetWeather""/>
<input><soap:body use=""literal""/></input>
<output><soap:body use=""literal""/></output>
</operation>
</binding>
<service name=""WeatherService"">
<port name=""WeatherPort"" binding=""tns:WeatherBinding"">
<soap:address location=""http://localhost/ws/weather""/>
</port>
</service>
</definitions>";
using var client = new MockServerClient("localhost", 1080);
var expectations = client.WsdlExpectation(wsdl);
// expectations is the List<Expectation> of generated (upserted) expectations
use mockserver_client::ClientBuilder;
let wsdl = r#"<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather"
name="WeatherService">
<message name="GetWeatherRequest"/>
<message name="GetWeatherResponse"/>
<portType name="WeatherPortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherBinding" type="tns:WeatherPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/GetWeather"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="tns:WeatherBinding">
<soap:address location="http://localhost/ws/weather"/>
</port>
</service>
</definitions>"#;
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let expectations = client.wsdl_expectation(wsdl).unwrap();
// expectations is the Vec<Expectation> of generated (upserted) expectations
use MockServer\MockServerClient;
$wsdl = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather"
name="WeatherService">
<message name="GetWeatherRequest"/>
<message name="GetWeatherResponse"/>
<portType name="WeatherPortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherBinding" type="tns:WeatherPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/GetWeather"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="tns:WeatherBinding">
<soap:address location="http://localhost/ws/weather"/>
</port>
</service>
</definitions>
XML;
$client = new MockServerClient('localhost', 1080);
$expectations = $client->wsdlExpectation($wsdl);
// $expectations is the array of generated (upserted) expectations
curl -v -X PUT "http://localhost:1080/mockserver/wsdl" \
-H "Content-Type: text/xml" \
-d '<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather"
name="WeatherService">
...
</definitions>'
Pass the full WSDL XML as the request body with Content-Type: text/xml.