OpenAPITools / OpenAPITools/openapi-generator

[BUG][nodejs-express-server] npm start Error: openapi.validator: args.apiDoc was invalid.

Open
#7,992 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Nodejs
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version

4.3.1

OpenAPI declaration file content or url
Generation Details

nodejs-express-server generates code fine, but npm start prints error:

Error: openapi.validator: args.apiDoc was invalid.  See the output.
    at OpenAPIFramework.initialize (/media/databank/tmp/scratch-2020-11-20-15:17:57/node_modules/express-openapi-validator/dist/framework/index.js:32:23)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async OpenApiSpecLoader.discoverRoutes (/media/databank/tmp/scratch-2020-11-20-15:17:57/node_modules/express-openapi-validator/dist/framework/openapi.spec.loader.js:47:39)
Listening on port 3000

Note that mentioned YAML passes validation done with github/super-linter

Steps to reproduce
$ openapi-generator-cli version
4.3.1
$ openapi-generator-cli generate -g nodejs-express-server -i https://raw.githubusercontent.com/ipfs/pinning-services-api-spec/v0.1.2/ipfs-pinning-service.yaml
$ npm start

> ipfs-pinning-service-api@0.1.2 prestart /media/databank/tmp/scratch-2020-11-20-15:17:57
> npm install


> deasync@0.1.21 install /media/databank/tmp/scratch-2020-11-20-15:17:57/node_modules/deasync
> node ./build.js

`linux-x64-node-12` exists; testing
Binary is fine; exiting
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.1 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 375 packages from 284 contributors and audited 377 packages in 10.4s

26 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities


> ipfs-pinning-service-api@0.1.2 start /media/databank/tmp/scratch-2020-11-20-15:17:57
> node index.js

{"message":"Express server running","level":"info","service":"user-service","timestamp":"2020-11-20T14:22:34.253Z"}
info: Express server running {"service":"user-service","timestamp":"2020-11-20T14:22:34.253Z"}
openapi.validator: Validating schema
openapi.validator: validation errors [
  {
    "keyword": "required",
    "dataPath": ".paths['/pins']['get'].parameters[7]",
    "schemaPath": "#/definitions/SchemaXORContent/oneOf/0/required",
    "params": {
      "missingProperty": "schema"
    },
    "message": "should have required property 'schema'"
  },
  {
    "keyword": "not",
    "dataPath": ".paths['/pins']['get'].parameters[7]",
    "schemaPath": "#/definitions/SchemaXORContent/oneOf/1/allOf/0/not",
    "params": {},
    "message": "should NOT be valid"
  },
  {
    "keyword": "not",
    "dataPath": ".paths['/pins']['get'].parameters[7]",
    "schemaPath": "#/definitions/SchemaXORContent/oneOf/1/allOf/1/not",
    "params": {},
    "message": "should NOT be valid"
  },
  {
    "keyword": "oneOf",
    "dataPath": ".paths['/pins']['get'].parameters[7]",
    "schemaPath": "#/definitions/SchemaXORContent/oneOf",
    "params": {
      "passingSchemas": null
    },
    "message": "should match exactly one schema in oneOf"
  },
  {
    "keyword": "required",
    "dataPath": ".paths['/pins']['get'].parameters[7]",
    "schemaPath": "#/definitions/Reference/required",
    "params": {
      "missingProperty": "$ref"
    },
    "message": "should have required property '$ref'"
  },
  {
    "keyword": "oneOf",
    "dataPath": ".paths['/pins']['get'].parameters[7]",
    "schemaPath": "#/properties/parameters/items/oneOf",
    "params": {
      "passingSchemas": null
    },
    "message": "should match exactly one schema in oneOf"
  },
  {
    "keyword": "required",
    "dataPath": ".components.parameters['meta']",
    "schemaPath": "#/definitions/Reference/required",
    "params": {
      "missingProperty": "$ref"
    },
    "message": "should have required property '$ref'"
  },
  {
    "keyword": "required",
    "dataPath": ".components.parameters['meta']",
    "schemaPath": "#/definitions/SchemaXORContent/oneOf/0/required",
    "params": {
      "missingProperty": "schema"
    },
    "message": "should have required property 'schema'"
  },
  {
    "keyword": "not",
    "dataPath": ".components.parameters['meta']",
    "schemaPath": "#/definitions/SchemaXORContent/oneOf/1/allOf/0/not",
    "params": {},
    "message": "should NOT be valid"
  },
  {
    "keyword": "not",
    "dataPath": ".components.parameters['meta']",
    "schemaPath": "#/definitions/SchemaXORContent/oneOf/1/allOf/1/not",
    "params": {},
    "message": "should NOT be valid"
  },
  {
    "keyword": "oneOf",
    "dataPath": ".components.parameters['meta']",
    "schemaPath": "#/definitions/SchemaXORContent/oneOf",
    "params": {
      "passingSchemas": null
    },
    "message": "should match exactly one schema in oneOf"
  },
  {
    "keyword": "oneOf",
    "dataPath": ".components.parameters['meta']",
    "schemaPath": "#/properties/parameters/patternProperties/%5E%5Ba-zA-Z0-9%5C.%5C-_%5D%2B%24/oneOf",
    "params": {
      "passingSchemas": null
    },
    "message": "should match exactly one schema in oneOf"
  }
]
Error: openapi.validator: args.apiDoc was invalid.  See the output.
    at OpenAPIFramework.initialize (/media/databank/tmp/scratch-2020-11-20-15:17:57/node_modules/express-openapi-validator/dist/framework/index.js:32:23)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async OpenApiSpecLoader.discoverRoutes (/media/databank/tmp/scratch-2020-11-20-15:17:57/node_modules/express-openapi-validator/dist/framework/openapi.spec.loader.js:47:39)
Listening on port 3000
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generated nodejs-express-server project from the linked OpenAPI declaration with openapi-generator-cli 4.3.1, then run npm start. Inspect index.js and the reported express-openapi-validator stack and validation output; done means the generated server starts without the args.apiDoc validation error for this specification.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, node.js
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.