swagger-api / swagger-api/swagger-codegen

Simple API-Gateway codegen, suggestion

Open
#5,034 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: New generator General: Suggestion help wanted
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked tpl01-baseBreak.mustache template and petstore-expanded.json example, then review the x-rewrite_regex and x-proxy_url extensions used there. The issue does not name swagger-codegen files or tests, so the implementation entry point and acceptance checks would need to be established before work begins. Done would mean supported Apache and Nginx rewrite targets that generate the requested gateway configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
apache, nginx, openapi
Domain
api, backend-api-design, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.