mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Swagger implementation #415
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 @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.
@StefH commented on GitHub (Apr 11, 2022):
A Swagger API contains two things:
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 13, 2022):
@devmariodiaz is this clear?
@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.
@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 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-16049and let me know if you find any bugs or issues.@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 commented on GitHub (Apr 26, 2022):
@brunotarghetta @leolplex please bear in mind to test this new feature using swagger 🥇
@StefH commented on GitHub (Apr 28, 2022):
@devmariodiaz @brunotarghetta @leolplex
Did you have time to test this functionality?
@leolplex commented on GitHub (Apr 29, 2022):
@StefH I've been testing this feature and I found a issue.
I ran the next code:
testopenapifile.json:
__admin/mappings:
__admin/mappings/swagger:
The issue here is the request body it is not mapped in the swagger output.
@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.
@leolplex commented on GitHub (May 1, 2022):
@StefH yes I use:
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:
In this try the __admin/mappings looks like this;
__admin/mappings, look that there's a request "Body" mapped (request body) :
Although the swagger result improved in this try yet there is no track of the request body. I hope to make myself understood:
Note:
When I mapped with ReadStaticMappings in false the swagger result improved.
@StefH commented on GitHub (May 1, 2022):
Please try
16113.the request should be present
@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:
(Ignore the
xpath, that's just my other example mapping.)@leolplex commented on GitHub (May 3, 2022):
@StefH yes go ahead it looks good.
@StefH commented on GitHub (May 3, 2022):
So I can merge this and create a new official version?
@leolplex commented on GitHub (May 3, 2022):
No wait, I need to run a couple a complex cases.
@StefH commented on GitHub (May 3, 2022):
Ok.
@leolplex commented on GitHub (May 3, 2022):
@StefH it looks as an issue:
testopenapifile2.yaml:
__admin/mappings:
__admin/mappings/swagger:
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):
I found what looks like another issue:
After of run the next code:
testopenapifile.json:
The output in the __admin/mappings was:
And the __admin/mappings/swagger output was:
At first glance it looks good but when passing it through the swagger editor there are a lot of structure errors related with $ref :
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.
@StefH commented on GitHub (May 4, 2022):
@leolplex
Please try latest preview
16129.@StefH commented on GitHub (May 5, 2022):
@leolplex
The very latest version (
16135) fixes all issues with array.@StefH commented on GitHub (May 10, 2022):
@leolplex
Did you have time to test this?
@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 array is woking fine.
Version used:
16135I've found what looks like an issue:
Code:
file_error.yaml:
__admin/mappings:
__admin/mappings/swagger:
Track log:
@StefH commented on GitHub (May 10, 2022):
This is solved in
16144. Please retest.@leolplex commented on GitHub (May 10, 2022):
@StefH yep solved on this version.
A last thing:

Looks like when a param is defined is missing the type and it should be into a label schema:
Code:
pet.json:
__admin/mappings:
__admin/mappings/swagger:
In case of the last issue won't be consider as an Issue the version is ready.
@StefH commented on GitHub (May 11, 2022):
@leolplex
Latest version
16147:schema: type: string is included always
and "required = true" is also added when it's a normal matcher (so "not" RejectOnMatch)
@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?
Finally, any chance to enable swagger UI?
@StefH commented on GitHub (May 12, 2022):
For some reason it seems that
patternis not allowed for "Header parameters", but it's fine for query and cookie?I can not find any clear documentation why and how
patternis 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
@leolplex commented on GitHub (May 12, 2022):
@StefH
You can put pattern at the schema level:
(Swagger UI will be awesome)
@StefH commented on GitHub (May 12, 2022):
@leolplex
See
16158@leolplex commented on GitHub (May 12, 2022):
@StefH
It's working.
I've found other structural error:
c# code:
refs.yaml:
__admin/mappings:
__admin/mappings/swagger:
Structural errors:
@StefH commented on GitHub (May 12, 2022):
Test version 16160
@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 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
This time is related with files put in __admin/mappings with PatternAsFile and BodyAsFile.
Code:
Folder: __admin/mappings/test.json:
Folder: __admin/mappings/test_request.xml:
Folder: __admin/mappings/data/test_response.xml:
Http Get: __admin/mappings:
Http Get: __admin/mappings/swagger:
The request and response are not mapped in the swagger output.
@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?
@leolplex commented on GitHub (May 13, 2022):
@StefH I agree. Then this version is ready for release. Thanks.