Skip to content

Implemented on Lambda Handler Functions yields missing info object error! #319

Open

Description

@pjcjonas

Describe the bug
When running the swagger-jsdoc command on the definition file I keep getting:

$> yarn swagger-jsdoc -d ./swaggerDef.js
yarn run v1.22.17
$ /Userscolldude/apihhooks/app/node_modules/.bin/swagger-jsdoc -d ./swaggerDef.js
Definition file should contain an info object!
More at http://swagger.io/specification/#infoObject

To Reproduce
Steps to reproduce the behavior:
1: Create lambda handler method
2: Add swagger or openapi commend.
3: create SW Deffinition file referencing the handler file.

// IMPORTS GO HERE

/**
 * @openapi
 * /:
 *   get:
 *     description: Welcome to swagger-jsdoc!
 *     responses:
 *       200:
 *         description: Returns a mysterious string.
 */
export const handler = async (request) => {
  try {
    
    // LOGIC GOES HEREE

    return responseSuccess({ data: subscription })
  } catch (error) {
    return error
  }
}

deffinition file:

const swaggerJsdoc = require('swagger-jsdoc')

const options = {
  swaggerDefinition: {
    openapi: '3.0.0',
    info: {
      title: 'Hello World',
      version: '1.0.0',
    },
  },
  apis: ['./webhooks/webhookscreate.js'],
}

const openapiSpecification = swaggerJsdoc(options)

Expected behavior
I am expecting a swagger json output to use with swagger ui

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac
  • Node: v14.18.3
  • Yarn: 1.22.17
  • NPM: 6.14.15

I am looking for a way to generate Swagger deffinition files to use with swagger UI in the same way that .net core uses Swashbuckle.

Activity

  1. added
    pinnedIssues that will not be automatically closed
    on Apr 19, 2022
  2. daniloab commented on Apr 19, 2022

    @daniloab
    Collaborator

    Hi, @pjcjonas

    Seems you have a project named /apihhooks/app/. Can you provide a tiny repo reproducing the error that are you getting it?

  3. pjcjonas commented on Apr 19, 2022

    @pjcjonas
    Author

    I sort that out ASAP, in the mean time I fixed it by creating the swagger.js file below and running node swagger.js that then generates the json file for me included at the end:

    const express = require("express");
    const swaggerJSDoc = require("swagger-jsdoc");
    const app = express();
    const fs = require("fs");
    
    const options = {
    	definition: {
    		openapi: "3.0.0",
    		info: {
    			title: "Hello World",
    			description: "A sample API",
    			version: "1.0.0",
    		},
    	},
    	apis: ["./api*.js"],
    };
    
    const spec = swaggerJSDoc(options);
    
    // ADDED THIS LINE
    fs.writeFileSync("./swagger.json", JSON.stringify(spec));

    OUTPUT

    {
    	"openapi": "3.0.0",
    	"info": {
    		"title": "Hello World",
    		"description": "A sample API",
    		"version": "1.0.0"
    	},
    	"paths": {
    		"/": {
    			"get": {
    				"description": "QQQQ Welcome to swagger-jsdoc!",
    				"responses": {
    					"200": { "description": "Returns a mysterious string." }
    				}
    			}
    		}
    	},
    	"components": {},
    	"tags": []
    }
    
  4. daniloab commented on Apr 19, 2022

    @daniloab
    Collaborator

    Awesome, I was debugging here. So, can we consider that this is working for you?

  5. pjcjonas commented on Apr 19, 2022

    @pjcjonas
    Author

    I works when I used the node index.js method using fs to write a file to the file system, but not the yarn swagger-jsdoc method.

    So its working in a way but not sure if it is suppose to work using the yarn swagger-jsdoc by referencing the definition file and supplying an output

    https://github.com/pjcjonas/swagger-jsodc-test/tree/master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pinnedIssues that will not be automatically closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions