Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide OPTIONS endpoint from Swagger UI using serverless

I have set cors: true for each endpoint in the serverless YAML file. However, I do not want to show "OPTIONS" endpoint in the swagger UI for the same. I am using the serverless framework and below is the code for sample endpoint:

sample name:
    handler: path/to/the/handler/
    events:
      - http:
          path: v1/sample
          method: get
          cors: true
          private: true
          documentation:
            summary: "summary of the endpoint"
            methodResponses:
              - statusCode: "200"
                responseBody:
                  description: "response body"
                responseModels:
                  "application/json": "response model"

I am expecting that OPTIONS should NOT be visible on Swagger UI despite the CORS is enabled.

like image 897
Ripundeep Gill Avatar asked Jul 25 '26 12:07

Ripundeep Gill


1 Answers

Technically the OPTIONS method endpoint is necessary for CORS to function correctly as it's the method used in the Preflight request that checks CORS viability.

AWS Swagger exports do include the OPTIONS endpoint in quite an intrusive way. If you don't want it in your Swagger UI I suggest you programmatically filter the OPTIONS endpoints out of the Swagger file after exporting it from API Gateway, before using it for Swagger UI (depending on how you construct your Swagger UI).

like image 195
jlaitio Avatar answered Jul 28 '26 02:07

jlaitio