Automatic Documentation - Generate Swagger UI from your Serverless Config

Поделиться
HTML-код
  • Опубликовано: 8 ноя 2021
  • If you want to automatically generate documentation for your serverless project then you can use the "serverless-auto-swagger" to do just that.
    `npm install -D serverless-auto-swagger`
    If you want to have a text based version of this article then you can read it here.
    www.completecloudarchitects.c...
    If you want to look at the underlying code, want to submit a bug or issue, or even want to contribute then the link to the github is here:
    github.com/SamWSoftware/serve...
  • НаукаНаука

Комментарии • 124

  • @pavelrazuvalau4164
    @pavelrazuvalau4164 Год назад +11

    In case the plugin deploys Swagger UI at a different host than your application's one. I figured out how to make the plugin deploy Swagger UI at the same host as your application. You most likely want to add apiType: 'http' to the plugin configuration section. It works for me. Additionally, don't forget to add basePath if you use a custom stage. Please rate the comment, so everyone else can see the possible solution for their headache.

    • @DJ-pf1xe
      @DJ-pf1xe Год назад

      You can share your solution on stackoverflow

    • @i_mayanktyagi
      @i_mayanktyagi Год назад

      very helpful

  • @chanyounglee8914
    @chanyounglee8914 2 года назад +2

    Awesome! I have question.
    How can I specify the "Example Value" without using the default value of type??

  • @johnsstudies4335
    @johnsstudies4335 Год назад +1

    Hi Sam great plugin!
    But i am having a little issue here when I created a type file I tried to extend a class into a Interface but doesnt seems to work am I missing something?

  • @abrahamgonzalez7704
    @abrahamgonzalez7704 Год назад

    From Mexico, you are the goat

  • @renatomoreira8587
    @renatomoreira8587 3 месяца назад

    thank you. I wanst understanding how to specify bodyType until your explanation

  • @naveensaini1618
    @naveensaini1618 2 года назад

    thanks you for your support my friend

    • @CompleteCoding
      @CompleteCoding  2 года назад

      Thanks for watching and commenting on the videos. It really does help

  • @PrateekKumarS
    @PrateekKumarS Год назад

    Thanks for the introduction to this Plugin Sam. Could you share an example where GET call with Query Params is also present - as of now its mostly GET with path params and POST calls. :) :) You are doing an awesome job there, so much to learn.

    • @CompleteCoding
      @CompleteCoding  Год назад +1

      I think there are some examples using query strings in the docs of the plugin

  • @mateoloaizarios2476
    @mateoloaizarios2476 Год назад

    Hi Sam! At the moment of deploy, the swagger documentation is deployed in a different API Gateway because add *dev-{service-name}* exist some way for delete the stage before *{service-name}*

  • @mozesong5264
    @mozesong5264 2 года назад +1

    Amazing work Sam! I Been looking for a solution for API documentation.

    • @CompleteCoding
      @CompleteCoding  2 года назад

      It's something that I've thought about for ages. Why define your api once for serverless and repeat yourself for documentation

    • @mozesong5264
      @mozesong5264 2 года назад

      @@CompleteCoding Yup! Anyway, I realised that there is no link to your github repo for the code on NPM, could you list your github repo there incase anyone wants to open issues or get help? Thanks

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      Just added the link to the video description
      github.com/SamWSoftware/serverless-auto-swagger

  • @hermersonaraujo1671
    @hermersonaraujo1671 2 года назад

    Thanks man, you save my life!

  • @febinr8888
    @febinr8888 2 года назад +4

    Great work Sam.. Really Helpful.
    I have one question: will it identify query parameters of the request?

    • @CompleteCoding
      @CompleteCoding  2 года назад

      That's a really good question. At the moment it doesn't but that is definitely a feature I could add.
      Would you think it better to do it like this
      {
      path: '...',
      queryParameter: ApiQueryParamType
      }
      or something else?

    • @febinr8888
      @febinr8888 2 года назад

      @@CompleteCoding Hey Sam, I can see you added that .. Great

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      @@febinr8888 I've already added that to the plugin. If you read the readme there are instructions on how to add query string details

  • @chelodegli
    @chelodegli Год назад

    Amazing! Thank you!

  • @nicolaswenner7149
    @nicolaswenner7149 2 года назад

    Hello Sam ! Thanks you for your job.
    Is there a way to exclude endpoints, or specify only some endpoints ?

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      Not at the moment. Adding that functionality wouldn't be too hard. It would just mean adding an optional parameter to each event for exclude. In the plugin logic, when creating an 'endpoint' you just filter on ones that are excluded.
      I've added an issue to the repo. You could look at adding that functionality to the repo if you want to.

    • @nicolaswenner7149
      @nicolaswenner7149 2 года назад

      @@CompleteCoding Thanks a lot !

  • @victrio1996
    @victrio1996 Год назад

    love this plugin but i miss some implementation using the serverless-openapi-documentation format,

  • @MrKalsim
    @MrKalsim 2 года назад

    Nice plugin, excellent work! Does the plugin work with serverless framework 2.0? Also is there a way to hide the API documentation based on the stage - for example the API documentation should be available in non prod but should be hidden in prod to avoid exposing proprietary information to public.

    • @CompleteCoding
      @CompleteCoding  2 года назад

      yes it works with framework v2.
      Currently not but that would be a really cool feature. I'll add it as a feature request to the repo. If you want to try and implement it then that would be amazing.

  • @FelipeAvellaMoreira
    @FelipeAvellaMoreira Год назад

    Hello, I'm trying to use the bodyType with an interface that extends properties from another interface. When swagger is loaded the model is not showing the proprieties from the extended interface. There's a way to fix this?

  • @kishored1973
    @kishored1973 Год назад

    Thank you for this npm package! A quick question on C# based Lambda implementations, are there any special requirements for using this npm package? Will it work the way you demoed in the video? Thanks again!

    • @CompleteCoding
      @CompleteCoding  Год назад

      The plugin shouldn't care how you've written your code. The only thing you'll not be able to do is use the type definitions to define your body in requests and responses

  • @viniciusfilenga4730
    @viniciusfilenga4730 Год назад

    That is magic! Thanks.

  • @ramyasaminathan4431
    @ramyasaminathan4431 2 года назад

    Hi,
    I tried auto-swagger with serverless-esbuild and they are working as you mentioned in a comment. Thanks for that.
    Could you please provide option not to deploy, so that we deploy the generated swagger files using our serverless.yml, which will deploy the docs in same url as our app and we can do Try-it-out in swagger page. Please correct me if i am wrong.

  • @angelacardenas3121
    @angelacardenas3121 Год назад

    Thank you very much for the video, one question, can this plugin generate the same file for two different paths where one shows only certain functions? I appreciate any information

    • @CompleteCoding
      @CompleteCoding  Год назад

      So generate two separate swagger files - eg one for internal docs and one for external (which hides some endpoints)?
      Not at the moment. You could add it as a feature request though

  • @davidchoqueluqueroman623
    @davidchoqueluqueroman623 2 года назад

    Hello, great work. The pluging can manage function versions? It just works with serverless offline o it can be uploaded to s3? Thank you.

    • @CompleteCoding
      @CompleteCoding  2 года назад

      The serverless framework manages the function versions. The plugin just generates the documentation.
      You could deploy the swagger config to S3, but the plugin deploys the swagger docs url with the rest of your APIs.

  • @mahimajain9133
    @mahimajain9133 Год назад

    Hi Sam!
    Tons of thanks for the video.
    I want to ask a question. Would be so greatful if you could answer it.
    I want to pass origin from header parameters in api but swager url is overriding the origin. Is there any way to pass different origin in header?

    • @CompleteCoding
      @CompleteCoding  Год назад

      Do you mean in the swagger UI when testing the API endpoint?

    • @mahimajain9133
      @mahimajain9133 Год назад

      @@CompleteCoding yes

    • @mahimajain9133
      @mahimajain9133 Год назад

      for more example: i have one api get-roles... and on the basis of the origin i am fetching roles.... now in this scenario what is happening.. when i testing api from swaggerUI the origin will always be the swagger one.. so not able to do the testing

    • @CompleteCoding
      @CompleteCoding  Год назад +1

      @@mahimajain9133 That would be a feature for swagger-UI it's self.

  • @aniketmore3598
    @aniketmore3598 2 года назад

    Hello Sam!
    Can you add option to include context path in 'try it out' ?, the stage context path is missing ('dev') in the api path, hence it results in error

    • @CompleteCoding
      @CompleteCoding  2 года назад

      I've looked into updating the package to get the 'try-it-out' to work.
      The challenge isn't with localhost but when it gets deployed. The plugin somehow needs to know the url of the API before it's deployed.

    • @nicoiamarino4568
      @nicoiamarino4568 2 года назад

      ​@@CompleteCoding
      Would be okey to concat the stage in generatePaths() (ServerlessAutoSwagger.ts:273) ?
      I'd like to try that but I don't know how.
      Thanks you for your job!

  • @alanschapira
    @alanschapira 2 года назад

    Do you have the source code for the project you ended up with? I have tried using the aws-nodejs-typescript starter, but it looks very different to your code. It seems to now use serverless-esbuild instead of serverless-webpack. Does serverless-auto-swagger work with serverless-esbuild?

    • @CompleteCoding
      @CompleteCoding  2 года назад

      I've not tried it yet but it should do.
      The serverless-auto-swagger hooks into the serverless framework before it gets to compile

  • @abhilashkokkonda1713
    @abhilashkokkonda1713 Год назад

    Awesome... I have a question, I have my end-points generated with /dev in the basepath as the dev stage when I run serverless locally. The swagger is getting generated, but the /dev is not getting appended in the URL, when I try try out, I'm getting 404 error. Request your help on this.

    • @CompleteCoding
      @CompleteCoding  Год назад

      The stage should be getting added to the url path.
      Are you using http or httpAPI endpoints?

    • @abhilashkokkonda1713
      @abhilashkokkonda1713 Год назад

      @@CompleteCoding Im using http end-points
      Can you please share sample code
      Also, the swagger folder is getting created outside my src folder, so the sls deploy command is failing to deploy the generated swagger folder.

  • @KoyaMel
    @KoyaMel 2 года назад

    I'm getting below error when trying to serverless offline start
    TypeError: _a.defineFunctionEventProperties is not a function

  • @Sebasarra1
    @Sebasarra1 Год назад +1

    Hi Sam,
    When I set the responses object in http event function i'm receiving an error 500 (TypeError: Cannot destructure property 'responseParameters' of 'chosenResponse' as it is undefined.Ï)
    when I try the endpoint in both postman and swagger.
    When I comment the object the endpoint works.
    Thanks in advance!

    • @dimakozoliy2248
      @dimakozoliy2248 Год назад +1

      Try to use responseData field instead of responses, it helps me

    • @Sebasarra1
      @Sebasarra1 Год назад

      @@dimakozoliy2248 It works! Thank you so much!

  • @codinglife1277
    @codinglife1277 2 года назад

    great content

  • @TheGranZapan
    @TheGranZapan 2 года назад

    Awesome!!!

  • @salahaosamaelhoseneyali7019
    @salahaosamaelhoseneyali7019 2 года назад +2

    Good content

  • @ramyasaminathan4431
    @ramyasaminathan4431 2 года назад

    Hello Sam,
    I am trying to use serverless-auto-swagger along with serverless-bundle for a nodejs project. serverless-bundle seems to expect ES6 export import syntax, but the swagger src created are having commonJS require() syntax..could you pls guide me how can i use serverless-auto-swagger along with server-bundle plugin ?Im getting the follow error:
    swagger-json.js
    1:1 error 'use strict' is unnecessary inside of modules strict
    2:1 error Definition for rule '@typescript-eslint/no-var-requires' was not found @typescript-eslint/no-var-requires

  • @eduupo8322
    @eduupo8322 2 года назад

    Hey, Sam! For some reason my SwaggerUI and SwaggerJSON function names are returning undefined when deploying to AWS. Do you know why it can possibly happen?

    • @CompleteCoding
      @CompleteCoding  2 года назад

      I'm not sure. If you add an issue to the github project then we now have a group of us working to improve it

  • @mahimajain9133
    @mahimajain9133 2 года назад

    Hi Sam,
    Thanks for the amazing content I just joined the project that is using serverless framework and your channel is my one stop destination for every problem.
    Now, I am struggling with passing array, string, date ... data types via bodyType to request body or response body. Is there any way of doing it. if yes please let me know. Thanks.

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      Super glad that my videos are helping you out.
      You have to pass the name of the typescript interface into bodyType. That could be as simple as
      type postRequestBody = String
      if you want them just to post up a string in the body.

    • @mahimajain9133
      @mahimajain9133 2 года назад

      @@CompleteCoding Thank you so much Sam . Can you please also guide if we somehow can use date data type as well?

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      ​@@mahimajain9133 The only data types supported by swagger are string, number, int, boolean, array and object
      you'd have to specify that they send either a string (Wed Apr 06 2022 10:44:56 GMT+0200)
      Or a number (1649234680333) which is just the timestamp.

  • @dorianyeye
    @dorianyeye 2 года назад +1

    Hello Sam, excellent work and content.
    Question: Your awesome plugin also will work if I use the standard "serverless.yml" file ? or is only compatible with the typeScript implementation ?
    Thanks 😊

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      It'll work exactly the same with a serverless.yml file.

    • @dorianyeye
      @dorianyeye 2 года назад

      @@CompleteCoding Thanks Sam

    • @dorianyeye
      @dorianyeye 2 года назад

      @@CompleteCoding And what about if I have the standard "serverless.yml" file and also I am not using TypeScript ? I ask because i'm using NodeJs and got this error "Error: ENOENT: no such file or directory, open './src/types/api-types.d.ts': unable to get types"

    • @CompleteCoding
      @CompleteCoding  2 года назад

      @@dorianyeye Nice spot. I'll have to fix that. For now if you add an empty file to /src/types/api-types.d.ts` then everything should work.

  • @leandrofita8879
    @leandrofita8879 Месяц назад

    Is there a way to agroup endpoints under a controller group? I was implementing it here and all endpoints got clustered in a single group, without separation by entity.
    Thank you for the plugin!

    • @leandrofita8879
      @leandrofita8879 Месяц назад

      Just found it, using swaggerTags, thank you for your work!

  • @ML-ns4fg
    @ML-ns4fg 2 года назад

    Hi, Sam, It is really amazing and super convenient plugin. Thank you!
    I am implementing auto-swagger to TypeScript Lambda project with serverless-esbuild and it creates its own host not connected to my end points. When I tried to use host property config it throw error on deploy as unrecognized. Try to search and google with no result. May be you can advise? thanks a lot in advance

    • @chelodegli
      @chelodegli Год назад

      Look at Pavel Razuvalau reply!

  • @GilGiovani
    @GilGiovani 2 года назад

    Can I use it in a JS projetct? How can I specify .js models?

  • @veteranodilso
    @veteranodilso 6 месяцев назад

    Hi Sam!
    This plugin was deprecated? I didn't see updates on npm...

  • @sebasoft
    @sebasoft Год назад

    Does this support 'serverless-http' for having `/{proxy}` functions to be read from the express router?

    • @CompleteCoding
      @CompleteCoding  Год назад

      It wouldn't be able to pull the paths from express. It gets all of the path data from the serverless config.

  • @PrateekKumarS
    @PrateekKumarS 8 месяцев назад

    can you please share the github version of this project - also a video on serverless frameworkversion 3 migration is much needed, as the documentation sucks.

  • @guitarrasan
    @guitarrasan Год назад

    Is that possible to generate two different Open API files? Like Internal OpenAPI and Partners OpenAPI?

    • @CompleteCoding
      @CompleteCoding  Год назад

      That would be a new feature request for the plugin.
      It would have to add a way to define which docs to add each endpoint to.

  • @asishsam7747
    @asishsam7747 2 года назад

    Hello Sam, Nice Plugin!
    But I can't able to deploy to multiple environment, every time it is deploying to dev only. I'm getting Error:
    CREATE_FAILED: SwaggerJSONLambdaFunction (AWS::Lambda::Function)
    XXX-dev-swagger-json already exists in stack. Can you please help me!!

  • @madhavkwatra5888
    @madhavkwatra5888 Год назад

    I am getting this error
    Failure: Cannot assign to read only property 'exports' of object '#'
    Can anybody resolve this?

  • @SauravKumar-vv5qq
    @SauravKumar-vv5qq 8 месяцев назад

    Is there any one who has solved error at production level i am struggling with statusCode 406 please help.

  • @danielcarvalho8153
    @danielcarvalho8153 2 года назад

    Hi Sam, there are some modules that I want to ommit in the documentation, how can I do this?

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      The plugin currently adds all interfaces in the provided type files to the docs.
      The easiest way to exclude some interfaces is to have one type file that exports interfaces you want in your documentation and one with all the types that you don't. Then just tell the plugin to only look at the first file.

    • @danielcarvalho8153
      @danielcarvalho8153 2 года назад

      @@CompleteCoding Hey. sam. After my deploy I get this sls error " Missing required key 'FunctionName' in params" and it breaks my pipeline, do you know how to solve it?

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      @@danielcarvalho8153 I don't think that is coming from my plugin. I searched the repo for `Missing required key` and found nothing.
      Does it appear to be breaking in the auto-swagger part?

    • @danielcarvalho8153
      @danielcarvalho8153 2 года назад

      ​@@CompleteCoding I don't know, too. I imagine it's caused because the name of swagger's lambdas which the plugin creates comes like this. '' swaggerUI: undefined". But I don't know if there is a way to solve it. But no problems, Sam. I total appreciate your answers.

  • @madhavkwatra5888
    @madhavkwatra5888 Год назад

    What if i have created a swagger.yml file myself and want to get a swagger ui of that without auto generating?

    • @CompleteCoding
      @CompleteCoding  Год назад

      Then just create a swagger endpoint that imports your existing swagger file. No need to use the plugin. There are loads of code examples of creating a swagger endpoint.

    • @madhavkwatra5888
      @madhavkwatra5888 Год назад

      @@CompleteCoding yeah did that , thanks for the reply

  • @vishalpatil-sp3iz
    @vishalpatil-sp3iz 2 года назад

    I am getting like this No operations defined in spec!

  • @loudornelles
    @loudornelles 2 года назад

    which VS Code Theme are you using?

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      Monocai Pro. It $10 but so worth it. I used to switch themes every few weeks but had this one for almost 2 years now

    • @loudornelles
      @loudornelles 2 года назад

      @@CompleteCoding thank you!

  • @rohitjaiswal946
    @rohitjaiswal946 Год назад

    Tinku Jiya

  • @mahimajain9133
    @mahimajain9133 2 года назад +1

    Hi sam,
    How can we pass path parameters from swagger?

    • @CompleteCoding
      @CompleteCoding  2 года назад +1

      Yes, Check out the documentation. You can add path params, query params and more

    • @michalzawitowski2518
      @michalzawitowski2518 2 года назад

      @@CompleteCoding I only found queryStringParameters and headerParameters. Is there any way to add a path param? Btw. great job!

    • @mahimajain9133
      @mahimajain9133 2 года назад

      @@michalzawitowski2518 same here

    • @michalzawitowski2518
      @michalzawitowski2518 2 года назад

      @@mahimajain9133 Im able to present path params only by duplicating path in
      parameters:
      path: hello/{helloId}
      What probably is a bug?

    • @mahimajain9133
      @mahimajain9133 2 года назад

      @@michalzawitowski2518 ya probably it is coded to work this way only though its working for me as well thanks for sharing.

  • @opehardesina
    @opehardesina 2 года назад

    hi...how do i set my body properties

    • @CompleteCoding
      @CompleteCoding  2 года назад

      on each event you can add a "bodyType" parameter which points at your typescript type.
      http: {
      path: 'hello',
      method: 'post',
      cors: true,
      bodyType: 'helloPostBody',
      }

    • @opehardesina
      @opehardesina 2 года назад

      @@CompleteCoding I get the error "bodyType" is not a property
      P.S: I am not using Typescript

    • @CompleteCoding
      @CompleteCoding  2 года назад

      @@opehardesina Are you using something like ES Lint or something similar?
      bodyType is not normally a property of an event, but when using the plugin it should be available.

    • @opehardesina
      @opehardesina 2 года назад

      @@CompleteCoding No i'm not but for some reason i get that error

  • @ayami123
    @ayami123 Год назад

    why people don't use apidoc and they prefer swagger? weird

    • @CompleteCoding
      @CompleteCoding  Год назад

      Swagger has been around for a very long time and is what a lot of people are used to. I've never heard of apiDoc but it looks like it could be used in a similar way.
      It does look like you have to comment your code in a particular way to get it to work. That means there are two places you're now defining what your path looks like, making it just as likely to become out of sync. This plugin generates the swagger from your API config so you only define it in one place

  • @mdrijwanrazzaqmatin2503
    @mdrijwanrazzaqmatin2503 2 года назад

    this doesn't work anymore

    • @CompleteCoding
      @CompleteCoding  2 года назад

      Since releasing the video there have been LOADS of changes to the npm package

    • @mdrijwanrazzaqmatin2503
      @mdrijwanrazzaqmatin2503 2 года назад

      @@CompleteCoding yeah, that's why. is there any fixes?

  • @seekingholyspirit
    @seekingholyspirit 2 года назад

    Thanks Sam for the nice plugin. That is very useful.
    Getting validation error on bodyType,
    Configuration error:
    at 'functions.hello.events[0].http': unrecognized property 'bodyType'

    • @CompleteCoding
      @CompleteCoding  2 года назад

      I've had this pointed out. I'm looking into fixing it in the next release
      Are you using typescript, ES Lint or anything like that? Also what IDE are you using?

    • @seekingholyspirit
      @seekingholyspirit 2 года назад

      @@CompleteCoding To reproduce it, in serverless.yml, set configValidationMode: error; I will get the above error doing sls generate-swagger. Thanks for looking into it.

  • @muhammadzahir946
    @muhammadzahir946 10 месяцев назад

    I am getting Couldn't read types from file: ./src/types/api-types.d.ts.Dont know why

    • @joseandresmayo
      @joseandresmayo 4 дня назад

      You must create "api-types.d.ts" file in your local folder src/type, otherwise, you can also use another file for types using the config param "typefiles"