Import Response Body with Shortcodes Suggestions from OpenAPI Schema
Introducing an improvement for OpenAPI / Swagger endpoints integration. Now you can import not only endpoints with its HTTP method, URI, HTTP status, content type and description. Now you have a new option to import the response body from the OpenAPI model schema / definitions.
But we did not stop on this and went even a bit further. During the import, QuickMocker will try to guess an appropriate shortcode for each property of the model, so the response will become more dynamic. Currently it is using 3 methods to guess the shortcode:
- We’ve created a very simple mapping (or in other words shortcodes index) from property name to shortcode name which is just a JSON object stored in a file. The index works in a partial match mode, which means that for instance both “title” and “fullTitle” will match the index with “title” property which is mapped to the “(fakeSentence:5)” shortcode. Here’s a link to the file. It is located on the GiHub and you may create pull requests to provide your own suggestions for the shortcodes index.
- Partial matching of the property name and the shortcode name. For instance if you have a property name `email`, its value will automatically become “(fakeEmail)” shortcode, “phoneNumber” property value will be “(fakePhone)” shortcode.
- Finally, if the previous methods are not able to get the correct shortcode, Quickmocker is using a levenshtein algorithm as a fallback to get the most appropriate shortcode. Frankly speaking, after doing a lot of testing, it does not seem to work very well. If you have any better ideas, we are happy to hear it from you. Otherwise, in order to make the shortcodes guessing better we simply need to extend our shortcodes index from the method #2.
In order to allow the response body import, make sure that the corresponding toggler is turned on, same as on the screenshot below:
Also make sure that your OpenAPI / Swagger schema consists of the model definitions and they are referenced in the endpoint’s response.
Last thing to mention is that the shortcode guessing at the moment does not take into account the type of the Swagger model property. We plan to introduce the data type support later this year with respect to additional properties attributes like minimum/maximum number etc. It will be revised and a much better way of guessing the proper shortcodes for the imported dummy endpoint body. So, stay tuned and as usual we wish you a happy API mocking!