Coder Social home page Coder Social logo

thanhson1085 / swagger-combined Goto Github PK

View Code? Open in Web Editor NEW
110.0 11.0 29.0 2.89 MB

Combines all swagger documents in microservices

License: MIT License

JavaScript 95.81% HTML 0.19% Shell 0.01% CSS 3.96% Dockerfile 0.04%
microservice proxy swagger-documentation

swagger-combined's Introduction

Build Status

NPM

If you are building a microservice system and using Swagger.

This packet is able to help you combine all swagger documents to only one document.

For example, you have the swagger documents at http://service1/docs, http://service2/docs

This will help you combine all links above to only one link http://service/docs

NOTE: If you need Gulp, ES6 and somethings more, please see branch added_gulp

Installation & Run from Docker

docker run -d -p 3000:3000 thanhson1085/swagger-combined

Configuration file

See config/default.json as below:

{
    "list_url": [
        {
            "docs": "http://petstore.swagger.io/v2/swagger.json",
            "base_path": "http://petstore.swagger.io/v2",
            "route_match": ["/user*", "/pet*", "/store*"]
        }
    ],
    "info": { "title": "Example API", "version": "1.0" },
    "port": 3000
}
  • docs: swagger document links
  • base_path: Proxy Target
  • route_match: Routes for proxy

Please make note that you changed config/default.json to match all swagger document links you have

Installation & Run from Source Code

git clone https://github.com/thanhson1085/swagger-combined.git

Run:

cd swagger-combined
npm install
node index.js

Test

In the default, swagger-combined run on port 3000 and included swagger-ui. So you just run http://localhost:3000?url=http://localhost:3000/docs to see everything you need. Or you can see swagger api at http://localhost:3000/docs

Example & Demo

With config/default.json:

{
    "list_url": [
        {
            "docs": "http://petstore.swagger.io/v2/swagger.json",
            "base_path": "http://petstore.swagger.io/v2",
            "route_match": ["/user*", "/pet*", "/store*"]
        },
        {
            "docs": "https://angular-admin-seed.sonnguyen.ws/docs",
            "base_path": "https://angular-admin-seed.sonnguyen.ws",
            "route_match": ["/api/v1*"]
        }
    ],
    "info": { "title": "Example API", "version": "1.0" },
    "port": 3000
}

License (MIT)

Copyright (c) 2015 Nguyen Sy Thanh Son [email protected]

swagger-combined's People

Contributors

dependabot[bot] avatar lukemcgregor avatar sylwit avatar thanhson1085 avatar thurstonsand avatar uvtrip 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

swagger-combined's Issues

Calls are going on internal server in place of swagger base path

It seems all call are going on localhost or if keeping on server then server url when swagger "Try it out" button clicked where it should point to given swagger url.

Steps:
In default json added swagger json and base path for my service and ran the application. Now if -

  1. Using http://localhost:3000 then it is going to harcoded pet side where everything works fine
  2. Using http://localhost:3000/?url=http://localhost:3000/docs Then it shows correct endpoints but calls are going on localhost or swagger-combined application url instead swagger base path.

No newline in description

"info": { "title": "Client Gateway Documentationz", "version": "1.0",
    "description": "Hello<p>World " },

}

Expected to write hello and World on separate lines but they end up on the same.

forEach without an array

It looks like in your last check-in, something got broken. Either the example config is off or the program is off. On line 46 of app.js, it is doing a forEach on whatever is in route_match in the config. route_match is not an array, so the line fails.

I fixed that and am able to get the code to run, but it still doesn't work. I am getting a 404.

This looks cool. I'd love to see it working.

Two microservices with different endpoint, but same services & similar path

I have 11 microservices in my project for the most part your application is working fine.

But one of those microservies is a facade for one of of those other modules.

My configuration is as follows

{
    "docs": "http://${COMMON_CORE_HOST}/core-facade/swagger.json",
    "base_path": "http://${COMMON_CORE_HOST}/core-facade",
    "route_match": ["/facade*"]
}

and

{
    "docs": "http://${MIGRATION_HOST}:${MIGRATION_PORT}/core-migration/swagger.json",
    "base_path": "http://${MIGRATION_HOST}:${MIGRATION_HOST_PORT}/core-migration",
    "route_match": ["/migration*"]
}

URL's are very similar in both services i.e.:
http://{{url}}/core-migration/migration/migrate/
http://{{url}}/core-facade/migration/migrate/

For some reason swagger-combined can't tell the different and only one of the modules is listed in the docs. In my case it's the migration module. When I slightly change the URL for the facade it's working in both modules.

