swaggest / swac

🤖 OpenAPI/Swagger client generator for PHP, Go and JavaScript (ES5)
MIT License
9 stars 3 forks source link

Create krakend endpoint #24

Closed egandro closed 3 years ago

egandro commented 3 years ago

I am looking for a GO project where I can hook in.

We have multiple openapi.json files of multiple Microservices.

We are using krakend as API gateway. Krakend has a sweet and simple configuration. So my idea is to generate code for the endpoints and do some filtering out of the openapi specs. So sort of a code generator like you have.

Check the config of Krakend:

https://www.krakend.io/docs/configuration/flexible-config/

Relevant example: (real world might have 200+ endpoints)

{
    "example_group": [
        {
            "method": "GET",
            "endpoint": "/users/{id}",
             "host": [
                        "http://127.0.0.1:8012",
                        "backend": "/users/id}"
              ]
        },
        ...
        {
            "method": "POST",
            "endpoint": "/posts/{id}",
             "host": [
                        "http://127.0.0.1:8010",
                        "backend": "/posts/{id}"
              ]
        }
    ]
}

So the generator is very simple - no DTOs just the Method, Route, URL Parameters.

However - we might need to filter it. E.g. "Only add that route, if a Swagger/OpenAPI Tag matches"

u.SetTags("API-Gateway-Moblie")

So this route should be added.

Maybe some shaping of routes is required e.g. add a "/vi" to some paths in the json.

Can this be added into swac?

At the moment I am using some nodejs tool. But I would love having a GO version.

vearutop commented 3 years ago

Sorry, I failed to understand this issue and what is needed. Could you explain again with different words? 😅

Do you need a filter like

   --operations <operations>               Operations filter in form of comma-separated list of method/path, default empty                  

but based on OpenAPI tags instead of method/path?

egandro commented 3 years ago

I finieshed my own project :)

Check this:

I define an inputfile: https://github.com/egandro/microservice-playground/blob/master/microservices/api-gateway.json

This points to a bunch of OpenAPI endpoints to microservices.

I run "make update-krakend-config". This will download all openapi.jsons of the microservices. It filteres out e.g. Serices that are marked "x-internal". It creates a endpoint.json for krakend and a joined (filtered) openapi.json.

Conclusion. I can have a API-Gateway in a pure declarative way. Just using the OpenAPI.json and transform them.

In the end I didn't use your project, because I hacked my own implementation for parsing OpenAPI files.