Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't allow specify undefined property as required in schema

See original GitHub issue


  • Node.js: 8.12.0
  • swagger-parser: 6.0.2

Code example

API specification:

openapi: '3.0.2'
  version: v1
  title: test
        required: true
              type: object
                  type: string
                - foo
                - bar # This property is not defined!
              additionalProperties: false
          description: Success
const SwaggerParser = require('swagger-parser');

  .then((api) => console.log('done'))
  .catch((err) => console.error(err));

Expected behavior

Validation error: property bar is required, but it’s not defined.

Actual behavior

No errors.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

jdegrecommented, Jan 7, 2019

Just to understanda the issue… why the schema in the OP is supposed to be wrong?? In my view, the schema is correct, and it simply says that property “bar” is required, and must always be present in the response, but the schema does not constrain what type it can take. “bar” can be an integer, a string, an object… whatever.

stueynzcommented, Jul 22, 2021

Fixed in - All the spec consistency checks were only used to work on Swagger 2.0 specs; All fixed now for OpenAPI v3.0 specs; Might get a chance to look into v3.1 changes later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Schema: Ignore required property if not defined in ...
Agreed, I know this behavior is according to the specs. I was just wondering if there was a keyword or set up in...
Read more >
Ajv options - Ajv JSON schema validator
Replace missing or undefined properties and items with the values from corresponding default keywords. Default behaviour is to ignore default keywords. This ...
Read more >
Understanding JSON Schema
JSON Schema is a powerful tool for validating the structure of JSON data. However, learning to use it by reading its.
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
Types that are not accompanied by a format property follow the type definition in the JSON Schema. Tools that do not recognize a...
Read more >
Schema - Dynamoose
This setting lets you specify if the schema should allow properties not defined in the schema. If you pass true in for this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found