Don't allow specify undefined property as required in schema
See original GitHub issueVersions
- Node.js:
8.12.0
- swagger-parser:
6.0.2
Code example
API specification:
openapi: '3.0.2'
info:
version: v1
title: test
paths:
/:
post:
requestBody:
required: true
content:
'application/json':
schema:
type: object
properties:
foo:
type: string
required:
- foo
- bar # This property is not defined!
additionalProperties: false
responses:
200:
description: Success
const SwaggerParser = require('swagger-parser');
SwaggerParser.validate('api.yml')
.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:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Fixed in https://github.com/APIDevTools/swagger-parser/pull/179 - 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.