SpringBoot Swagger UI - Get swagger.json of specific Controller - spring-boot

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)

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)

Adding a parameter by default to all API calls in Swagger UI

I want to use Swagger UI with Jersey REST APIs. I want to add an extra parameter to all APIs in Swagger UI but don't want to change the APIs itself(don't want to add corresponding #QueryParam in APIs).
How can I achieve this?
Swagger version i'm using: v2.1.4

swagger ui without swagger auto apidoc json generation

I'd like to use the nice io.springfox:springfox-swagger-ui interface but I don't want to have my documentation auto generated via annotations in my springboot app (/v2/api-docs).
I have my proper swagger-api.json api description file under my project resources, how can I tell swagger-ui to use it as default ?
I tried to use: springfox.documentation.swagger.v2.path=/swagger-config.json as swagger properties but it does not use my file.

Spring HATEOAS Linking to Another Service

Spring HATEOAS works great at linking to another method in the same application. For example:
Greeting greeting = new Greeting(String.format(TEMPLATE, name));
greeting.add(linkTo(methodOn(GreetingController.class).greeting(name)).withSelfRel());
If one were to implement a microservice architecture, then most of the linked methods would be part of a different service and different Java project.
The only way I can see of to add a link to a method outside of the existing project is to hard-code in the URL (or put it in an external configuration).
Are there any alternatives to dynamically create the URL? For instance, is it possible to use Spring HATEOAS in conjunction with a Service Registry (like Eureka)?

Mocking Rest Api with Swagger Documentation

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

Resources