Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple API-Gateway codegen, suggestion #5034

Open
ppKrauss opened this issue Mar 12, 2017 · 3 comments
Open

Simple API-Gateway codegen, suggestion #5034

ppKrauss opened this issue Mar 12, 2017 · 3 comments

Comments

@ppKrauss
Copy link

Apache and Nginx have a lean language to express API Gateways,

Description

The "API Gateway" (at server-side) acts as a dedicated orchestration layer for all your backend APIs, to separate orchestration from implementation concerns. In this example the gateway is a Nginx script generated from the OpenAPI specifications of each microservice (adding some x- properties when need ... and perhaps some openapi-gateway.json file for complex cases).

EXAMPLE: extracted from here,

server {

   server_name petstore.swagger.io;
   root /var/www/petstore.swagger.io/html;

   # publishing by default the HTML for API description and related files for navigation
   index index.html index.htm;

   location / {
   	try_files $uri $uri/ @proxy;
   }

   location @proxy {
   	### endpoints defined by OpenAPI spec of this app:

   	rewrite    # endpoint "pets" for get,post
   	  ^/api/(pets?|darlings?)$
   	  http://localhost:3000/pets
   	  break;

   	rewrite    # endpoint "pets/{id}" for get,delete
   	  ^/api/pets/([0-9]+)
   	  http://localhost:3000/pets?id=eq.$1
   	  break;

   	# endpoint insects (automatic PostgREST) for get
   	
   	rewrite    # endpoint "fishes TO OTHER PROXY" for get
   	  ^/api/fishes
   	  http://localhost:4000
   	  break;

   	### default and auxiliar endpoint, for all other requests for PostgREST-queries
   	rewrite     ^/api/(.*)$      /$1     break;
   	
   	### proxy configurations:
   	proxy_pass  http://localhost:3000;  # my PostREST is  here!
   	...
   }
}

It is obtained by tpl01-baseBreak template and petstore-expanded.json as input.

Swagger-codegen version

Suggestion to add Apache-rewrite and Nginx-rewrite languages as new targets in codegen.

Swagger declaration file content or url

See this this adapted petstore-expanded.json example: with x-rewrite_regex , x-proxy_url and new endpoint adictions. The specific mustache templates generates the code.

Related issues

It is a enhance suggestion... How to discuss this kind of suggestion?

@wing328 wing328 added this to the v2.2.3 milestone Mar 13, 2017
@wing328
Copy link
Contributor

wing328 commented Mar 13, 2017

@ppKrauss thanks for the suggestion. I think it's a good idea 👍 and I'm sure developers are using Apache or Ngnix as API gateway would welcome the new generator to automate the config generation.

Let us know if you need help adding the new generators.

@ppKrauss
Copy link
Author

Thanks @wing328 (!)... Well, I need to do some homework and review contrib guide... But, ... hum, yes I need help to adding the new generators.

  • There are some client or server code here that is the "most similar" to my mustache needs?

  • How to, after git clone swagger-codegen, with simple command line (I have no Jave IDE!), in a UBUNTU 16 LTS, run the generator to do my tests?

@wing328
Copy link
Contributor

wing328 commented Jun 5, 2017

@ppKrauss sorry I missed your reply.

There are some client or server code here that is the "most similar" to my mustache needs?

I would suggest you start with the documentation generators, which generate only 1 or several files similar to configuration files that you want to generate.

How to, after git clone swagger-codegen, with simple command line (I have no Jave IDE!), in a UBUNTU 16 LTS, run the generator to do my tests?

Please do the following

git clone https://github.com/swagger-api/swagger-codegen
cd swagger-codegen
(make some changes)
mvn clean install -DskiptTests
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l new_generator_name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants