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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With