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

Allow use of 'serverless-http' when reading functions #85

Open
SebaSOFT opened this issue Aug 16, 2022 · 7 comments
Open

Allow use of 'serverless-http' when reading functions #85

SebaSOFT opened this issue Aug 16, 2022 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@SebaSOFT
Copy link

SebaSOFT commented Aug 16, 2022

Currently the plugin does not support proxy installations with custom handlers. This is understandable but many templates for "express.js project for lambda functions" come with this feature built in. As the handler should be available for the plugin API I wanted to show my setup:

in my serverless.yml

...
plugins:
  - serverless-auto-swagger
  - serverless-dotenv-plugin
  - serverless-webpack
  - serverless-offline
  - serverless-plugin-scripts
  - serverless-apigw-binary
...
functions:
  app:
    handler: app.serverless # reference the file and exported method
    events:
      - http:
          path: / # this matches the base path
          method: ANY
      - http:
          path: /{proxy+} # this matches any path, the token 'any' doesn't mean anything special
          method: ANY

and then on app.js

const sls = require('serverless-http');
...
...
...
module.exports = app;
module.exports.serverless = sls(app);

With this setup, the sls generate-swagger command will generate a json description that looks like this:

{
  "swagger": "2.0",
  "info": {
    "title": "swagger",
    "version": "1"
  },
  "paths": {
    "/": {
      "any": {
        "summary": "app",
        "description": "",
        "operationId": "app.any./",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "security": [
          {
            "Authorization": [],
            "x-api-key": []
          }
        ]
      }
    },
    "/{proxy+}": {
      "any": {
        "summary": "app",
        "description": "",
        "operationId": "app.any./{proxy+}",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "proxy+",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "security": [
          {
            "Authorization": [],
            "x-api-key": []
          }
        ]
      }
    }
  },
  "definitions": {},
  "securityDefinitions": {
    "Authorization": {
      "type": "apiKey",
      "name": "Authorization",
      "in": "header"
    },
    "x-api-key": {
      "type": "apiKey",
      "name": "x-api-key",
      "in": "header"
    }
  },
  "basePath": "/"
}

But the expected result would be that the plugin generates a json that would be representative of the express app which is distributed in many files/folders for big APIs.

Tested with node/lambda

@bfaulk96
Copy link
Collaborator

bfaulk96 commented Aug 16, 2022

I'm not following what the question is here.

Are you saying you'd expect the output to look like the code you posted?
Or are you saying the output currently looks like the code you posted?

@SebaSOFT
Copy link
Author

Sorry about my english and lack of clarity. I updated the OP to be more descriptive. Congratulations BTW as this project is a great plugin that allows for keeping the source project nice a tidy without Swagger UI's custom CSS/JS/HTML laying around

@bfaulk96
Copy link
Collaborator

bfaulk96 commented Aug 23, 2022

In what order are your serverless plugins?

If serverless-auto-swagger is before serverless-http, it would almost certainly need to come after it.

If you already have serverless-auto-swagger after serverless-http, I'm afraid this probably cannot be avoided, as serverless-auto-swagger builds the swagger docs off of the serverless config supplied to it.

@SebaSOFT
Copy link
Author

In what order are your serverless plugins?

If serverless-auto-swagger is before serverless-http, it would almost certainly need to come after it.

If you already have serverless-auto-swagger after serverless-http, I'm afraid this probably cannot be avoided, as serverless-auto-swagger builds the swagger docs off of the serverless config supplied to it.

I've added my plugins list

@bfaulk96
Copy link
Collaborator

Ah, yeah.. If serverless-http is not a serverless plugin (and therefore would happen after serverless plugins are installed), then I don't know that there's any way to do what you're requesting.

Perhaps if we exposed a function to generate autoswagger via Node?

@SebaSOFT
Copy link
Author

serverless-http is not a plugin, but a handler to be invoked by the schema handler to generate a "final" lambda functions list. Autoswagger via node is always nice

@bfaulk96 bfaulk96 added enhancement New feature or request help wanted Extra attention is needed labels Aug 30, 2022
@bfaulk96
Copy link
Collaborator

Right, auto-swagger via node would probably be the only way to make what you're asking possible. I unfortunately don't have a lot of free time right now, but PRs are always welcome 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants