Swagger implementation #415

Closed
opened 2025-12-29 08:27:42 +01:00 by adam · 38 comments
Owner

Originally created by @devmariodiaz on GitHub (Apr 8, 2022).

Hello Stef,

Long time no see you :D, hoping you are doing well,

I have a question for you:

Is there any way to implement Swagger into a WireMock.Net project? It's not for Admin, is for mocked apis.

Originally created by @devmariodiaz on GitHub (Apr 8, 2022). Hello Stef, Long time no see you :D, hoping you are doing well, I have a question for you: Is there any way to implement Swagger into a WireMock.Net project? It's not for Admin, is for mocked apis.
adam added the question label 2025-12-29 08:27:42 +01:00
adam closed this issue 2025-12-29 08:27:42 +01:00
Author
Owner

@StefH commented on GitHub (Apr 11, 2022):

A Swagger API contains two things:

  1. UI
  2. a download from a json file which describes the swagger for an API

All calls can be mocked by WireMock.Net, however for option 1 you probably need to capture some data using the Proxy mode because you need css, html and so on.

Option 2 is just easy : return a json as body.

@StefH commented on GitHub (Apr 11, 2022): A Swagger API contains two things: 1. UI 2. a download from a json file which describes the swagger for an API All calls can be mocked by WireMock.Net, however for option 1 you probably need to capture some data using the Proxy mode because you need css, html and so on. Option 2 is just easy : return a json as body.
Author
Owner

@StefH commented on GitHub (Apr 13, 2022):

@devmariodiaz is this clear?

@StefH commented on GitHub (Apr 13, 2022): @devmariodiaz is this clear?
Author
Owner

@devmariodiaz commented on GitHub (Apr 18, 2022):

Hello Stef,

Hoping you are doing well,

We really need is that for example, WireMock be able to read all mocked endpoints and expose those endpoints in his user interface to be shown to the users.

@devmariodiaz commented on GitHub (Apr 18, 2022): Hello Stef, Hoping you are doing well, We really need is that for example, WireMock be able to read all mocked endpoints and expose those endpoints in his user interface to be shown to the users.
Author
Owner

@StefH commented on GitHub (Apr 19, 2022):

Hello @devmariodiaz,

I understand your question now. I'll take a look, however this will take some time to implement.

@StefH commented on GitHub (Apr 19, 2022): Hello @devmariodiaz, I understand your question now. I'll take a look, however this will take some time to implement.
Author
Owner

@StefH commented on GitHub (Apr 23, 2022):

@devmariodiaz
I've created an initial version which returns a 3.0 swagger file at /_admin/mappings/swagger.

Please test preview version 1.4.41-ci-16049 and let me know if you find any bugs or issues.

@StefH commented on GitHub (Apr 23, 2022): @devmariodiaz I've created an initial version which returns a 3.0 swagger file at `/_admin/mappings/swagger`. Please test preview version `1.4.41-ci-16049` and let me know if you find any bugs or issues.
Author
Owner

@devmariodiaz commented on GitHub (Apr 24, 2022):

Great to hear from you that, great news, I’ll test ASAP and I’ll get back
to you

Thanks a lot stef

On Sat, 23 Apr 2022 at 5:36 AM Stef Heyenrath @.***>
wrote:

@devmariodiaz https://github.com/devmariodiaz
I've created an initial version which returns a 3.0 swagger file at
/_admin/mappings/swagger.

Please test preview version 1.4.41-ci-16049 and let me know if you find
any bugs or issues.


Reply to this email directly, view it on GitHub
https://github.com/WireMock-Net/WireMock.Net/issues/745#issuecomment-1107449658,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ANAU3WZJXFV5742UM3YC5ALVGPHCPANCNFSM5S2Z367Q
.
You are receiving this because you were mentioned.Message ID:
@.***>

@devmariodiaz commented on GitHub (Apr 24, 2022): Great to hear from you that, great news, I’ll test ASAP and I’ll get back to you Thanks a lot stef On Sat, 23 Apr 2022 at 5:36 AM Stef Heyenrath ***@***.***> wrote: > @devmariodiaz <https://github.com/devmariodiaz> > I've created an initial version which returns a 3.0 swagger file at > /_admin/mappings/swagger. > > Please test preview version 1.4.41-ci-16049 and let me know if you find > any bugs or issues. > > — > Reply to this email directly, view it on GitHub > <https://github.com/WireMock-Net/WireMock.Net/issues/745#issuecomment-1107449658>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ANAU3WZJXFV5742UM3YC5ALVGPHCPANCNFSM5S2Z367Q> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> >
Author
Owner

@devmariodiaz commented on GitHub (Apr 26, 2022):

@brunotarghetta @leolplex please bear in mind to test this new feature using swagger 🥇

@devmariodiaz commented on GitHub (Apr 26, 2022): @brunotarghetta @leolplex please bear in mind to test this new feature using swagger 🥇
Author
Owner

@StefH commented on GitHub (Apr 28, 2022):

@devmariodiaz @brunotarghetta @leolplex
Did you have time to test this functionality?

@StefH commented on GitHub (Apr 28, 2022): @devmariodiaz @brunotarghetta @leolplex Did you have time to test this functionality?
Author
Owner

@leolplex commented on GitHub (Apr 29, 2022):

@StefH I've been testing this feature and I found a issue.

I ran the next code:

static void Main(string[] args)
{

    var server = WireMockServer.Start(new WireMockServerSettings
    {
        StartAdminInterface = true,
        ReadStaticMappings = true,
        WatchStaticMappings = true,
        Port = 8080
    });
    var settings = new WireMockOpenApiParserSettings
    {
        NumberOfArrayItems = 1
    };

    server.WithMappingFromOpenApiFile("testopenapifile.json", settings, out var d);


    Console.WriteLine("Press any key to stop the server");
    Console.Read();
}

testopenapifile.json:

{
	"openapi": "3.0.2",
	"info": {
		"title": "Swagger Petstore - OpenAPI 3.0",
		"description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) ",
		"termsOfService": "http://swagger.io/terms/",
		"contact": { "email": "apiteam@swagger.io" },
		"license": {
			"name": "Apache 2.0",
			"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
		},
		"version": "1.0.4"
	},
	"externalDocs": {
		"description": "Find out more about Swagger",
		"url": "http://swagger.io"
	},
	"servers": [ { "url": "/api/v3" } ],
	"tags": [
		{
			"name": "pet",
			"description": "Everything about your Pets",
			"externalDocs": {
				"description": "Find out more",
				"url": "http://swagger.io"
			}
		},
		{
			"name": "store",
			"description": "Operations about user"
		},
		{
			"name": "user",
			"description": "Access to Petstore orders",
			"externalDocs": {
				"description": "Find out more about our store",
				"url": "http://swagger.io"
			}
		}
	],
	"paths": {
		"/pet": {
			"put": {
				"tags": [ "pet" ],
				"summary": "Update an existing pet",
				"description": "Update an existing pet by Id",
				"operationId": "updatePet",
				"requestBody": {
					"description": "Update an existent pet in the store",
					"content": {
						"application/json": { "schema": { "$ref": "#/components/schemas/Pet" } },
						"application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } },
						"application/x-www-form-urlencoded": { "schema": { "$ref": "#/components/schemas/Pet" } }
					},
					"required": true
				},
				"responses": {
					"200": {
						"description": "Successful operation",
						"content": {
							"application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } },
							"application/json": { "schema": { "$ref": "#/components/schemas/Pet" } }
						}
					},
					"400": { "description": "Invalid ID supplied" },
					"404": { "description": "Pet not found" },
					"405": { "description": "Validation exception" }
				},
				"security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ]
			}
		}
	},
	"components": {
		"schemas": {
			"Category": {
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"format": "int64",
						"example": 1
					},
					"name": {
						"type": "string",
						"example": "Dogs"
					}
				},
				"xml": { "name": "category" }
			},
			"Tag": {
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"format": "int64"
					},
					"name": { "type": "string" }
				},
				"xml": { "name": "tag" }
			},
			"Pet": {
				"required": [ "name", "photoUrls" ],
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"format": "int64",
						"example": 10
					},
					"name": {
						"type": "string",
						"example": "doggie"
					},
					"category": { "$ref": "#/components/schemas/Category" },
					"photoUrls": {
						"type": "array",
						"xml": { "wrapped": true },
						"items": {
							"type": "string",
							"xml": { "name": "photoUrl" }
						}
					},
					"tags": {
						"type": "array",
						"xml": { "wrapped": true },
						"items": { "$ref": "#/components/schemas/Tag" }
					},
					"status": {
						"type": "string",
						"description": "pet status in the store",
						"enum": [ "available", "pending", "sold" ]
					}
				},
				"xml": { "name": "pet" }
			},
			"ApiResponse": {
				"type": "object",
				"properties": {
					"code": {
						"type": "integer",
						"format": "int32"
					},
					"type": { "type": "string" },
					"message": { "type": "string" }
				},
				"xml": { "name": "##default" }
			}
		}
	}
}

__admin/mappings:

 {
    "Guid": "ce56ccc6-c921-47eb-b164-28ee541b02aa",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/api/v3/pet",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "PUT"
      ],
      "Body": {
        "Matcher": {
          "Name": "JsonMatcher",
          "Pattern": "{\n  \"id\": 10,\n  \"name\": \"doggie\",\n  \"category\": {\n    \"id\": 1,\n    \"name\": \"Dogs\"\n  },\n  \"photoUrls\": [\n    \"example-string\"\n  ],\n  \"tags\": [\n    {\n      \"id\": 42,\n      \"name\": \"example-string\"\n    }\n  ],\n  \"status\": \"available\"\n}",
          "IgnoreCase": true
        }
      }
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "id": 10,
        "name": "doggie",
        "category": {
          "id": 1,
          "name": "Dogs"
        },
        "photoUrls": [
          "example-string"
        ],
        "tags": [
          {
            "id": 42,
            "name": "example-string"
          }
        ],
        "status": "pending"
      },
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }

__admin/mappings/swagger:

   "/api/v3/pet": {
      "put": {
        "operationId": "petPUT",
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      },
      "post": {
        "operationId": "petPOST",
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      }
    }

The issue here is the request body it is not mapped in the swagger output.

@leolplex commented on GitHub (Apr 29, 2022): @StefH I've been testing this feature and I found a issue. I ran the next code: ```c# static void Main(string[] args) { var server = WireMockServer.Start(new WireMockServerSettings { StartAdminInterface = true, ReadStaticMappings = true, WatchStaticMappings = true, Port = 8080 }); var settings = new WireMockOpenApiParserSettings { NumberOfArrayItems = 1 }; server.WithMappingFromOpenApiFile("testopenapifile.json", settings, out var d); Console.WriteLine("Press any key to stop the server"); Console.Read(); } ``` **testopenapifile.json:** ``` json { "openapi": "3.0.2", "info": { "title": "Swagger Petstore - OpenAPI 3.0", "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) ", "termsOfService": "http://swagger.io/terms/", "contact": { "email": "apiteam@swagger.io" }, "license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.html" }, "version": "1.0.4" }, "externalDocs": { "description": "Find out more about Swagger", "url": "http://swagger.io" }, "servers": [ { "url": "/api/v3" } ], "tags": [ { "name": "pet", "description": "Everything about your Pets", "externalDocs": { "description": "Find out more", "url": "http://swagger.io" } }, { "name": "store", "description": "Operations about user" }, { "name": "user", "description": "Access to Petstore orders", "externalDocs": { "description": "Find out more about our store", "url": "http://swagger.io" } } ], "paths": { "/pet": { "put": { "tags": [ "pet" ], "summary": "Update an existing pet", "description": "Update an existing pet by Id", "operationId": "updatePet", "requestBody": { "description": "Update an existent pet in the store", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/x-www-form-urlencoded": { "schema": { "$ref": "#/components/schemas/Pet" } } }, "required": true }, "responses": { "200": { "description": "Successful operation", "content": { "application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/json": { "schema": { "$ref": "#/components/schemas/Pet" } } } }, "400": { "description": "Invalid ID supplied" }, "404": { "description": "Pet not found" }, "405": { "description": "Validation exception" } }, "security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ] } } }, "components": { "schemas": { "Category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64", "example": 1 }, "name": { "type": "string", "example": "Dogs" } }, "xml": { "name": "category" } }, "Tag": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } }, "xml": { "name": "tag" } }, "Pet": { "required": [ "name", "photoUrls" ], "type": "object", "properties": { "id": { "type": "integer", "format": "int64", "example": 10 }, "name": { "type": "string", "example": "doggie" }, "category": { "$ref": "#/components/schemas/Category" }, "photoUrls": { "type": "array", "xml": { "wrapped": true }, "items": { "type": "string", "xml": { "name": "photoUrl" } } }, "tags": { "type": "array", "xml": { "wrapped": true }, "items": { "$ref": "#/components/schemas/Tag" } }, "status": { "type": "string", "description": "pet status in the store", "enum": [ "available", "pending", "sold" ] } }, "xml": { "name": "pet" } }, "ApiResponse": { "type": "object", "properties": { "code": { "type": "integer", "format": "int32" }, "type": { "type": "string" }, "message": { "type": "string" } }, "xml": { "name": "##default" } } } } } ``` **__admin/mappings:** ``` json { "Guid": "ce56ccc6-c921-47eb-b164-28ee541b02aa", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/api/v3/pet", "IgnoreCase": false } ] }, "Methods": [ "PUT" ], "Body": { "Matcher": { "Name": "JsonMatcher", "Pattern": "{\n \"id\": 10,\n \"name\": \"doggie\",\n \"category\": {\n \"id\": 1,\n \"name\": \"Dogs\"\n },\n \"photoUrls\": [\n \"example-string\"\n ],\n \"tags\": [\n {\n \"id\": 42,\n \"name\": \"example-string\"\n }\n ],\n \"status\": \"available\"\n}", "IgnoreCase": true } } }, "Response": { "StatusCode": 200, "BodyAsJson": { "id": 10, "name": "doggie", "category": { "id": 1, "name": "Dogs" }, "photoUrls": [ "example-string" ], "tags": [ { "id": 42, "name": "example-string" } ], "status": "pending" }, "Headers": { "Content-Type": "application/json" } } } ``` **__admin/mappings/swagger:** ```yaml "/api/v3/pet": { "put": { "operationId": "petPUT", "responses": { "200": { "description": "", "content": { "application/json": { "schema": {} } } } } }, "post": { "operationId": "petPOST", "responses": { "200": { "description": "", "content": { "application/json": { "schema": {} } } } } } } ``` The issue here is the request body it is not mapped in the swagger output.
Author
Owner

@StefH commented on GitHub (Apr 30, 2022):

@leolplex
Can you try version 1.4.41-ci-16094?

(Also not that converting openapi -> mappings -> openapi will probably lose some information during the process, so don't expect full 100% correct.

@StefH commented on GitHub (Apr 30, 2022): @leolplex Can you try version `1.4.41-ci-16094`? (Also not that converting openapi -> mappings -> openapi will probably lose some information during the process, so don't expect full 100% correct.
Author
Owner

@leolplex commented on GitHub (May 1, 2022):

@StefH yes I use:

<PackageReference Include="WireMock.Net" Version="1.4.41-ci-16094" />
<PackageReference Include="WireMock.Net.OpenApiParser" Version="1.4.41-ci-16094" />

I don't expect full 100% correct but I expect get the same that mapped __admin/mappings:

For the example I changed the ReadStaticMappings to false and it worked better but yet I didn't find the request body:

var server = WireMockServer.Start(new WireMockServerSettings
{
    StartAdminInterface = true,
    ReadStaticMappings = false,
    WatchStaticMappings = false,
    Port = 8080
});
var settings = new WireMockOpenApiParserSettings
{
    NumberOfArrayItems = 1
};

server.WithMappingFromOpenApiFile("testopenapifile.json", settings, out var d);


Console.WriteLine("Press any key to stop the server");
Console.Read();

In this try the __admin/mappings looks like this;

__admin/mappings, look that there's a request "Body" mapped (request body) :

[
  {
    "Guid": "343da75c-cabd-4292-a4dd-bff5bee7d2c7",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/api/v3/pet",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "PUT"
      ],
      "Body": {
        "Matcher": {
          "Name": "JsonMatcher",
          "Pattern": "{\r\n  \"id\": 10,\r\n  \"name\": \"doggie\",\r\n  \"category\": {\r\n    \"id\": 1,\r\n    \"name\": \"Dogs\"\r\n  },\r\n  \"photoUrls\": [\r\n    \"example-string\"\r\n  ],\r\n  \"tags\": [\r\n    {\r\n      \"id\": 42,\r\n      \"name\": \"example-string\"\r\n    }\r\n  ],\r\n  \"status\": \"pending\"\r\n}",
          "IgnoreCase": true
        }
      }
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "id": 10,
        "name": "doggie",
        "category": {
          "id": 1,
          "name": "Dogs"
        },
        "photoUrls": [
          "example-string"
        ],
        "tags": [
          {
            "id": 42,
            "name": "example-string"
          }
        ],
        "status": "available"
      },
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

Although the swagger result improved in this try yet there is no track of the request body. I hope to make myself understood:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Swagger specification",
    "version": "1.0.0"
  },
  "paths": {
    "/api/v3/pet": {
      "put": {
        "operationId": "pet",
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer"
                    },
                    "name": {
                      "type": "string"
                    },
                    "category": {
                      "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/Category"
                    },
                    "photoUrls": {
                      "type": "array",
                      "items": {
                        "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/PhotoUrl"
                      }
                    },
                    "tags": {
                      "type": "array",
                      "items": {
                        "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/Tag"
                      }
                    },
                    "status": {
                      "type": "string"
                    }
                  },
                  "definitions": {
                    "Category": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    },
                    "PhotoUrl": {
                      "type": "string"
                    },
                    "Tag": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    
  }
}

Note:
When I mapped with ReadStaticMappings in false the swagger result improved.

@leolplex commented on GitHub (May 1, 2022): @StefH yes I use: ```csproj <PackageReference Include="WireMock.Net" Version="1.4.41-ci-16094" /> <PackageReference Include="WireMock.Net.OpenApiParser" Version="1.4.41-ci-16094" /> ``` I don't expect full 100% correct but I expect get the same that mapped __admin/mappings: For the example I changed the ReadStaticMappings to false and it worked better but yet I didn't find the request body: ```c# var server = WireMockServer.Start(new WireMockServerSettings { StartAdminInterface = true, ReadStaticMappings = false, WatchStaticMappings = false, Port = 8080 }); var settings = new WireMockOpenApiParserSettings { NumberOfArrayItems = 1 }; server.WithMappingFromOpenApiFile("testopenapifile.json", settings, out var d); Console.WriteLine("Press any key to stop the server"); Console.Read(); ``` In this try the __admin/mappings looks like this; __admin/mappings, look that there's a request "Body" mapped (request body) : ```json [ { "Guid": "343da75c-cabd-4292-a4dd-bff5bee7d2c7", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/api/v3/pet", "IgnoreCase": false } ] }, "Methods": [ "PUT" ], "Body": { "Matcher": { "Name": "JsonMatcher", "Pattern": "{\r\n \"id\": 10,\r\n \"name\": \"doggie\",\r\n \"category\": {\r\n \"id\": 1,\r\n \"name\": \"Dogs\"\r\n },\r\n \"photoUrls\": [\r\n \"example-string\"\r\n ],\r\n \"tags\": [\r\n {\r\n \"id\": 42,\r\n \"name\": \"example-string\"\r\n }\r\n ],\r\n \"status\": \"pending\"\r\n}", "IgnoreCase": true } } }, "Response": { "StatusCode": 200, "BodyAsJson": { "id": 10, "name": "doggie", "category": { "id": 1, "name": "Dogs" }, "photoUrls": [ "example-string" ], "tags": [ { "id": 42, "name": "example-string" } ], "status": "available" }, "Headers": { "Content-Type": "application/json" } } } ] ``` Although the swagger result improved in this try yet there is no track of the request body. I hope to make myself understood: ```json { "openapi": "3.0.0", "info": { "title": "Swagger specification", "version": "1.0.0" }, "paths": { "/api/v3/pet": { "put": { "operationId": "pet", "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "category": { "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/Category" }, "photoUrls": { "type": "array", "items": { "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/PhotoUrl" } }, "tags": { "type": "array", "items": { "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/Tag" } }, "status": { "type": "string" } }, "definitions": { "Category": { "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" } } }, "PhotoUrl": { "type": "string" }, "Tag": { "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" } } } } } } } } } } } }, "components": { } } ``` Note: When I mapped with ReadStaticMappings in false the swagger result improved. #
Author
Owner

@StefH commented on GitHub (May 1, 2022):

Please try 16113.

the request should be present

@StefH commented on GitHub (May 1, 2022): Please try `16113`. the request should be present
Author
Owner

@StefH commented on GitHub (May 3, 2022):

@leolplex
With the very latest Preview NuGet (will be available in max 30 minutes), the generated swagger looks like:

{
    "x-generator": "WireMock.Net",
    "openapi": "3.0.0",
    "info": {
        "title": "WireMock.Net Mappings Swagger specification",
        "version": "1.4.41.0"
    },
    "paths": {
        "x": {
            "get": {
                "operationId": "x",
                "responses": {
                    "200": {
                        "description": "",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "properties": {
                                        "result": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/v3/pet": {
            "put": {
                "operationId": "pet",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "properties": {
                                    "id": {
                                        "type": "integer",
                                        "format": "int32"
                                    },
                                    "name": {
                                        "type": "string"
                                    },
                                    "category": {
                                        "type": "object",
                                        "properties": {
                                            "id": {
                                                "type": "integer",
                                                "format": "int32"
                                            },
                                            "name": {
                                                "type": "string"
                                            }
                                        }
                                    },
                                    "photoUrls": {
                                        "type": "array",
                                        "items": [
                                            {
                                                "type": "string"
                                            }
                                        ]
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": [
                                            {
                                                "type": "object",
                                                "properties": {
                                                    "id": {
                                                        "type": "integer",
                                                        "format": "int32"
                                                    },
                                                    "name": {
                                                        "type": "string"
                                                    }
                                                }
                                            }
                                        ]
                                    },
                                    "status": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "properties": {
                                        "id": {
                                            "type": "integer",
                                            "format": "int32"
                                        },
                                        "name": {
                                            "type": "string"
                                        },
                                        "category": {
                                            "type": "object",
                                            "properties": {
                                                "id": {
                                                    "type": "integer",
                                                    "format": "int32"
                                                },
                                                "name": {
                                                    "type": "string"
                                                }
                                            }
                                        },
                                        "photoUrls": {
                                            "type": "array",
                                            "items": [
                                                {
                                                    "type": "string"
                                                }
                                            ]
                                        },
                                        "tags": {
                                            "type": "array",
                                            "items": [
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "id": {
                                                            "type": "integer",
                                                            "format": "int32"
                                                        },
                                                        "name": {
                                                            "type": "string"
                                                        }
                                                    }
                                                }
                                            ]
                                        },
                                        "status": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {}
}

(Ignore the x path, that's just my other example mapping.)

@StefH commented on GitHub (May 3, 2022): @leolplex With the very latest Preview NuGet (will be available in max 30 minutes), the generated swagger looks like: ``` json { "x-generator": "WireMock.Net", "openapi": "3.0.0", "info": { "title": "WireMock.Net Mappings Swagger specification", "version": "1.4.41.0" }, "paths": { "x": { "get": { "operationId": "x", "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "properties": { "result": { "type": "string" } } } } } } } } }, "/api/v3/pet": { "put": { "operationId": "pet", "requestBody": { "content": { "application/json": { "schema": { "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" }, "category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" } } }, "photoUrls": { "type": "array", "items": [ { "type": "string" } ] }, "tags": { "type": "array", "items": [ { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" } } } ] }, "status": { "type": "string" } } } } } }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" }, "category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" } } }, "photoUrls": { "type": "array", "items": [ { "type": "string" } ] }, "tags": { "type": "array", "items": [ { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" } } } ] }, "status": { "type": "string" } } } } } } } } } }, "components": {} } ``` (Ignore the `x` path, that's just my other example mapping.)
Author
Owner

@leolplex commented on GitHub (May 3, 2022):

@StefH yes go ahead it looks good.

@leolplex commented on GitHub (May 3, 2022): @StefH yes go ahead it looks good.
Author
Owner

@StefH commented on GitHub (May 3, 2022):

So I can merge this and create a new official version?

@StefH commented on GitHub (May 3, 2022): So I can merge this and create a new official version?
Author
Owner

@leolplex commented on GitHub (May 3, 2022):

No wait, I need to run a couple a complex cases.

@leolplex commented on GitHub (May 3, 2022): No wait, I need to run a couple a complex cases.
Author
Owner

@StefH commented on GitHub (May 3, 2022):

Ok.

@StefH commented on GitHub (May 3, 2022): Ok.
Author
Owner

@leolplex commented on GitHub (May 3, 2022):

@StefH it looks as an issue:

var server = WireMockServer.Start(new WireMockServerSettings
{
    StartAdminInterface = true,
    ReadStaticMappings = false,
    WatchStaticMappings = false,
    Port = 8080
});
var settings = new WireMockOpenApiParserSettings
{
    NumberOfArrayItems = 1
};

server.WithMappingFromOpenApiFile("testopenapifile2.yaml", settings, out var d);


Console.WriteLine("Press any key to stop the server");
Console.Read();

testopenapifile2.yaml:

openapi: 3.0.0
info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: 0.1.9
servers:
  - url: http://api.example.com/v1
    description: Optional server description, e.g. Main (production) server
  - url: http://staging-api.example.com
    description: Optional server description, e.g. Internal staging server for testing
paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in CommonMark or HTML.
      responses:
        '200':    # status code
          description: A JSON array of user names
          content:
            application/json:
              schema: 
                type: array
                items: 
                  type: string

__admin/mappings:

[
  {
    "Guid": "eeda8d1e-3bf3-46e0-b3e8-cea262f16854",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/v1/users",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": [
        "example-string"
      ],
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

__admin/mappings/swagger:

{
  "x-generator": "WireMock.Net",
  "openapi": "3.0.0",
  "info": {
    "title": "WireMock.Net Mappings Swagger specification",
    "version": "1.4.41.0"
  },
  "paths": {
    "/v1/users": {
      "get": {
        "operationId": "users",
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {}
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {}
}

In this case the BodyAsJson mapped in _admin/mappings is an array but in the swagger it is mapped as an array but the string property is missing.

I use version 1.4.41-ci-16113.

@leolplex commented on GitHub (May 3, 2022): @StefH it looks as an issue: ```c# var server = WireMockServer.Start(new WireMockServerSettings { StartAdminInterface = true, ReadStaticMappings = false, WatchStaticMappings = false, Port = 8080 }); var settings = new WireMockOpenApiParserSettings { NumberOfArrayItems = 1 }; server.WithMappingFromOpenApiFile("testopenapifile2.yaml", settings, out var d); Console.WriteLine("Press any key to stop the server"); Console.Read(); ``` testopenapifile2.yaml: ```yaml openapi: 3.0.0 info: title: Sample API description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. version: 0.1.9 servers: - url: http://api.example.com/v1 description: Optional server description, e.g. Main (production) server - url: http://staging-api.example.com description: Optional server description, e.g. Internal staging server for testing paths: /users: get: summary: Returns a list of users. description: Optional extended description in CommonMark or HTML. responses: '200': # status code description: A JSON array of user names content: application/json: schema: type: array items: type: string ``` __admin/mappings: ```json [ { "Guid": "eeda8d1e-3bf3-46e0-b3e8-cea262f16854", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/v1/users", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": [ "example-string" ], "Headers": { "Content-Type": "application/json" } } } ] ``` __admin/mappings/swagger: ```json { "x-generator": "WireMock.Net", "openapi": "3.0.0", "info": { "title": "WireMock.Net Mappings Swagger specification", "version": "1.4.41.0" }, "paths": { "/v1/users": { "get": { "operationId": "users", "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "type": "array", "items": {} } } } } } } } }, "components": {} } ``` In this case the BodyAsJson mapped in __admin_/mappings is an array but in the swagger it is mapped as an array but the string property is missing. I use version 1.4.41-ci-16113.
Author
Owner

@leolplex commented on GitHub (May 3, 2022):

I found what looks like another issue:

After of run the next code:

var server = WireMockServer.Start(new WireMockServerSettings
{
    StartAdminInterface = true,
    ReadStaticMappings = false,
    WatchStaticMappings = false,
    Port = 8080
});
var settings = new WireMockOpenApiParserSettings
{
    NumberOfArrayItems = 1
};

server.WithMappingFromOpenApiFile("testopenapifile.json", settings, out var da);


Console.WriteLine("Press any key to stop the server");
Console.Read();

testopenapifile.json:

{
	"openapi": "3.0.2",
	"info": {
		"title": "Swagger Petstore - OpenAPI 3.0",
		"description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) ",
		"termsOfService": "http://swagger.io/terms/",
		"contact": { "email": "apiteam@swagger.io" },
		"license": {
			"name": "Apache 2.0",
			"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
		},
		"version": "1.0.4"
	},
	"externalDocs": {
		"description": "Find out more about Swagger",
		"url": "http://swagger.io"
	},
	"servers": [ { "url": "/api/v3" } ],
	"tags": [
		{
			"name": "pet",
			"description": "Everything about your Pets",
			"externalDocs": {
				"description": "Find out more",
				"url": "http://swagger.io"
			}
		},
		{
			"name": "store",
			"description": "Operations about user"
		},
		{
			"name": "user",
			"description": "Access to Petstore orders",
			"externalDocs": {
				"description": "Find out more about our store",
				"url": "http://swagger.io"
			}
		}
	],
	"paths": {
		"/pet": {
			"put": {
				"tags": [ "pet" ],
				"summary": "Update an existing pet",
				"description": "Update an existing pet by Id",
				"operationId": "updatePet",
				"requestBody": {
					"description": "Update an existent pet in the store",
					"content": {
						"application/json": { "schema": { "$ref": "#/components/schemas/Pet" } },
						"application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } },
						"application/x-www-form-urlencoded": { "schema": { "$ref": "#/components/schemas/Pet" } }
					},
					"required": true
				},
				"responses": {
					"200": {
						"description": "Successful operation",
						"content": {
							"application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } },
							"application/json": { "schema": { "$ref": "#/components/schemas/Pet" } }
						}
					},
					"400": { "description": "Invalid ID supplied" },
					"404": { "description": "Pet not found" },
					"405": { "description": "Validation exception" }
				},
				"security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ]
			}
		}
	},
	"components": {
		"schemas": {
			"Category": {
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"format": "int64",
						"example": 1
					},
					"name": {
						"type": "string",
						"example": "Dogs"
					}
				},
				"xml": { "name": "category" }
			},
			"Tag": {
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"format": "int64"
					},
					"name": { "type": "string" }
				},
				"xml": { "name": "tag" }
			},
			"Pet": {
				"required": [ "name", "photoUrls" ],
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"format": "int64",
						"example": 10
					},
					"name": {
						"type": "string",
						"example": "doggie"
					},
					"category": { "$ref": "#/components/schemas/Category" },
					"photoUrls": {
						"type": "array",
						"xml": { "wrapped": true },
						"items": {
							"type": "string",
							"xml": { "name": "photoUrl" }
						}
					},
					"tags": {
						"type": "array",
						"xml": { "wrapped": true },
						"items": { "$ref": "#/components/schemas/Tag" }
					},
					"status": {
						"type": "string",
						"description": "pet status in the store",
						"enum": [ "available", "pending", "sold" ]
					}
				},
				"xml": { "name": "pet" }
			},
			"ApiResponse": {
				"type": "object",
				"properties": {
					"code": {
						"type": "integer",
						"format": "int32"
					},
					"type": { "type": "string" },
					"message": { "type": "string" }
				},
				"xml": { "name": "##default" }
			}
		}
	}
}

The output in the __admin/mappings was:

[
  {
    "Guid": "892fff46-c255-46b1-adab-f61466ebfe6b",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/api/v3/pet",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "PUT"
      ],
      "Body": {
        "Matcher": {
          "Name": "JsonMatcher",
          "Pattern": "{\n  \"id\": 10,\n  \"name\": \"doggie\",\n  \"category\": {\n    \"id\": 1,\n    \"name\": \"Dogs\"\n  },\n  \"photoUrls\": [\n    \"example-string\"\n  ],\n  \"tags\": [\n    {\n      \"id\": 42,\n      \"name\": \"example-string\"\n    }\n  ],\n  \"status\": \"pending\"\n}",
          "IgnoreCase": true
        }
      }
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "id": 10,
        "name": "doggie",
        "category": {
          "id": 1,
          "name": "Dogs"
        },
        "photoUrls": [
          "example-string"
        ],
        "tags": [
          {
            "id": 42,
            "name": "example-string"
          }
        ],
        "status": "pending"
      },
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

And the __admin/mappings/swagger output was:

{
  "x-generator": "WireMock.Net",
  "openapi": "3.0.0",
  "info": {
    "title": "WireMock.Net Mappings Swagger specification",
    "version": "1.4.41.0"
  },
  "paths": {
    "/api/v3/pet": {
      "put": {
        "operationId": "pet",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "name": {
                    "type": [
                      "null",
                      "string"
                    ]
                  },
                  "category": {
                    "oneOf": [
                      {
                        "type": "null"
                      },
                      {
                        "$ref": "#/paths//api/v3/pet/PUT/requestBody/content/application/json/schema/definitions/Category"
                      }
                    ]
                  },
                  "photoUrls": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "string"
                    }
                  },
                  "tags": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "$ref": "#/paths//api/v3/pet/PUT/requestBody/content/application/json/schema/definitions/Category"
                    }
                  },
                  "status": {
                    "type": [
                      "null",
                      "string"
                    ]
                  }
                },
                "definitions": {
                  "Category": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "id": {
                        "type": "integer",
                        "format": "int64"
                      },
                      "name": {
                        "type": [
                          "null",
                          "string"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "name": {
                      "type": [
                        "null",
                        "string"
                      ]
                    },
                    "category": {
                      "oneOf": [
                        {
                          "type": "null"
                        },
                        {
                          "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/Category"
                        }
                      ]
                    },
                    "photoUrls": {
                      "type": [
                        "array",
                        "null"
                      ],
                      "items": {
                        "type": "string"
                      }
                    },
                    "tags": {
                      "type": [
                        "array",
                        "null"
                      ],
                      "items": {
                        "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/Category"
                      }
                    },
                    "status": {
                      "type": [
                        "null",
                        "string"
                      ]
                    }
                  },
                  "definitions": {
                    "Category": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64"
                        },
                        "name": {
                          "type": [
                            "null",
                            "string"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {}
}

At first glance it looks good but when passing it through the swagger editor there are a lot of structure errors related with $ref :

swaggererrors

I think you have to review the issue of references

If you want you can go to https://editor.swagger.io/ and put the swagger output then you'll see the errors.

@leolplex commented on GitHub (May 3, 2022): I found what looks like another issue: After of run the next code: ```c# var server = WireMockServer.Start(new WireMockServerSettings { StartAdminInterface = true, ReadStaticMappings = false, WatchStaticMappings = false, Port = 8080 }); var settings = new WireMockOpenApiParserSettings { NumberOfArrayItems = 1 }; server.WithMappingFromOpenApiFile("testopenapifile.json", settings, out var da); Console.WriteLine("Press any key to stop the server"); Console.Read(); ``` testopenapifile.json: ```json { "openapi": "3.0.2", "info": { "title": "Swagger Petstore - OpenAPI 3.0", "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) ", "termsOfService": "http://swagger.io/terms/", "contact": { "email": "apiteam@swagger.io" }, "license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.html" }, "version": "1.0.4" }, "externalDocs": { "description": "Find out more about Swagger", "url": "http://swagger.io" }, "servers": [ { "url": "/api/v3" } ], "tags": [ { "name": "pet", "description": "Everything about your Pets", "externalDocs": { "description": "Find out more", "url": "http://swagger.io" } }, { "name": "store", "description": "Operations about user" }, { "name": "user", "description": "Access to Petstore orders", "externalDocs": { "description": "Find out more about our store", "url": "http://swagger.io" } } ], "paths": { "/pet": { "put": { "tags": [ "pet" ], "summary": "Update an existing pet", "description": "Update an existing pet by Id", "operationId": "updatePet", "requestBody": { "description": "Update an existent pet in the store", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/x-www-form-urlencoded": { "schema": { "$ref": "#/components/schemas/Pet" } } }, "required": true }, "responses": { "200": { "description": "Successful operation", "content": { "application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/json": { "schema": { "$ref": "#/components/schemas/Pet" } } } }, "400": { "description": "Invalid ID supplied" }, "404": { "description": "Pet not found" }, "405": { "description": "Validation exception" } }, "security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ] } } }, "components": { "schemas": { "Category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64", "example": 1 }, "name": { "type": "string", "example": "Dogs" } }, "xml": { "name": "category" } }, "Tag": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } }, "xml": { "name": "tag" } }, "Pet": { "required": [ "name", "photoUrls" ], "type": "object", "properties": { "id": { "type": "integer", "format": "int64", "example": 10 }, "name": { "type": "string", "example": "doggie" }, "category": { "$ref": "#/components/schemas/Category" }, "photoUrls": { "type": "array", "xml": { "wrapped": true }, "items": { "type": "string", "xml": { "name": "photoUrl" } } }, "tags": { "type": "array", "xml": { "wrapped": true }, "items": { "$ref": "#/components/schemas/Tag" } }, "status": { "type": "string", "description": "pet status in the store", "enum": [ "available", "pending", "sold" ] } }, "xml": { "name": "pet" } }, "ApiResponse": { "type": "object", "properties": { "code": { "type": "integer", "format": "int32" }, "type": { "type": "string" }, "message": { "type": "string" } }, "xml": { "name": "##default" } } } } } ``` The output in the __admin/mappings was: ```json [ { "Guid": "892fff46-c255-46b1-adab-f61466ebfe6b", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/api/v3/pet", "IgnoreCase": false } ] }, "Methods": [ "PUT" ], "Body": { "Matcher": { "Name": "JsonMatcher", "Pattern": "{\n \"id\": 10,\n \"name\": \"doggie\",\n \"category\": {\n \"id\": 1,\n \"name\": \"Dogs\"\n },\n \"photoUrls\": [\n \"example-string\"\n ],\n \"tags\": [\n {\n \"id\": 42,\n \"name\": \"example-string\"\n }\n ],\n \"status\": \"pending\"\n}", "IgnoreCase": true } } }, "Response": { "StatusCode": 200, "BodyAsJson": { "id": 10, "name": "doggie", "category": { "id": 1, "name": "Dogs" }, "photoUrls": [ "example-string" ], "tags": [ { "id": 42, "name": "example-string" } ], "status": "pending" }, "Headers": { "Content-Type": "application/json" } } } ] ``` And the __admin/mappings/swagger output was: ```json { "x-generator": "WireMock.Net", "openapi": "3.0.0", "info": { "title": "WireMock.Net Mappings Swagger specification", "version": "1.4.41.0" }, "paths": { "/api/v3/pet": { "put": { "operationId": "pet", "requestBody": { "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": [ "null", "string" ] }, "category": { "oneOf": [ { "type": "null" }, { "$ref": "#/paths//api/v3/pet/PUT/requestBody/content/application/json/schema/definitions/Category" } ] }, "photoUrls": { "type": [ "array", "null" ], "items": { "type": "string" } }, "tags": { "type": [ "array", "null" ], "items": { "$ref": "#/paths//api/v3/pet/PUT/requestBody/content/application/json/schema/definitions/Category" } }, "status": { "type": [ "null", "string" ] } }, "definitions": { "Category": { "type": "object", "additionalProperties": false, "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": [ "null", "string" ] } } } } } } } }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": [ "null", "string" ] }, "category": { "oneOf": [ { "type": "null" }, { "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/Category" } ] }, "photoUrls": { "type": [ "array", "null" ], "items": { "type": "string" } }, "tags": { "type": [ "array", "null" ], "items": { "$ref": "#/paths//api/v3/pet/PUT/responses/200/content/application/json/schema/definitions/Category" } }, "status": { "type": [ "null", "string" ] } }, "definitions": { "Category": { "type": "object", "additionalProperties": false, "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": [ "null", "string" ] } } } } } } } } } } } }, "components": {} } ``` At first glance it looks good but when passing it through the swagger editor there are a lot of structure errors related with $ref : ![swaggererrors](https://user-images.githubusercontent.com/11394398/166572283-477b66b7-7293-4e19-8695-fa93681306c2.png) I think you have to review the issue of references If you want you can go to https://editor.swagger.io/ and put the swagger output then you'll see the errors.
Author
Owner

@StefH commented on GitHub (May 4, 2022):

@leolplex

  1. Issue with array should be fixed
  2. references --> I also saw this, therefore I decided to write my own logic to convert an JObject/JArray/object to a Swagger Schema.

Please try latest preview 16129.

@StefH commented on GitHub (May 4, 2022): @leolplex 1. Issue with array should be fixed 2. references --> I also saw this, therefore I decided to write my own logic to convert an JObject/JArray/object to a Swagger Schema. Please try latest preview `16129`.
Author
Owner

@StefH commented on GitHub (May 5, 2022):

@leolplex

The very latest version (16135) fixes all issues with array.

@StefH commented on GitHub (May 5, 2022): @leolplex The very latest version (`16135`) fixes all issues with array.
Author
Owner

@StefH commented on GitHub (May 10, 2022):

@leolplex
Did you have time to test this?

@StefH commented on GitHub (May 10, 2022): @leolplex Did you have time to test this?
Author
Owner

@leolplex commented on GitHub (May 10, 2022):

@StefH
I'm going to test it asap, I'll let you know when news

@leolplex commented on GitHub (May 10, 2022): @StefH I'm going to test it asap, I'll let you know when news
Author
Owner

@leolplex commented on GitHub (May 10, 2022):

@StefH array is woking fine.

Version used: 16135

I've found what looks like an issue:

Code:

var server = WireMockServer.Start(new WireMockServerSettings
{
    StartAdminInterface = true,
    ReadStaticMappings = false,
    WatchStaticMappings = false,
    Port = 8080
});
var settings = new WireMockOpenApiParserSettings
{
    NumberOfArrayItems = 1
};

server.WithMappingFromOpenApiFile("file_error.yaml", settings, out var da);


Console.WriteLine("Press any key to stop the server");
Console.Read();

file_error.yaml:

openapi: 3.0.1
info:
  title: Basic-String-Test
  description: Basic string test
  version: "4.5.2"
servers:
  - url: https://localhost/examples
paths:
  /string/basic:
    get:
      tags:
        - basic-string
      description: Basic string test
      operationId: getBasicString1
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: string
  /string/maxlenght/minlenght:
    get:
      tags:
        - basic-string
      description: Basic string test with maxlength and minlength properties
      operationId: getBasicString2
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: string
                maxLength: 8
                minLength: 8
  /string/maxlenght:
    get:
      tags:
        - basic-string
      description: Basic string test with maxlength property
      operationId: getBasicString3
      
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: string
                maxLength: 5
  /string/minlenght:
    get:
      tags:
        - basic-string
      description: Basic string test with minlength property
      operationId: getBasicString
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: string
                minLength: 10
  /string/enum:
    get:
      tags:
        - basic-string
      description: Basic string test with enum property
      operationId: getBasicString4
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: string
                enum:
                  - response1
                  - response2
  /string/pattern/uri:
    get:
      tags:
        - basic-string
      description: Basic string test with uri pattern property
      operationId: getBasicString5
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: string
                pattern: '^(http|https|ftp|sftp)://((([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))|((www\.|())[a-z0-9]{2,5}\.([a-z]{2,3}((\.[a-z]{2})|()))))(()|(:((102[5-9])|(1[0-9][3-9][0-9])|(1[1-9][0-9]{2})|([2-9][0-9]{3})|([2-5][0-9]{4})|(1[0-9]{4})|(60000))))$'
  /string/pattern/ipv4:
    get:
      tags:
        - basic-string
      description: Basic string test with ipv4 pattern property
      operationId: getBasicString6
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: string
                pattern: '^(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))$'
  /string/header/ipv4:
    get:
      tags:
        - basic-string
      description: Basic string test with ipv4 pattern property
      operationId: getBasicString7
      parameters:
        - name: Header-Sample
          in: header
          required: true
          schema:
            type: string
            pattern: "ipv4 pattern"
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: string
                pattern: '^(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))$'




__admin/mappings:

[
  {
    "Guid": "3a50f82e-bd42-424a-95dd-f010a2adeef1",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/examples/string/minlenght",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": "8P3WZ46CAZ",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  },
  {
    "Guid": "48f4987b-103a-45b6-9565-1fda7e3e07f0",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/examples/string/enum",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": "response1",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  },
  {
    "Guid": "055c32fc-6aa5-4dd0-b215-05793d4be33d",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/examples/string/maxlenght",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": "04Z2J",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  },
  {
    "Guid": "c7725ef4-a4f9-4362-9d6a-a485f5c5ae15",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/examples/string/pattern/ipv4",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": "26.0.161.0",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  },
  {
    "Guid": "388f629c-f061-45cd-95e9-76afdb17f6b4",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/examples/string/pattern/uri",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": "ftp://c5.dos:7555",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  },
  {
    "Guid": "eb777ce6-1500-4a31-af49-19021c47051f",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/examples/string/basic",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": "C9",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  },
  {
    "Guid": "45d20467-e26a-474e-9e86-7ee3cfffd62e",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/examples/string/maxlenght/minlenght",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": "BX5Y35OH",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  },
  {
    "Guid": "d114c39f-1186-445d-a70b-45a4c800ea6d",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/examples/string/header/ipv4",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ],
      "Headers": [
        {
          "Name": "Header-Sample",
          "Matchers": [
            {
              "Name": "ExactMatcher",
              "Pattern": "ipv4 pattern"
            }
          ]
        }
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": "1.0.2.1",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

__admin/mappings/swagger:

{
"Status":"Unexpected character encountered while parsing number: P. Path '', line 1, position 1."
}

Track log:

[11:32:21 ERR] Providing a Response for Mapping 'e7dc1445-5fa3-445f-ab50-9ff8e295caf5' failed. HttpStatusCode set to 500. Exception: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing number: P. Path '', line 1, position 1.
   at Newtonsoft.Json.JsonTextReader.ReadNumberCharIntoBuffer(Char currentChar, Int32 charPos)
   at Newtonsoft.Json.JsonTextReader.ReadNumberIntoBuffer()
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
   at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at NJsonSchema.Generation.SampleJsonSchemaGenerator.Generate(String json)
   at NJsonSchema.JsonSchema.FromSampleJson(String data)
   at WireMock.Serialization.SwaggerMapper.GetJsonSchema(Object instance)
   at WireMock.Serialization.SwaggerMapper.MapResponse(ResponseModel response)
   at WireMock.Serialization.SwaggerMapper.ToSwagger(WireMockServer server)
   at WireMock.Server.WireMockServer.SwaggerGet(IRequestMessage requestMessage)
   at WireMock.ResponseProviders.DynamicResponseProvider.ProvideResponseAsync(IRequestMessage requestMessage, WireMockServerSettings settings)
   at WireMock.Mapping.ProvideResponseAsync(IRequestMessage requestMessage)
   at WireMock.Owin.WireMockMiddleware.InvokeInternalAsync(HttpContext ctx)
@leolplex commented on GitHub (May 10, 2022): @StefH array is woking fine. Version used: `16135` I've found what looks like an issue: Code: ```csharp var server = WireMockServer.Start(new WireMockServerSettings { StartAdminInterface = true, ReadStaticMappings = false, WatchStaticMappings = false, Port = 8080 }); var settings = new WireMockOpenApiParserSettings { NumberOfArrayItems = 1 }; server.WithMappingFromOpenApiFile("file_error.yaml", settings, out var da); Console.WriteLine("Press any key to stop the server"); Console.Read(); ``` file_error.yaml: ```yaml openapi: 3.0.1 info: title: Basic-String-Test description: Basic string test version: "4.5.2" servers: - url: https://localhost/examples paths: /string/basic: get: tags: - basic-string description: Basic string test operationId: getBasicString1 responses: 200: description: successful operation content: application/json: schema: type: string /string/maxlenght/minlenght: get: tags: - basic-string description: Basic string test with maxlength and minlength properties operationId: getBasicString2 responses: 200: description: successful operation content: application/json: schema: type: string maxLength: 8 minLength: 8 /string/maxlenght: get: tags: - basic-string description: Basic string test with maxlength property operationId: getBasicString3 responses: 200: description: successful operation content: application/json: schema: type: string maxLength: 5 /string/minlenght: get: tags: - basic-string description: Basic string test with minlength property operationId: getBasicString responses: 200: description: successful operation content: application/json: schema: type: string minLength: 10 /string/enum: get: tags: - basic-string description: Basic string test with enum property operationId: getBasicString4 responses: 200: description: successful operation content: application/json: schema: type: string enum: - response1 - response2 /string/pattern/uri: get: tags: - basic-string description: Basic string test with uri pattern property operationId: getBasicString5 responses: 200: description: successful operation content: application/json: schema: type: string pattern: '^(http|https|ftp|sftp)://((([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))|((www\.|())[a-z0-9]{2,5}\.([a-z]{2,3}((\.[a-z]{2})|()))))(()|(:((102[5-9])|(1[0-9][3-9][0-9])|(1[1-9][0-9]{2})|([2-9][0-9]{3})|([2-5][0-9]{4})|(1[0-9]{4})|(60000))))$' /string/pattern/ipv4: get: tags: - basic-string description: Basic string test with ipv4 pattern property operationId: getBasicString6 responses: 200: description: successful operation content: application/json: schema: type: string pattern: '^(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))$' /string/header/ipv4: get: tags: - basic-string description: Basic string test with ipv4 pattern property operationId: getBasicString7 parameters: - name: Header-Sample in: header required: true schema: type: string pattern: "ipv4 pattern" responses: 200: description: successful operation content: application/json: schema: type: string pattern: '^(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))$' ``` __admin/mappings: ```json [ { "Guid": "3a50f82e-bd42-424a-95dd-f010a2adeef1", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/examples/string/minlenght", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": "8P3WZ46CAZ", "Headers": { "Content-Type": "application/json" } } }, { "Guid": "48f4987b-103a-45b6-9565-1fda7e3e07f0", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/examples/string/enum", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": "response1", "Headers": { "Content-Type": "application/json" } } }, { "Guid": "055c32fc-6aa5-4dd0-b215-05793d4be33d", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/examples/string/maxlenght", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": "04Z2J", "Headers": { "Content-Type": "application/json" } } }, { "Guid": "c7725ef4-a4f9-4362-9d6a-a485f5c5ae15", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/examples/string/pattern/ipv4", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": "26.0.161.0", "Headers": { "Content-Type": "application/json" } } }, { "Guid": "388f629c-f061-45cd-95e9-76afdb17f6b4", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/examples/string/pattern/uri", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": "ftp://c5.dos:7555", "Headers": { "Content-Type": "application/json" } } }, { "Guid": "eb777ce6-1500-4a31-af49-19021c47051f", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/examples/string/basic", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": "C9", "Headers": { "Content-Type": "application/json" } } }, { "Guid": "45d20467-e26a-474e-9e86-7ee3cfffd62e", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/examples/string/maxlenght/minlenght", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": "BX5Y35OH", "Headers": { "Content-Type": "application/json" } } }, { "Guid": "d114c39f-1186-445d-a70b-45a4c800ea6d", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/examples/string/header/ipv4", "IgnoreCase": false } ] }, "Methods": [ "GET" ], "Headers": [ { "Name": "Header-Sample", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "ipv4 pattern" } ] } ] }, "Response": { "StatusCode": 200, "BodyAsJson": "1.0.2.1", "Headers": { "Content-Type": "application/json" } } } ] ``` __admin/mappings/swagger: ```json { "Status":"Unexpected character encountered while parsing number: P. Path '', line 1, position 1." } ``` Track log: ```log [11:32:21 ERR] Providing a Response for Mapping 'e7dc1445-5fa3-445f-ab50-9ff8e295caf5' failed. HttpStatusCode set to 500. Exception: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing number: P. Path '', line 1, position 1. at Newtonsoft.Json.JsonTextReader.ReadNumberCharIntoBuffer(Char currentChar, Int32 charPos) at Newtonsoft.Json.JsonTextReader.ReadNumberIntoBuffer() at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonReader.ReadAndMoveToContent() at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at NJsonSchema.Generation.SampleJsonSchemaGenerator.Generate(String json) at NJsonSchema.JsonSchema.FromSampleJson(String data) at WireMock.Serialization.SwaggerMapper.GetJsonSchema(Object instance) at WireMock.Serialization.SwaggerMapper.MapResponse(ResponseModel response) at WireMock.Serialization.SwaggerMapper.ToSwagger(WireMockServer server) at WireMock.Server.WireMockServer.SwaggerGet(IRequestMessage requestMessage) at WireMock.ResponseProviders.DynamicResponseProvider.ProvideResponseAsync(IRequestMessage requestMessage, WireMockServerSettings settings) at WireMock.Mapping.ProvideResponseAsync(IRequestMessage requestMessage) at WireMock.Owin.WireMockMiddleware.InvokeInternalAsync(HttpContext ctx) ```
Author
Owner

@StefH commented on GitHub (May 10, 2022):

This is solved in 16144. Please retest.

@StefH commented on GitHub (May 10, 2022): This is solved in `16144`. Please retest.
Author
Owner

@leolplex commented on GitHub (May 10, 2022):

@StefH yep solved on this version.

A last thing:
Screen Shot 2022-05-10 at 2 59 22 PM

Looks like when a param is defined is missing the type and it should be into a label schema:

      parameters:
        - name: api_key
          in: header
          description: ExactMatcher (RejectOnMatch = False)
          pattern: example-string
          example: example-string
          schema:
            type: string

Code:

var server = WireMockServer.Start(new WireMockServerSettings
{
    StartAdminInterface = true,
    ReadStaticMappings = false,
    WatchStaticMappings = false,
    Port = 8080
});
var settings = new WireMockOpenApiParserSettings
{
    NumberOfArrayItems = 1
};

server.WithMappingFromOpenApiFile("pet.json", settings, out var da);

Console.WriteLine("Press any key to stop the server");
Console.Read();

pet.json:

{
  "openapi": "3.0.2",
  "info": {
    "title": "Swagger Petstore - OpenAPI 3.0",
    "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)",
    "termsOfService": "http://swagger.io/terms/",
    "contact": { "email": "apiteam@swagger.io" },
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
    },
    "version": "1.0.11"
  },
  "externalDocs": {
    "description": "Find out more about Swagger",
    "url": "http://swagger.io"
  },
  "servers": [{ "url": "/api/v3" }],
  "tags": [
    {
      "name": "pet",
      "description": "Everything about your Pets",
      "externalDocs": {
        "description": "Find out more",
        "url": "http://swagger.io"
      }
    },
    {
      "name": "store",
      "description": "Access to Petstore orders",
      "externalDocs": {
        "description": "Find out more about our store",
        "url": "http://swagger.io"
      }
    },
    { "name": "user", "description": "Operations about user" }
  ],
  "paths": {
    "/pet": {
      "put": {
        "tags": ["pet"],
        "summary": "Update an existing pet",
        "description": "Update an existing pet by Id",
        "operationId": "updatePet",
        "parameters": [
          {
            "name": "api_key",
            "in": "header",
            "description": "",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "description": "Update an existent pet in the store",
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/Pet" }
            },
            "application/xml": {
              "schema": { "$ref": "#/components/schemas/Pet" }
            },
            "application/x-www-form-urlencoded": {
              "schema": { "$ref": "#/components/schemas/Pet" }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/xml": {
                "schema": { "$ref": "#/components/schemas/Pet" }
              },
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Pet" }
              }
            }
          },
          "400": { "description": "Invalid ID supplied" },
          "404": { "description": "Pet not found" },
          "405": { "description": "Validation exception" }
        },
        "security": [{ "petstore_auth": ["write:pets", "read:pets"] }]
      }
    }
  },
  "components": {
    "schemas": {
      "Category": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "format": "int64", "example": 1 },
          "name": { "type": "string", "example": "Dogs" }
        },
        "xml": { "name": "category" }
      },
      "Tag": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "name": { "type": "string" }
        },
        "xml": { "name": "tag" }
      },
      "Pet": {
        "required": ["name", "photoUrls"],
        "type": "object",
        "properties": {
          "id": { "type": "integer", "format": "int64", "example": 10 },
          "name": { "type": "string", "example": "doggie" },
          "category": { "$ref": "#/components/schemas/Category" },
          "photoUrls": {
            "type": "array",
            "xml": { "wrapped": true },
            "items": { "type": "string", "xml": { "name": "photoUrl" } }
          },
          "tags": {
            "type": "array",
            "xml": { "wrapped": true },
            "items": { "$ref": "#/components/schemas/Tag" }
          },
          "status": {
            "type": "string",
            "description": "pet status in the store",
            "enum": ["available", "pending", "sold"]
          }
        },
        "xml": { "name": "pet" }
      }
    }
  }
}

__admin/mappings:

[
  {
    "Guid": "f68faea1-0f58-455c-b688-bbebc06ce422",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/api/v3/pet",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "PUT"
      ],
      "Headers": [
        {
          "Name": "api_key",
          "Matchers": [
            {
              "Name": "ExactMatcher",
              "Pattern": "example-string"
            }
          ]
        }
      ],
      "Body": {
        "Matcher": {
          "Name": "JsonMatcher",
          "Pattern": "{\n  \"id\": 10,\n  \"name\": \"doggie\",\n  \"category\": {\n    \"id\": 1,\n    \"name\": \"Dogs\"\n  },\n  \"photoUrls\": [\n    \"example-string\"\n  ],\n  \"tags\": [\n    {\n      \"id\": 42,\n      \"name\": \"example-string\"\n    }\n  ],\n  \"status\": \"available\"\n}",
          "IgnoreCase": true
        }
      }
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "id": 10,
        "name": "doggie",
        "category": {
          "id": 1,
          "name": "Dogs"
        },
        "photoUrls": [
          "example-string"
        ],
        "tags": [
          {
            "id": 42,
            "name": "example-string"
          }
        ],
        "status": "pending"
      },
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

__admin/mappings/swagger:

{
  "x-generator": "WireMock.Net",
  "openapi": "3.0.0",
  "info": {
    "title": "WireMock.Net Mappings Swagger specification",
    "version": "1.4.41.0"
  },
  "paths": {
    "/api/v3/pet": {
      "put": {
        "operationId": "pet",
        "parameters": [
          {
            "name": "api_key",
            "in": "header",
            "description": "ExactMatcher (RejectOnMatch = False)",
            "pattern": "example-string",
            "example": "example-string"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer",
                    "format": "int32"
                  },
                  "name": {
                    "type": "string"
                  },
                  "category": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer",
                        "format": "int32"
                      },
                      "name": {
                        "type": "string"
                      }
                    }
                  },
                  "photoUrls": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int32"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "status": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer",
                      "format": "int32"
                    },
                    "name": {
                      "type": "string"
                    },
                    "category": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int32"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    },
                    "photoUrls": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "tags": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer",
                            "format": "int32"
                          },
                          "name": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {}
}

In case of the last issue won't be consider as an Issue the version is ready.

@leolplex commented on GitHub (May 10, 2022): @StefH yep solved on this version. A last thing: <img width="1434" alt="Screen Shot 2022-05-10 at 2 59 22 PM" src="https://user-images.githubusercontent.com/11394398/167711925-2489776d-2fd2-4676-a4d6-395f2838cdb6.png"> Looks like when a param is defined is missing the type and it should be into a label schema: ```yaml parameters: - name: api_key in: header description: ExactMatcher (RejectOnMatch = False) pattern: example-string example: example-string schema: type: string ``` Code: ```csharp var server = WireMockServer.Start(new WireMockServerSettings { StartAdminInterface = true, ReadStaticMappings = false, WatchStaticMappings = false, Port = 8080 }); var settings = new WireMockOpenApiParserSettings { NumberOfArrayItems = 1 }; server.WithMappingFromOpenApiFile("pet.json", settings, out var da); Console.WriteLine("Press any key to stop the server"); Console.Read(); ``` pet.json: ```json { "openapi": "3.0.2", "info": { "title": "Swagger Petstore - OpenAPI 3.0", "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)", "termsOfService": "http://swagger.io/terms/", "contact": { "email": "apiteam@swagger.io" }, "license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.html" }, "version": "1.0.11" }, "externalDocs": { "description": "Find out more about Swagger", "url": "http://swagger.io" }, "servers": [{ "url": "/api/v3" }], "tags": [ { "name": "pet", "description": "Everything about your Pets", "externalDocs": { "description": "Find out more", "url": "http://swagger.io" } }, { "name": "store", "description": "Access to Petstore orders", "externalDocs": { "description": "Find out more about our store", "url": "http://swagger.io" } }, { "name": "user", "description": "Operations about user" } ], "paths": { "/pet": { "put": { "tags": ["pet"], "summary": "Update an existing pet", "description": "Update an existing pet by Id", "operationId": "updatePet", "parameters": [ { "name": "api_key", "in": "header", "description": "", "required": true, "schema": { "type": "string" } } ], "requestBody": { "description": "Update an existent pet in the store", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/x-www-form-urlencoded": { "schema": { "$ref": "#/components/schemas/Pet" } } }, "required": true }, "responses": { "200": { "description": "Successful operation", "content": { "application/xml": { "schema": { "$ref": "#/components/schemas/Pet" } }, "application/json": { "schema": { "$ref": "#/components/schemas/Pet" } } } }, "400": { "description": "Invalid ID supplied" }, "404": { "description": "Pet not found" }, "405": { "description": "Validation exception" } }, "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] } } }, "components": { "schemas": { "Category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64", "example": 1 }, "name": { "type": "string", "example": "Dogs" } }, "xml": { "name": "category" } }, "Tag": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } }, "xml": { "name": "tag" } }, "Pet": { "required": ["name", "photoUrls"], "type": "object", "properties": { "id": { "type": "integer", "format": "int64", "example": 10 }, "name": { "type": "string", "example": "doggie" }, "category": { "$ref": "#/components/schemas/Category" }, "photoUrls": { "type": "array", "xml": { "wrapped": true }, "items": { "type": "string", "xml": { "name": "photoUrl" } } }, "tags": { "type": "array", "xml": { "wrapped": true }, "items": { "$ref": "#/components/schemas/Tag" } }, "status": { "type": "string", "description": "pet status in the store", "enum": ["available", "pending", "sold"] } }, "xml": { "name": "pet" } } } } } ``` __admin/mappings: ```json [ { "Guid": "f68faea1-0f58-455c-b688-bbebc06ce422", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/api/v3/pet", "IgnoreCase": false } ] }, "Methods": [ "PUT" ], "Headers": [ { "Name": "api_key", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "example-string" } ] } ], "Body": { "Matcher": { "Name": "JsonMatcher", "Pattern": "{\n \"id\": 10,\n \"name\": \"doggie\",\n \"category\": {\n \"id\": 1,\n \"name\": \"Dogs\"\n },\n \"photoUrls\": [\n \"example-string\"\n ],\n \"tags\": [\n {\n \"id\": 42,\n \"name\": \"example-string\"\n }\n ],\n \"status\": \"available\"\n}", "IgnoreCase": true } } }, "Response": { "StatusCode": 200, "BodyAsJson": { "id": 10, "name": "doggie", "category": { "id": 1, "name": "Dogs" }, "photoUrls": [ "example-string" ], "tags": [ { "id": 42, "name": "example-string" } ], "status": "pending" }, "Headers": { "Content-Type": "application/json" } } } ] ``` __admin/mappings/swagger: ```json { "x-generator": "WireMock.Net", "openapi": "3.0.0", "info": { "title": "WireMock.Net Mappings Swagger specification", "version": "1.4.41.0" }, "paths": { "/api/v3/pet": { "put": { "operationId": "pet", "parameters": [ { "name": "api_key", "in": "header", "description": "ExactMatcher (RejectOnMatch = False)", "pattern": "example-string", "example": "example-string" } ], "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" }, "category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" } } }, "photoUrls": { "type": "array", "items": { "type": "string" } }, "tags": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" } } } }, "status": { "type": "string" } } } } } }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" }, "category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" } } }, "photoUrls": { "type": "array", "items": { "type": "string" } }, "tags": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "name": { "type": "string" } } } }, "status": { "type": "string" } } } } } } } } } }, "components": {} } ``` In case of the last issue won't be consider as an Issue the version is ready.
Author
Owner

@StefH commented on GitHub (May 11, 2022):

@leolplex

Latest version 16147:

  1. schema: type: string is included always

  2. and "required = true" is also added when it's a normal matcher (so "not" RejectOnMatch)

@StefH commented on GitHub (May 11, 2022): @leolplex Latest version `16147`: 1. schema: type: string is included always 2. and "required = true" is also added when it's a normal matcher (so "not" RejectOnMatch)
Author
Owner

@leolplex commented on GitHub (May 11, 2022):

@StefH
That's working, great.

On the same scenario above I received other structural error: "additionalProperty: pattern" I'm wondering if this property could be removed?

Screen Shot 2022-05-11 at 2 20 39 PM

Screen Shot 2022-05-11 at 2 20 32 PM

Finally, any chance to enable swagger UI?

@leolplex commented on GitHub (May 11, 2022): @StefH That's working, great. On the same scenario above I received other structural error: "additionalProperty: pattern" I'm wondering if this property could be removed? ![Screen Shot 2022-05-11 at 2 20 39 PM](https://user-images.githubusercontent.com/11394398/167929134-7cae4ab6-ef13-47a0-b09f-7e61091944eb.png) ![Screen Shot 2022-05-11 at 2 20 32 PM](https://user-images.githubusercontent.com/11394398/167929265-7ade33be-3540-4acd-ba83-84c6656ceaee.png) Finally, any chance to enable swagger UI?
Author
Owner

@StefH commented on GitHub (May 12, 2022):

For some reason it seems that pattern is not allowed for "Header parameters", but it's fine for query and cookie?
I can not find any clear documentation why and how pattern is valid.
For now I'll remove pattern everywhere. Unless you can find some documentation on this.

Swagger UI: maybe there is a simple NuGet from Swagger to do that, but this will be for the future.

new version = 16154

@StefH commented on GitHub (May 12, 2022): For some reason it seems that `pattern` is not allowed for "Header parameters", but it's fine for query and cookie? I can not find any clear documentation why and how `pattern` is valid. For now I'll remove pattern everywhere. Unless you can find some documentation on this. Swagger UI: maybe there is a simple NuGet from Swagger to do that, but this will be for the future. new version = 16154
Author
Owner

@leolplex commented on GitHub (May 12, 2022):

@StefH

You can put pattern at the schema level:

          schema:
            type: string
            pattern: example-string

(Swagger UI will be awesome)

@leolplex commented on GitHub (May 12, 2022): @StefH You can put pattern at the schema level: ```yaml schema: type: string pattern: example-string ``` (Swagger UI will be awesome)
Author
Owner

@StefH commented on GitHub (May 12, 2022):

@leolplex
See 16158

@StefH commented on GitHub (May 12, 2022): @leolplex See `16158`
Author
Owner

@leolplex commented on GitHub (May 12, 2022):

@StefH
It's working.

I've found other structural error:

c# code:

var server = WireMockServer.Start(new WireMockServerSettings
{
    StartAdminInterface = true,
    ReadStaticMappings = false,
    WatchStaticMappings = false,
    Port = 8080
});
var settings = new WireMockOpenApiParserSettings
{
    NumberOfArrayItems = 1
};

server.WithMappingFromOpenApiFile("refs.yaml", settings, out var da);

refs.yaml:

swagger: "2.0"
info:
  description: "This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters."
  version: "1.0.0"
  title: "Swagger Petstore"
  termsOfService: "http://swagger.io/terms/"
  contact:
    email: "apiteam@swagger.io"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
tags:
- name: "pet"
  description: "Everything about your Pets"
  externalDocs:
    description: "Find out more"
    url: "http://swagger.io"
- name: "store"
  description: "Access to Petstore orders"
- name: "user"
  description: "Operations about user"
  externalDocs:
    description: "Find out more about our store"
    url: "http://swagger.io"
schemes:
- "https"
- "http"
paths:
  /user/createWithList:
    post:
      tags:
      - "user"
      summary: "Creates list of users with given input array"
      description: ""
      operationId: "createUsersWithListInput"
      produces:
      - "application/xml"
      - "application/json"
      parameters:
      - in: "body"
        name: "body"
        description: "List of user object"
        required: true
        schema:
          type: "array"
          items:
            $ref: "#/definitions/User"
      responses:
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/Order"        
        default:
          description: "successful operation"
definitions:
  Order:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      petId:
        type: "integer"
        format: "int64"
      quantity:
        type: "integer"
        format: "int32"
      shipDate:
        type: "string"
        format: "date-time"
      status:
        type: "string"
        description: "Order Status"
        enum:
        - "placed"
        - "approved"
        - "delivered"
      complete:
        type: "boolean"
        default: false
    xml:
      name: "Order"
  Category:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      name:
        type: "string"
    xml:
      name: "Category"
  User:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      username:
        type: "string"
      firstName:
        type: "string"
      lastName:
        type: "string"
      email:
        type: "string"
      password:
        type: "string"
      phone:
        type: "string"
      userStatus:
        type: "integer"
        format: "int32"
        description: "User Status"
    xml:
      name: "User"
  Tag:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      name:
        type: "string"
    xml:
      name: "Tag"
  Pet:
    type: "object"
    required:
    - "name"
    - "photoUrls"
    properties:
      id:
        type: "integer"
        format: "int64"
      category:
        $ref: "#/definitions/Category"
      name:
        type: "string"
        example: "doggie"
      photoUrls:
        type: "array"
        xml:
          name: "photoUrl"
          wrapped: true
        items:
          type: "string"
      tags:
        type: "array"
        xml:
          name: "tag"
          wrapped: true
        items:
          $ref: "#/definitions/Tag"
      status:
        type: "string"
        description: "pet status in the store"
        enum:
        - "available"
        - "pending"
        - "sold"
    xml:
      name: "Pet"
  ApiResponse:
    type: "object"
    properties:
      code:
        type: "integer"
        format: "int32"
      type:
        type: "string"
      message:
        type: "string"
externalDocs:
  description: "Find out more about Swagger"
  url: "http://swagger.io"

__admin/mappings:

[
  {
    "Guid": "416295d7-de26-443c-b2c2-62583effd602",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/v2/user/createWithList",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "POST"
      ],
      "Body": {
        "Matcher": {
          "Name": "JsonMatcher",
          "Pattern": "[\n  {\n    \"id\": 42,\n    \"username\": \"example-string\",\n    \"firstName\": \"example-string\",\n    \"lastName\": \"example-string\",\n    \"email\": \"example-string\",\n    \"password\": \"example-string\",\n    \"phone\": \"example-string\",\n    \"userStatus\": 42\n  }\n]",
          "IgnoreCase": true
        }
      }
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "id": 42,
        "petId": 42,
        "quantity": 42,
        "shipDate": "2022-05-12T20:11:17.626+00:00",
        "status": "placed",
        "complete": true
      },
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

__admin/mappings/swagger:

{
  "x-generator": "WireMock.Net",
  "openapi": "3.0.0",
  "info": {
    "title": "WireMock.Net Mappings Swagger specification",
    "version": "1.4.41.0"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/v2/user/createWithList": {
      "post": {
        "operationId": "createWithList",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/paths//v2/user/createWithList/POST/requestBody/content/application/json/schema/definitions/Anonymous"
                },
                "definitions": {
                  "Anonymous": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "username": {
                        "type": "string"
                      },
                      "firstName": {
                        "type": "string"
                      },
                      "lastName": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string"
                      },
                      "password": {
                        "type": "string"
                      },
                      "phone": {
                        "type": "string"
                      },
                      "userStatus": {
                        "type": "integer"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer",
                      "format": "int32"
                    },
                    "petId": {
                      "type": "integer",
                      "format": "int32"
                    },
                    "quantity": {
                      "type": "integer",
                      "format": "int32"
                    },
                    "shipDate": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "status": {
                      "type": "string"
                    },
                    "complete": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {}
}

Structural errors:

  1. should NOT have additional properties additionalProperty: definitions
  2. Could not resolve reference: #/paths//v2/user/createWithList/POST/requestBody/content/application/json/schema/definitions/Anonymous
  3. $refs must reference a valid location in the document

Screen Shot 2022-05-12 at 3 15 57 PM

Screen Shot 2022-05-12 at 3 16 03 PM

@leolplex commented on GitHub (May 12, 2022): @StefH It's working. I've found other structural error: c# code: ```csharp var server = WireMockServer.Start(new WireMockServerSettings { StartAdminInterface = true, ReadStaticMappings = false, WatchStaticMappings = false, Port = 8080 }); var settings = new WireMockOpenApiParserSettings { NumberOfArrayItems = 1 }; server.WithMappingFromOpenApiFile("refs.yaml", settings, out var da); ``` refs.yaml: ```yaml swagger: "2.0" info: description: "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters." version: "1.0.0" title: "Swagger Petstore" termsOfService: "http://swagger.io/terms/" contact: email: "apiteam@swagger.io" license: name: "Apache 2.0" url: "http://www.apache.org/licenses/LICENSE-2.0.html" host: "petstore.swagger.io" basePath: "/v2" tags: - name: "pet" description: "Everything about your Pets" externalDocs: description: "Find out more" url: "http://swagger.io" - name: "store" description: "Access to Petstore orders" - name: "user" description: "Operations about user" externalDocs: description: "Find out more about our store" url: "http://swagger.io" schemes: - "https" - "http" paths: /user/createWithList: post: tags: - "user" summary: "Creates list of users with given input array" description: "" operationId: "createUsersWithListInput" produces: - "application/xml" - "application/json" parameters: - in: "body" name: "body" description: "List of user object" required: true schema: type: "array" items: $ref: "#/definitions/User" responses: "200": description: "successful operation" schema: $ref: "#/definitions/Order" default: description: "successful operation" definitions: Order: type: "object" properties: id: type: "integer" format: "int64" petId: type: "integer" format: "int64" quantity: type: "integer" format: "int32" shipDate: type: "string" format: "date-time" status: type: "string" description: "Order Status" enum: - "placed" - "approved" - "delivered" complete: type: "boolean" default: false xml: name: "Order" Category: type: "object" properties: id: type: "integer" format: "int64" name: type: "string" xml: name: "Category" User: type: "object" properties: id: type: "integer" format: "int64" username: type: "string" firstName: type: "string" lastName: type: "string" email: type: "string" password: type: "string" phone: type: "string" userStatus: type: "integer" format: "int32" description: "User Status" xml: name: "User" Tag: type: "object" properties: id: type: "integer" format: "int64" name: type: "string" xml: name: "Tag" Pet: type: "object" required: - "name" - "photoUrls" properties: id: type: "integer" format: "int64" category: $ref: "#/definitions/Category" name: type: "string" example: "doggie" photoUrls: type: "array" xml: name: "photoUrl" wrapped: true items: type: "string" tags: type: "array" xml: name: "tag" wrapped: true items: $ref: "#/definitions/Tag" status: type: "string" description: "pet status in the store" enum: - "available" - "pending" - "sold" xml: name: "Pet" ApiResponse: type: "object" properties: code: type: "integer" format: "int32" type: type: "string" message: type: "string" externalDocs: description: "Find out more about Swagger" url: "http://swagger.io" ``` __admin/mappings: ```json [ { "Guid": "416295d7-de26-443c-b2c2-62583effd602", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/v2/user/createWithList", "IgnoreCase": false } ] }, "Methods": [ "POST" ], "Body": { "Matcher": { "Name": "JsonMatcher", "Pattern": "[\n {\n \"id\": 42,\n \"username\": \"example-string\",\n \"firstName\": \"example-string\",\n \"lastName\": \"example-string\",\n \"email\": \"example-string\",\n \"password\": \"example-string\",\n \"phone\": \"example-string\",\n \"userStatus\": 42\n }\n]", "IgnoreCase": true } } }, "Response": { "StatusCode": 200, "BodyAsJson": { "id": 42, "petId": 42, "quantity": 42, "shipDate": "2022-05-12T20:11:17.626+00:00", "status": "placed", "complete": true }, "Headers": { "Content-Type": "application/json" } } } ] ``` __admin/mappings/swagger: ```json { "x-generator": "WireMock.Net", "openapi": "3.0.0", "info": { "title": "WireMock.Net Mappings Swagger specification", "version": "1.4.41.0" }, "servers": [ { "url": "http://localhost:8080" } ], "paths": { "/v2/user/createWithList": { "post": { "operationId": "createWithList", "requestBody": { "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/paths//v2/user/createWithList/POST/requestBody/content/application/json/schema/definitions/Anonymous" }, "definitions": { "Anonymous": { "type": "object", "properties": { "id": { "type": "integer" }, "username": { "type": "string" }, "firstName": { "type": "string" }, "lastName": { "type": "string" }, "email": { "type": "string" }, "password": { "type": "string" }, "phone": { "type": "string" }, "userStatus": { "type": "integer" } } } } } } } }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32" }, "petId": { "type": "integer", "format": "int32" }, "quantity": { "type": "integer", "format": "int32" }, "shipDate": { "type": "string", "format": "date-time" }, "status": { "type": "string" }, "complete": { "type": "boolean" } } } } } } } } } }, "components": {} } ``` Structural errors: 1. should NOT have additional properties additionalProperty: definitions 2. Could not resolve reference: #/paths//v2/user/createWithList/POST/requestBody/content/application/json/schema/definitions/Anonymous 3. $refs must reference a valid location in the document ![Screen Shot 2022-05-12 at 3 15 57 PM](https://user-images.githubusercontent.com/11394398/168160645-76238cd9-8d55-41dc-9f09-cb4e16766c7b.png) ![Screen Shot 2022-05-12 at 3 16 03 PM](https://user-images.githubusercontent.com/11394398/168160661-6c3c585e-7914-426a-9c5c-71c391bc8864.png)
Author
Owner

@StefH commented on GitHub (May 12, 2022):

Test version 16160

@StefH commented on GitHub (May 12, 2022): Test version 16160
Author
Owner

@leolplex commented on GitHub (May 13, 2022):

@StefH all issues was resolver, I think it's a stable version to release.

I open other thread if I'll found any thing in the future.

Thanks a lot, I appreciate it.

@leolplex commented on GitHub (May 13, 2022): @StefH all issues was resolver, I think it's a stable version to release. I open other thread if I'll found any thing in the future. Thanks a lot, I appreciate it.
Author
Owner

@leolplex commented on GitHub (May 13, 2022):

@StefH wait, please.

I've found a new issues, let me a couple of minutes, I'll document the scenario.

@leolplex commented on GitHub (May 13, 2022): @StefH wait, please. I've found a new issues, let me a couple of minutes, I'll document the scenario.
Author
Owner

@leolplex commented on GitHub (May 13, 2022):

@StefH
This time is related with files put in __admin/mappings with PatternAsFile and BodyAsFile.

Code:

var server = WireMockServer.Start(new WireMockServerSettings
{
    StartAdminInterface = true,
    ReadStaticMappings = true,
    WatchStaticMappings = true,
    Port = 8080
});

Console.WriteLine("Press any key to stop the server");
Console.Read();

Folder: __admin/mappings/test.json:

[{
    "Title": "Test",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/test/some",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": ["POST"],
      "Body": {
        "Matcher": {
          "Name": "ExactMatcher",
          "PatternAsFile": "test_request.xml"
        }
      }
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsFile": "__admin/data/test_response.xml",
      "BodyAsFileIsCached": true,
      "Headers": {
        "Content-Type": "application/xml; charset=UTF-8"
      }
    }
  }]

Folder: __admin/mappings/test_request.xml:

<?xml version="1.0" encoding="UTF-8"?>
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>

Folder: __admin/mappings/data/test_response.xml:

<?xml version="1.0" encoding="UTF-8"?>
<InsuranceCompanies>
    <Top_Insurance_Companies>
        <Name>Berkshire Hathaway ( BRK.A)</Name>
        <Capitalization>$655 billion</Capitalization>
    </Top_Insurance_Companies>
</InsuranceCompanies>

Http Get: __admin/mappings:

[
  {
    "Guid": "95f85217-9214-4b42-978e-e26f1e13bcd3",
    "Title": "Test",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/test/some",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "POST"
      ],
      "Body": {
        "Matcher": {
          "Name": "ExactMatcher",
          "Pattern": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<note>\n    <to>Tove</to>\n    <from>Jani</from>\n    <heading>Reminder</heading>\n    <body>Don't forget me this weekend!</body>\n</note>",
          "PatternAsFile": "test_request.xml"
        }
      }
    },
    "Response": {
      "StatusCode": 200,
      "Headers": {
        "Content-Type": "application/xml; charset=UTF-8"
      }
    }
  }
]

Http Get: __admin/mappings/swagger:

{
  "x-generator": "WireMock.Net",
  "openapi": "3.0.0",
  "info": {
    "title": "WireMock.Net Mappings Swagger specification",
    "version": "1.4.41.0"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/test/some": {
      "post": {
        "operationId": "some",
        "responses": {}
      }
    }
  },
  "components": {}
}

The request and response are not mapped in the swagger output.

Screen Shot 2022-05-13 at 2 27 42 PM

@leolplex commented on GitHub (May 13, 2022): @StefH This time is related with files put in __admin/mappings with PatternAsFile and BodyAsFile. Code: ```csharp var server = WireMockServer.Start(new WireMockServerSettings { StartAdminInterface = true, ReadStaticMappings = true, WatchStaticMappings = true, Port = 8080 }); Console.WriteLine("Press any key to stop the server"); Console.Read(); ``` Folder: __admin/mappings/test.json: ```json [{ "Title": "Test", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/test/some", "IgnoreCase": false } ] }, "Methods": ["POST"], "Body": { "Matcher": { "Name": "ExactMatcher", "PatternAsFile": "test_request.xml" } } }, "Response": { "StatusCode": 200, "BodyAsFile": "__admin/data/test_response.xml", "BodyAsFileIsCached": true, "Headers": { "Content-Type": "application/xml; charset=UTF-8" } } }] ``` Folder: __admin/mappings/test_request.xml: ```xml <?xml version="1.0" encoding="UTF-8"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> ``` Folder: __admin/mappings/data/test_response.xml: ```xml <?xml version="1.0" encoding="UTF-8"?> <InsuranceCompanies> <Top_Insurance_Companies> <Name>Berkshire Hathaway ( BRK.A)</Name> <Capitalization>$655 billion</Capitalization> </Top_Insurance_Companies> </InsuranceCompanies> ``` Http Get: __admin/mappings: ```json [ { "Guid": "95f85217-9214-4b42-978e-e26f1e13bcd3", "Title": "Test", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/test/some", "IgnoreCase": false } ] }, "Methods": [ "POST" ], "Body": { "Matcher": { "Name": "ExactMatcher", "Pattern": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<note>\n <to>Tove</to>\n <from>Jani</from>\n <heading>Reminder</heading>\n <body>Don't forget me this weekend!</body>\n</note>", "PatternAsFile": "test_request.xml" } } }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": "application/xml; charset=UTF-8" } } } ] ``` Http Get: __admin/mappings/swagger: ```json { "x-generator": "WireMock.Net", "openapi": "3.0.0", "info": { "title": "WireMock.Net Mappings Swagger specification", "version": "1.4.41.0" }, "servers": [ { "url": "http://localhost:8080" } ], "paths": { "/test/some": { "post": { "operationId": "some", "responses": {} } } }, "components": {} } ``` The request and response are not mapped in the swagger output. ![Screen Shot 2022-05-13 at 2 27 42 PM](https://user-images.githubusercontent.com/11394398/168376292-a98ffc69-0aca-418c-9231-6e48fa0ccca1.png)
Author
Owner

@StefH commented on GitHub (May 13, 2022):

Yes.

However if this file is dynamic, so the content can change, which means that the swagger will change.

So this will be something for a next version.

Agree?

@StefH commented on GitHub (May 13, 2022): Yes. However if this file is dynamic, so the content can change, which means that the swagger will change. So this will be something for a next version. Agree?
Author
Owner

@leolplex commented on GitHub (May 13, 2022):

@StefH I agree. Then this version is ready for release. Thanks.

@leolplex commented on GitHub (May 13, 2022): @StefH I agree. Then this version is ready for release. Thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#415