Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

herbs2swagger #9

Open
italojs opened this issue Oct 22, 2021 · 3 comments
Open

herbs2swagger #9

italojs opened this issue Oct 22, 2021 · 3 comments
Labels
enhancement New feature or request hacktoberfest ready-to-work Item is ready to work on it severity-nice-to-have Item is nice to have

Comments

@italojs
Copy link
Member

italojs commented Oct 22, 2021

I think would be great if we could to use the herbs2rest metadata to generate a swagger page and a SDK-client for apis.

Following the @expresso router lib from @roziscoding, it receive a openAPIspecification and the swagger lib generates the documentation aaaaand the SDK-client.
thinking in herbsjs, would be great if I give the route matadata for a usecase or routes so it generates a swagger endpoint into my Express app.

const express = require('express')
const { generateSwagger } = require('@herbsjs/herbs2swagger')

const app = express()
const openAPISpecifications =     {
      "title": "Sample Pet Store App",
      "description": "This is a sample server for a pet store.",
      "termsOfService": "http://example.com/terms/",
      "contact": {
        "name": "API Support",
        "url": "http://www.example.com/support",
        "email": "[email protected]"
      },
      "license": {
        "name": "Apache 2.0",
        "url": "https://www.apache.org/licenses/LICENSE-2.0.html"
      },
      "version": "1.0.1",
    "routes":     {
      "get": {
        "description": "Returns pets based on ID",
        "summary": "Find pets by ID",
        "operationId": "getPetsById",
        "responses": {
          "200": {
            "description": "pet response",
            "content": {
              "*/*": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Pet"
                  }
                }
              }
            }
          },
          "default": {
            "description": "error payload",
            "content": {
              "text/html": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorModel"
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "description": "ID of pet to use",
          "required": true,
          "schema": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "style": "simple"
        }
      ]
    }
generateSwagger(app, routes)

we could use it together herbs2rest like

const express = require('express')
const { generateRoutes } = require('@herbsjs/herbs2rest')
const { useSwagger } = require('@herbsjs/herbs2swagger')

const app = express()
const routes = new express.Router()

const metadatas = generateRoutes(controllerList, routes, true)
useSwagger(app,metadatas)

app.use(routes)
@italojs italojs added the enhancement New feature or request label Oct 22, 2021
@jhomarolo
Copy link
Contributor

I like the idea, but I think this could be a feature inside herbs2rest instead of a new library. What do you think?

@italojs
Copy link
Member Author

italojs commented Oct 25, 2021

I thought that too, but I think it could be used without herbs2rest, imagine the APIs that implements herbs but doenst use the herbs2rest yet, they can manually(or automatically) write the openAPISpecification so pass it to herbs2swagger, they dont need to do a big change into they projects to have a autogenerated swagger/sdk-client

@dalssoft
Copy link
Member

Nice idea!

I would start by making it part of herbs2rest in order to move fast, delivery value and, if it make sense, refactoring to split the glues in the future.

@jhomarolo jhomarolo added ready-to-work Item is ready to work on it severity-nice-to-have Item is nice to have labels Dec 24, 2021
@dalssoft dalssoft moved this to More discussion is needed in Herbs - 3rd Anniversary Edition May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest ready-to-work Item is ready to work on it severity-nice-to-have Item is nice to have
Projects
Status: More discussion is needed
Development

No branches or pull requests

3 participants