To sum it up... different endpoints... same url schema... only one of the endpoints is recognized by swagger-combined. When I change one character making the paths to be different... everything works fine.

Any tips how to fix that?

the node command runs forever

Hello,

I've built the microservices using service fabric and they are currently deployed on my local cluster. I wanted to aggregrate the documentation and see the result. I installed swagger nuget package in the service layer and now I'm running your module. Here is how the json file looks like for me:

{

"list_url": [
    {

 "docs": "http://localhost:8622/swagger/docs/1.0,",

  "base_path": "http://localhost:8622",

  "route_match": ["/api/*"]
    },

{

"docs": "http://localhost:8625/swagger/docs/1.0,",

"base_path": "http://localhost:8625",

"route_match": ["/api/*"]

}

],

"info": { "title": "Documentation Demo API", "version": "1.0" },

"port": 3000
}

However the node command is running forever giving message "Combining swaggers http://::::3000"

Do you have any idea of why its not working.

Regards
Neeti

Swagger-Combined not working on Linux

First, I will say thanks for sparing time to provide this solution.
I had this app working on my mac laptop connecting to remote services i.e. it was combining docs from different micro services on a remote server.
I ran the following to ensure the relevant software was installed on the server.
node -v > v0.10.46
npm -v > 1.3.6

Now, I deployed the node.js app to that same remote server with the services and I was getting the following error;

ReferenceError: Promise is not defined
at checkConfig (/home/olakunle/microservices-swagger-ui/routes/swagger.js:33:14)
at genDocs (/home/olakunle.tomoloju/discr-microservices-swagger-ui/routes/swagger.js:64:10)
at agent (/home/olakunle/microservices-swagger-ui/routes/app.js:49:24)
at Layer.handle as handle_request
at next (/home/olakunle/microservices-swagger-ui/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/olakunle/microservices-swagger-ui/node_modules/express/lib/router/route.js:112:3)
at Layer.handle as handle_request
at /home/olakunle/microservices-swagger-ui/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/home/olakunle/microservices-swagger-ui/node_modules/express/lib/router/index.js:330:12)
at next (/home/olakunle/microservices-swagger-ui/node_modules/express/lib/router/index.js:271:10)

I would love to use the docker, but the lack of docker instruction did not help!
I was trying to use the following docs:

https://nodejs.org/en/docs/guides/nodejs-docker-webapp/

But, i notice you have a dockerfile and a dockershell, but i could not use that. I thought that will be ideal for running in the app on a linux VM.

YAML files in docs?

Is swagger-combined going to support YAML files as docs in configuration?

Npm install fails v1.4.2

fetchMetadata: ERR! registry error parsing json

Seems like dependency issue? Your package.json is fine

stuck in "fetching resource list"

Hello,

I'm having issues using swagger-combined, i have 2 microservices hosted on the same server, what changes is just the endpoint, something like this:

    {
       "docs": "https://myhost/service1/swagger/v1/swagger.json",
        "base_path": "myhost/service1/",
        "route_match": ["/api/service1*"] 
    },
    {
        "docs": "https://myhost/service2/swagger/v1/swagger.json",
        "base_path": "myhost/service2/",
        "route_match": ["/api/service2*"] 
    }

when i start the application, it get stuck in "fetching resource list", no error on browser's console.

any tips on this?

Npm install fails

Installing the module in a fresh Sails.js project and getting the following error:

npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN skippingAction Module is inside a symlinked module: not running add [email protected] node_modules/abbrev
npm WARN skippingAction Module is inside a symlinked module: not running move [email protected] node_modules/nopt
npm WARN skippingAction Module is inside a symlinked module: not running remove [email protected] node_modules/sails/node_modules/grunt-contrib-watch/node_modules/tiny-lr/node_modules/noptify/node_modules/nopt/node_modules/abbrev
npm ERR! Linux 4.2.0-42-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "swagger-combined" "--save"
npm ERR! node v4.4.2
npm ERR! npm  v3.10.6
npm ERR! path /home/***/Desktop/***/swagger-service/node_modules/swagger-combined/run.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod

npm ERR! enoent ENOENT: no such file or directory, chmod '/home/***/Desktop/***/swagger-service/node_modules/swagger-combined/run.js'
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/***/Desktop/***/swagger-service/node_modules/swagger-combined/run.js'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /home/***/Desktop/***/swagger-service/npm-debug.log

tags array should merge between specs

Only the tags from the first swagger spec to be loaded are included in the final "combined" spec. It would be ideal if all tags were merged. Will try to solve this myself, but I wanted to see if anyone had a solution before I do.

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.