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

Improvement: Specify stages for excluding swagger endpoints #46

Closed
jochembeetz opened this issue Feb 22, 2022 · 8 comments · Fixed by #47
Closed

Improvement: Specify stages for excluding swagger endpoints #46

jochembeetz opened this issue Feb 22, 2022 · 8 comments · Fixed by #47

Comments

@jochembeetz
Copy link
Contributor

As of right now, swagger endpoints are always added. I want my swagger to only be generated and/or deployed when the stage is development or staging.

Suggestion:

custom:
  autoswagger:
      stages:
         - staging
         - development
@bfaulk96
Copy link
Collaborator

I would think you could already do that with something like

Serverless 2.0.0:

custom:
  generateSwagger:
    staging: true
    development: true
    prod: false
  autoswagger:
    generateSwaggerOnDeploy: ${{self:custom.generateSwagger.${{self:provider.stage}}}} 

Serverless 3.0.0:

params:
  default:
    generateSwagger: false
  staging:
    generateSwagger: true
  development:
    generateSwagger: true
custom:
  autoswagger:
    generateSwaggerOnDeploy: ${param:generateSwagger}

@bfaulk96
Copy link
Collaborator

Would you mind checking and letting me know?

@jochembeetz
Copy link
Contributor Author

jochembeetz commented Feb 22, 2022

Thanks for your quick response.
I'm sorry I was not clear enough, I meant i don't want swagger endpoints to be: added to my lambda functions / deployed in specific stages.

P.S. I tested the above (Serverless 2.0) with config:

custom:
  generateSwagger:
    staging: true
    development: false
  autoswagger:
    generateSwaggerOnDeploy: ${{self:custom.generateSwagger.${{self:provider.stage}}}}
    schemes: ['https', 'http']
    apiType: http
    apiKeyHeaders: ['Authorization']
    basePath: /installation

serverless deploy --stage development still generates and adds swagger endpoints

@jochembeetz jochembeetz changed the title Improvement: Specify stages for creating swagger endpoints Improvement: Specify stages for adding swagger endpoints Feb 22, 2022
@jochembeetz jochembeetz changed the title Improvement: Specify stages for adding swagger endpoints Improvement: Specify stages for excluding swagger endpoints Feb 23, 2022
bfaulk96 added a commit that referenced this issue Feb 23, 2022
* feat: Only deploy swagger on specified stages (#46)

* Refactor to excluded stages

* update readme with excludeStages option

* Update src/ServerlessAutoSwagger.ts

Co-authored-by: Brandon Faulkner <[email protected]>

* Update src/ServerlessAutoSwagger.ts

Co-authored-by: Brandon Faulkner <[email protected]>

Co-authored-by: jochem <[email protected]>
Co-authored-by: Brandon Faulkner <[email protected]>
@sunilnalumachu
Copy link

Did you found solution for deploy swagger on specified stages, I tried above comment
custom:
generateSwagger:
staging: false
development: false
prod: false
autoswagger:
generateSwaggerOnDeploy: ${{self:custom.generateSwagger.${{self:provider.stage}}}}

But Did Not worked still deploying the swagger doc, Is there any way we can stop deploying swagger doc, while sls deploy.

@bfaulk96
Copy link
Collaborator

@sunilnalumachu please refer to the documentation rather than this thread for the final implementation. The config mentioned in your comment is not expected to work. See excludeStages in the README.

@sunilnalumachu
Copy link

@bfaulk96 I tried that before but want to understand more on stages, like which params you support. I am currently using my local stage env in excludeStages array like this.
excludeStages: ['mytestStage', 'prod'].

can you give some examples what are the stages you exclude and can i use my local stage to exclude while sls deploy.

@Jon-Berg
Copy link

Jon-Berg commented Apr 27, 2022

@sunilnalumachu please refer to the documentation rather than this thread for the final implementation. The config mentioned in your comment is not expected to work. See excludeStages in the README.

@bfaulk96
I tried using excludeStages: ['prd'] and weirdly, instead of not deploying the swagger lambdas to prd stage,
It did deploy them, and named them with dev stage prefixes.

So I think I'll temporarily use this workaround - #46 (comment)

Edit:
Now I've realized that it happens because the plugin assumes I put the stage name under provider, but we use it only from ${opt:stage}

@bfaulk96
Copy link
Collaborator

I'll look into updating that to support opt:stage and sls:stage as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants