[v2.0] Unexpected Failure on OpenAPI 3 Request Validation
I see the below stack trace when POSTing a CreateOpportunityCommand to /opportunities. I've included the relevant part of the spec. I cannot understand why this would fail...
Stack Trace
com.atlassian.oai.validator.restassured.SwaggerValidationFilter$SwaggerValidationException: Validation failed.
[ERROR] Object instance has properties which are not allowed by the schema: ["commandType","opportunity"]
[ERROR] Instance failed to match all required schemas (matched only 1 out of 2)
* /components/schemas/CreateOpportunityCommand/allOf/0: Object instance has properties which are not allowed by the schema: ["opportunity"]
[ERROR] An error occurred during schema validation - com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException.
Spec
openapi: 3.0.1
paths:
/opportunities:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreateOpportunityCommand'
required: true
responses:
201:
description: The events triggered by the request
content:
application/json:
schema:
$ref: '#/components/schemas/CommandProcessingResponse'
400:
description: The errors caused by a bad command
content:
application/json:
schema:
$ref: '#/components/schemas/CommandProcessingResponse'
500:
description: The errors caused by issues on the server
content:
application/json:
schema:
$ref: '#/components/schemas/CommandProcessingResponse'
components:
schemas:
Command:
type: object
required:
- commandType
properties:
commandType:
$ref: '#/components/schemas/CommandType'
CommandType:
type: string
enum:
- CreateOpportunityCommand
- WinOpportunityCommand
CreateOpportunityCommand:
allOf:
- $ref: '#/components/schemas/Command'
- required:
- opportunity
properties:
opportunity:
$ref: '#/components/schemas/Opportunity'
Request body
{
"commandType": "CreateOpportunityCommand",
"opportunity": {
"name": "super cool project",
"type": "residency",
"customerName": "acme"
}
}
Comments (6)
-
Account Deleted -
- changed title to [v2.0] Unexpected Failure on OpenAPI 3 Request Validation
-
Apologies for the delay in responding. SRV 2.0.0-rc2 supports OpenAPI v3 with no need to switch etc.
Its likely this is the same scenario described in the FAQ. The validator automatically inserts
additionalProperties: false
unless you disable (ignore) the additional properties validation, so even though you aren't specifying it in your spec you are likely still hitting the same problem.The NPE is a bit concerning though. I'll try to reproduce the issue in the next day or so.
Thanks.
-
@jholmes-rhc Ive recreated your example and it works on the current v2.0 branch when the
additionalProperties
validation is disabled as described in the FAQ. I will close this issue as resolved, but if you have further problems please feel free to re-open. -
- changed status to resolved
-
Account Deleted Thanks @jnavin
- Log in to comment
Perhaps I should clarify. I'm usig 2.0.0-rc2 with the understanding this supported version V3 OpenAPI. As I'm spelunking through the code, I see that https://bitbucket.org/atlassian/swagger-request-validator/src/f2ba3e52983e35d2d059091dcadd4d1a30218534/swagger-request-validator-core/src/main/java/com/atlassian/oai/validator/schema/SchemaValidator.java#lines-121 is loading up V2 schema validator.
Is there a switch I'm missing somewhere to use v3 validation? Or is v3 not supported?
Also, I'm not using additional properties so my reading of the FAQ doesn't seem to require me to turn of the validation here... May be that is the wrong reading?