Skip to content

Convert a Swagger/OpenAPI schema to a new L³ application. ⚠️ Work In Progress ⚠️

License

Notifications You must be signed in to change notification settings

lambda-lambda-lambda/swagger-converter

Repository files navigation

L³ Swagger converter

Convert a Swagger/OpenAPI schema to a new application. ⚠️ Work In Progress ⚠️

How it works

This command-line script parses the supported schema definitions (e.g API General Info, Paths and Operations) and scaffolds a new L³ application with predefined route/resource handlers.

For example, the JSON schema definition below, when parsed..

"/example/{resourceId}": {
  "put": {
    "description": "Example using `Route.create` handler alias.",
    "parameters": [
      {
        "in": "path",
        "name": "resourceId",
        "schema": {
          "type": "string"
        }
      }
    ],
    "responses": {
      "201": {
        "description": "Returns JSON response.",
        "headers": {
          "Content-Type": {
            "schema": {
              "type": "string",
              "example": "application/json"
            }
          }
        }
      }
    }
  }
}

would create a file in path <AppName>/routes/Example.js with the following:

module.exports = {
  resource: ['create'],

  /**
   * @openapi
   *
   * /example/{resourceId}:
   *   get:
   *     description: Example using `Route.index` handler alias.
   *     responses:
   *       201:
   *         description: Returns JSON response.
   *         content:
   *           application/json:
   *             schema:
   *               type: object
   *               properties:
   *                 name:
   *                   type: string
   *         headers:
   *           Content-Type:
   *             schema:
   *               type: string
   *               example: application/json
   */
  index (req, res) {
    res.status(200).send(req.param());
  }
}

Dependencies

Developers

CLI options

Compile JavaScript sources from TypeScript to a distribution:

$ npm run compile

Compile and listen for changes (development mode):

$ npm run watch

Run ESLint on project sources:

$ npm run lint

Run Mocha integration tests:

$ npm run test

Author

Marc S. Brooks

About

Convert a Swagger/OpenAPI schema to a new L³ application. ⚠️ Work In Progress ⚠️

Resources

License

Stars

Watchers

Forks