v5.0.1 with new ajv: short-hand syntax with nullable does not work anymore
Describe the bug
Prior to v 5.x I could combine a ref component with nullable: true in anyOf to achieve describing a nullable prop. Now I got the error.
To Reproduce
Combine a referenced component with nullable: true:
someField:
anyOf:
- $ref: '#/components/schemas/field-type'
- nullable: true
Actual behavior An exception instead of assuming a nullable component
"nullable" cannot be used without "type"
(I suppose at least it should be a validation error from the validator).
Expected behavior A nullable prop
Examples and context Not working example:
someField:
anyOf:
- $ref: '#/components/schemas/field-type'
- nullable: true
Workaround:
someField:
anyOf:
- $ref: '#/components/schemas/field-type'
- type: object
nullable: true
We ran into this problem to, so we reverted to v4.x.x for now. Would be nice if this could be solved in v5 though
I am trying to upgrade to 5.x and am running into this issue as well. It's particularly frustrating because it is not specific about where the error occurred. We have a large file with many nullable: true and it is not immediately apparent what is causing the issue.
@cdimascio Any plans on fixing this issue any time soon?
@aivanov-noveo can you provide a minimal version of the problematic spec that demonstrates the issue. Thus will help to reproduce and resolve
@cdimascio here it is:
openapi: '3.0.0'
info:
version: 1.0.0
title: test
servers:
- url: /
security: []
paths:
/test:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserLink'
responses:
'200':
description: OK
components:
schemas:
User:
type: object
properties:
id:
type: integer
UserLink:
type: object
properties:
user:
anyOf:
- $ref: '#/components/schemas/User'
- nullable: true
The middleware was registered like this:
import { middleware as oaMiddleware } from 'express-openapi-validator';
const apiTestSpec = join(__dirname, './api-test.yml');
const middleware = oaMiddleware({
apiSpec: apiTestSpec,
validateApiSpec: true,
});
I am seeing this too--any update here?