swagger-api/swagger-codegen

Simple API-Gateway codegen, suggestion

Open

#5,034 创建于 2017年3月12日

在 GitHub 查看
 (3 评论) (2 反应) (0 负责人)HTML (12,701 star) (5,474 fork)batch import
Enhancement: New generatorGeneral: Suggestionhelp wanted

描述

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?

贡献者指南