mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Swagger/OpenAPI conversion endpoint in Admin API #504
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @laslanian on GitHub (Mar 24, 2023).
Originally assigned to: @StefH on GitHub.
Hello, first off I'd like to thank everyone who contributed to the making of WireMock.Net!
I was wondering if it would be possible, and what would be the best way, to expose some of the OpenAPIParser methods in the Admin API?
The goal is to be able to submit a POST request to the Admin API containing Swagger/OpenAPI within the body, and receive back the converted WireMock mappings in the response.
@StefH commented on GitHub (Mar 26, 2023):
The logic for parsing an swagger/openapi document to a wiremock.net mapping is done via the WireMock.Net.OpenApiParser NuGet.
And because this NuGet does not support all frameworks used in WireMock.Net, this is a separate package.
However, there are some extension methods which can you use:
https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net.OpenApiParser/Extensions/WireMockServerExtensions.cs
Note that this is not exactly what you ask, you want an API Admin endpoint to convert Swagger/OpenAPI and get back the mappings.
I'll take a look if that can be added.
@StefH commented on GitHub (Mar 28, 2023):
@laslanian
I've create a preview version (1.5.21-ci-17268) (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions) which you can use to convert an openapi/swagger document to mappings.
Do a POST to
/__admin/openapi/convertto convert a openapi/swagger document to mappings (the mappings are only returned)Do a POST to
/__admin/openapi/saveto convert a openapi/swagger document to mappings + save the mappings in WireMock Server@laslanian commented on GitHub (Mar 28, 2023):
@StefH Thank you so much for such a quick turnaround on this! To be honest I was not expecting this to be added in, but thank you for that. I will try this out and let you know how it went.
@laslanian commented on GitHub (Mar 29, 2023):
@StefH The endpoints are working as expected with __admin/openapi/convert returning the mapping, and __admin/openapi/save persisting it to WireMock instance.
I did notice an inconsistency with the returned mappings.
The new endpoint (__admin/openapi/convert) returns the mappings in a different format than the existing __admin/mappings endpoint, which is also different than the mappings used in WireMock Java version (WireMock.org) as seen below.
Due to this inconsistency, importing the converted mappings into the Java version has many issues. Would it be possible to align these formats? I would be happy to contribute my time to working on this if there is initiative on this subject.
Original Swagger Json
WireMock.Net Mapping (POST __admin/openapi/convert)
WireMock.Net Mapping (GET __admin/mappings)
WireMock.org Mapping (GET __admin/mappings)
@StefH commented on GitHub (Mar 29, 2023):
I did some quick tests using your example pet store json. And it seems that the mappings are the same, although the ordering is different.
And about WireMock.Org --> https://github.com/WireMock-Net/WireMock.Net/wiki/WireMock.Org
@StefH commented on GitHub (Apr 1, 2023):
@laslanian
Is this clear?
@StefH commented on GitHub (Apr 5, 2023):
@laslanian
Can I merge this code change to the master?
@StefH commented on GitHub (Apr 8, 2023):
PR is merged