Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Klunder committed Apr 30, 2018
1 parent 95eaf36 commit ecb8af1
Show file tree
Hide file tree
Showing 9 changed files with 2,523 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Fastify swagger code generator

This repository contains an experiment to see if its possible to take a swagger file (v2) and autogenerate a configuration for fastify.

The result is quite simple:

* [index.js](index.js) loads the swagger file feeds it to the [parser](parserv2.js) and uses the result to generate the routes.

* The `definitions` section of the swagger specification is loaded in AJV to be able to resolve `$ref` schema references. AJV itself misses some format handlers so [ajv-oai](https://www.npmjs.com/package/ajv-oai) is being used as it adds the missing OpenApi formats.

* For each route the parser has determined an `operationId`, either taken from the swagger definition or generated by the parser.

* The `Service` class in [service.js](service.js) holds the implementation of the service (e.g. the business logic). When generating the routes the service is checked for methods with the same name as the `operationId` which are then attached as handler. When not available, a "not implemented" handler is attached to the route.

* [generator.js](generator.js) can be used to generate the `Service` class. The generator can be extended to add information about parameters, information in comments etc.
Loading

0 comments on commit ecb8af1

Please sign in to comment.