Mocking Rest Api with Swagger Documentation - spring

Whole idea is to create Mock service for UI guys to test without actual api.
- We have define specification in .ymcl files.
- Now want to generate Swagger-UI and Mock rest URI with mock data.
- Using spring-boot.
Please suggest some way to generate the same.

Given that you've the API documented in Swagger/OpenAPI spec (YAML format), you can use Swagger Codegen to generate Spring boot server stub.
Please pull the latest master of https://github.com/swagger-api/swagger-codegen and follow the instruction in the wiki:
https://github.com/swagger-api/swagger-codegen/wiki/Server-stub-generator-HOWTO#java-springboot

Related

How to generate an OpenAPI from a Spring app without running the app?

I can run a Spring Boot application and then use the springdoc-openapi-maven-plugin artifact to generate an OpenAPI spec.
However, is there also a way to generate the spec without running the application first?
I currently want to generate the spec in a GitHub Action and a direct way would simplify this a lot.
you can use swagger editor: https://editor.swagger.io/
It allows you to write a json/yaml with your specifications and at the same time you can view the result.
Also, in the upper part there are 2 features, which allow you to generate the code based on the json/yaml made.
For example you can create a spring application with all the endpoints you go to specify in your json/yaml ( server).
But you can also generate HTML. (Client)

SpringBoot Swagger UI - Get swagger.json of specific Controller

I have a SpringBoot Application which implements many Rest Controllers exposing multiple endpoints.
Each Rest Controller expects requests from a different Application/System, let's say:
RestControllerA - Called by System A
RestControllerB - Called by System B
...
Swagger provides the /api-docs endpoint, which provides the swagger.json for all RestControllers.
Is there a way to generate and provide the swagger.json to each system, only for the RestController it is interested into? For example I want to generate the swagger.json only for RestControllerA.
Adding to this, is there a way to generate the swagger.json for a specific endpoint of a controller?
(I'm using the springfox-boot-starter:3.0.0 dependency)

Quarkus+Apache Camel+Swagger ui

I'm currently working on Quarkus with swagger ui and followed a link to test it below link successfully https://quarkus.io/guides/openapi-swaggerui.
but is there any way to implement apache camel route with swagger ui in quarkus? kindly help me.
If you add the camel-quarkus-openapi-java extension to your application, then you can add documentation to your REST DSL routes and have it rendered as an OpenAPI document. There's more information on how to do this here:
https://camel.apache.org/manual/latest/rest-dsl.html
Then you can configure the default URL that the Swagger UI points to.
For example, assuming you configured your Camel OpenAPI documentation to be served at /openapi.yaml, you can configure the Quarkus Swagger UI extension to consume it.
camel.rest.api-context-path = /openapi.yaml
quarkus.swagger-ui.urls.camel = /openapi.yaml

Auto generate REST api documentation into RAML from Spring MVC controllers

I am new to Spring-Boot. I want to auto generate my REST api documentation into RAML from my Spring MVC controllers. Is there anything to do that? or any guide that I could use it for generating my rest api into RAML?
There is a Spring REST Docs to RAML extension for Spring REST Docs: https://github.com/ePages-de/restdocs-raml However, this project is not maintained anymore and the authors recommend to use their new project https://github.com/ePages-de/restdocs-openapi that converts to OpenAPI (Swagger) instead of RAML. They provide a guide on how to convert OpenAPI to RAML: https://github.com/ePages-de/restdocs-openapi#convert-to-raml There is an example project that demonstrates the conversion to OpenAPI and RAML https://github.com/ePages-de/restdocs-openapi/tree/master/samples/restdocs-openapi-sample One limitation of the extension is that it only works with Gradle at the moment.
I know, your Question is outdated, but there is something that might help.
You can use DocDog. From there it creates RAML from the existing source code. If it is SpringBoot you can run it easily with -lang=spring. If it is plain JAVA you can add comments to your code (see readme.md or examples), so DogDoc can understand.
May it helps you: https://github.com/skalski/docdog

Swagger client generation with Spring REST Docs

I have seen this Spring REST Docs - video
We are doing Spring boot projects and are using springfox library for generating the Swagger-ui and swagger documentation as outlined here
We like what Spring Rest docs can do for generating REST API documentation and the fact that we don't have to add swagger annotations like #ApiResponse or #ApiOperation in our Controller code. And also the fact that the documentation now lives with the code.
But if go with Spring Rest docs, we will miss out on the Swagger-UI that gets automatically generated for our API (when we use swagger integration).
Is it possible for Spring REST docs to generate a test UI like Swagger UI.
That pretty directly goes against the design idea and intention of Spring REST Docs. One of the main goals of it is that the docs are tied to unit tests so you know your documentation is rock solid even when you make logic or signature changes in your REST contract.
Also as the video you linked to provided a number of examples of how automated docs generation produces a lot of undesirable un-intended output.
So its a choice of do more work to get much better docs, or do the fully automated option to save time and get workable, but lower quality docs. It is what ever your priority is.
This project generates an OpenAPI specification from Spring REST Docs.
https://github.com/ePages-de/restdocs-api-spec

Resources