json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Generating OpenAPI Swagger definition from JSON-Server

Open MartinMuzatko opened this issue 4 years ago • 4 comments

Hi! I'm building a layer on top of json-server to dynamically add new lists (arrays) to the json file. It would be nice to generate a Swagger/OpenAPI documentation based on the plural/singular router settings.

Since the json-server is dynamic, this should be a function provided to generate the spec

MartinMuzatko avatar Apr 21 '21 08:04 MartinMuzatko

That would be a great feature

cristian-darwoft avatar Aug 19 '21 14:08 cristian-darwoft

Hi there, has anyone been working on this ? If not I could give it a try 🙂

codams avatar Mar 04 '22 11:03 codams

@codams can you start with this? How can I help you?

AlexScigalszky avatar Mar 30 '22 10:03 AlexScigalszky

Might the following project be of any use express-oas-generator (EOG)?:

How does it work?

  • During initialisation module iterates through all routes and methods and initialises OpenAPI (Swagger) specification.
  • After an application start module analyse every request/response and fills specification with schemes and examples.
  • Module replace values of password fields with ******

So EOG seems to be a set of Express middleware that can invoke and document Express server routes and generate OpenAPI documentation out of a json-server instance.

I haven't used this in anger myself, I was merely investigating getting a Swagger/OpenAPI spec out of an updated json-server API, your mileage may vary.

At a minimum, it should be possible to integrate this middleware readily into code embedding a json-server-express instance, in your own personal projects, although a new CLi option, employing this, might not be too difficult to develop, either.

It might also be possibly use the --middlewares, -m CLi option of json-server to simply pass your own my-oas-middleware.js implementing file, containing references to EOG. I'm not too sure about any potential import resolution issues (I'm new to json-server).

sixman9 avatar Aug 19 '22 00:08 sixman9