1

We're trying to integrate serverless-openapi-documentation plugin in our application which is developed using nodejs and serverless framework.

Here's a code that I've programmed by following their documentation.

Serverless.yml

service: thirdparty-api
frameworkVersion: "^3.19.0"
useDotenv: true

plugins:
  - serverless-offline
  - serverless-openapi-documentation
  - serverless-apigw-binary

custom:
  documentation:
    version: '1'
    title: 'My API'
    description: 'This is my API'
    models:
      - name: ErrorResponse
        description: This is an error
        contentType: application/json
        schema: ${file(conf/models/ErrorResponse.json)}
      - name: PutDocumentResponse
        description: PUT Document response model (external reference example)
        contentType: application/json
        schema: ${file(conf/models/PutDocumentResponse.json)}

Function Part in serverless.yml

functions:

  - ${file(conf/funcs/sertifi.yaml)}

ErrorResponse.Json

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "JSON API Schema",
    "description": "This is a schema for responses in the JSON API format. For more, see http://jsonapi.org",
    "type": "object",
    "required": [
      "errors"
    ],
    "properties": {
      "errors": {
        "type": "array",
        "items": {
          "$ref": "#/definitions/error"
        },
        "uniqueItems": true
      },
      "meta": {
        "$ref": "#/definitions/meta"
      },
      "links": {
        "$ref": "#/definitions/links"
      }
    },
    "additionalProperties": false,
    "definitions": {    
      "meta": {
        "description": "Non-standard meta-information that can not be represented as an attribute or relationship.",
        "type": "object",
        "additionalProperties": true
      },
      "links": {
        "description": "A resource object **MAY** contain references to other resource objects (\"relationships\"). Relationships may be to-one or to-many. Relationships can be specified by including a member in a resource's links object.",
        "type": "object",
        "properties": {
          "self": {
            "description": "A `self` member, whose value is a URL for the relationship itself (a \"relationship URL\"). This URL allows the client to directly manipulate the relationship. For example, it would allow a client to remove an `author` from an `article` without deleting the people resource itself.",
            "type": "string",
            "format": "uri"
          },
          "related": {
            "$ref": "#/definitions/link"
          }
        },
        "additionalProperties": true
      },
      "link": {
        "description": "A link **MUST** be represented as either: a string containing the link's URL or a link object.",
        "oneOf": [
          {
            "description": "A string containing the link's URL.",
            "type": "string",
            "format": "uri"
          },
          {
            "type": "object",
            "required": [
              "href"
            ],
            "properties": {
              "href": {
                "description": "A string containing the link's URL.",
                "type": "string",
                "format": "uri"
              },
              "meta": {
                "$ref": "#/definitions/meta"
              }
            }
          }
        ]
      },  
      "error": {
        "type": "object",
        "properties": {
          "id": {
            "description": "A unique identifier for this particular occurrence of the problem.",
            "type": "string"
          },
          "links": {
            "$ref": "#/definitions/links"
          },
          "status": {
            "description": "The HTTP status code applicable to this problem, expressed as a string value.",
            "type": "string"
          },
          "code": {
            "description": "An application-specific error code, expressed as a string value.",
            "type": "string"
          },
          "title": {
            "description": "A short, human-readable summary of the problem. It **SHOULD NOT** change from occurrence to occurrence of the problem, except for purposes of localization.",
            "type": "string"
          },
          "detail": {
            "description": "A human-readable explanation specific to this occurrence of the problem.",
            "type": "string"
          },
          "source": {
            "type": "object",
            "properties": {
              "pointer": {
                "description": "A JSON Pointer [RFC6901] to the associated entity in the request document [e.g. \"/data\" for a primary data object, or \"/data/attributes/title\" for a specific attribute].",
                "type": "string"
              },
              "parameter": {
                "description": "A string indicating which query parameter caused the error.",
                "type": "string"
              }
            }
          },
          "meta": {
            "$ref": "#/definitions/meta"
          }
        },
        "additionalProperties": false
      }
    }
  }

PutDocumentResponse.Json

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title" : "Empty Schema",
    "type" : "object"
}

After doing all these code, When I try to run following command as per their documentation

$ serverless openapi generate --output

This command results into an error like this...

Error:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type boolean (true)
    at Object.openSync (fs.js:489:10)
    at Object.writeFileSync (fs.js:1528:35)
    at ServerlessOpenApiDocumentation.generate (D:\Reinvent\Web\thirdparty-api\node_modules\serverless-openapi-documentation\ServerlessOpenApiDocumentation.js:127:12)
    at PluginManager.runHooks (D:\Reinvent\Web\thirdparty-api\node_modules\serverless\lib\classes\plugin-manager.js:530:15)
    at PluginManager.invoke (D:\Reinvent\Web\thirdparty-api\node_modules\serverless\lib\classes\plugin-manager.js:564:20)
    at async PluginManager.run (D:\Reinvent\Web\thirdparty-api\node_modules\serverless\lib\classes\plugin-manager.js:604:7)
    at async Serverless.run (D:\Reinvent\Web\thirdparty-api\node_modules\serverless\lib\serverless.js:174:5)
    at async D:\Reinvent\Web\thirdparty-api\node_modules\serverless\scripts\serverless.js:771:9
Chirag
  • 994
  • 2
  • 11
  • 26

0 Answers0