Giter Site home page Giter Site logo

varghgeorge / microservices-single-swagger Goto Github PK

View Code? Open in Web Editor NEW
123.0 11.0 50.0 404 KB

Repository to showcase how to create a single/aggregate Swagger Documentation server for multiple microservices

License: MIT License

Dockerfile 100.00%

microservices-single-swagger's Introduction

microservices-documentation-server (swagger aggregate)

Repository to showcase how to create a SpringBoot Single/Aggregate SpringFox-Swagger Documentation Server for all your micro services.

Challenge:

SpringFox-Swagger generates different URL/document for each microservice. There is no way currently to view complete list of micro servies available or the details of all micro services at one place.

Solution:

'microservices-documentation-server' is a springboot application and creates a documentation server where all the available microservices can be accessed. On the springfox swagger documentation page from this documentation server, use will be able to view all the microservices available (drop down on top) and select any service to view the documentation without leaving the page.

Configuration:

In the application.yaml file, you can configure all your microservice swagger URLs. This is the only change we need to do.

documentation: 
  baseurl: http://localhost
  swagger: 
    services:   
      - 
        name: <Service 1>
        url: ${documentation.baseurl}:8040/v2/api-docs?group=service1
        version: 2.0
      - 
        name: <Service 2>
        url: ${documentation.baseurl}:8050/v2/api-docs?group=service2
        version: 2.0

If you would like to configure APIs from different servers, use complete URL.

      - 
        name: <Service 3>
        url: http://myserver.com/v2/api-docs?group=service3
        version: 1.0

Docker file is also available to create an image.

Sample screenshot of the swagger APIs dropdown from the configuration.
agreegate_sample

Future enhacements:
  • Enhance the application to retrieve the list from API Gateway or Registry (e.g. Eureka or Zuul) so that the list will be dynamic.
Remember:
  • If you use Zuul or Eureka, please add the dependency on it to and Application files.
  • Cross origin Resource Sharing (CORS) need to be enabled on the microservices server. Please let me know if you need details on how to configure the same in SpringBoot application.

Thanks to @dilipkrish (SpringFox Member) & @jhipster.

@dilipkrish mentioned that he is planning to add this to springfox swagger demos. So, you might be able to get this directly as part of swagger in future.

microservices-single-swagger's People

Contributors

amarkevich avatar varghgeorge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microservices-single-swagger's Issues

Help in configuring in spring boot application

Hi,

I have the exact requirement. I have tried running the application by changing the yml file according to my services. But am not able to get it working. Can you kindly help me in configuring in spring boot application.

Discovery Client issue while autowiring

When @Autowiring DiscoveryClient and ProxyRouteLocator getting error that "can not autowire as no bean of type found". Any idea what can be missing. I will post my configuration soon as I am traveling.
Can you please think anything about. I have all microservices in application.yml in zuul > service id and their paths.

How to add authorization header

I want to add authorization header to all microservices. Which will be intercepted at Gateway Proxy level.

I can do this using following piece of code without aggregation.

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any()).build().pathMapping("")
            .securitySchemes(Arrays.asList(apiKey()));
    }

    private ApiKey apiKey() {
        return new ApiKey("authkey", "Authorization", "header");
    }

But when I use public class SwaggerAggregatorController implements SwaggerResourcesProvider { the authorization button does not show up on the UI.

CORS Issue in accessing individual Swagger Documentation Page in Microservice

Hello there,
Good swagger app, but I cannot get it to work.
I have configured it as per readme, but I am getting the following error in my google debugger tool:

XMLHttpRequest cannot load http://localhost:60816/employee-ms/v2/api-docs?group=employee. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8014' is therefore not allowed access. The response had HTTP status code 404.

I did enable CORS in my springboot microservice as follows:

@RestController
@RequestMapping(path = "/employee")
@crossorigin(origins = "*", maxAge = 3600)
public class EmployeeController {

}

Please, any help will be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.