Greetings team!
I have an OpenAPI spec with a POST operation that can contain one of three models in the request: Thing1, Thing2, Thing3.
The Thing models “inherit” from ThingBase, which contains a property common to all Things, which all use allOff to include this “base” class.
Thing3 differs from Things1 & 2 in that one of its properties is a object that is a oneOf.
Here is the spec:
openapi: 3.0.0
info:
version: '1.0'
title: Apigee OasValidation POC
servers:
- url: 'http://localhost:3000'
paths:
/things:
post:
summary: Your POST endpoint
operationId: post-things
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Thing1'
- $ref: '#/components/schemas/Thing2'
- $ref: '#/components/schemas/Thing3'
examples:
Example 1:
value:
ThingId: 0
Thing1Property: string
responses:
'201':
description: Created
content:
application/json:
schema: {}
servers:
- url: 'http://localhost:3000'
components:
schemas:
Thing1:
title: Thing1
allOf:
- $ref: '#/components/schemas/ThingBase'
- type: object
additionalProperties: false
properties:
Thing1Property:
type: string
ThingBase:
type: object
title: ThingBase
additionalProperties: false
properties:
ThingId:
type: number
Thing2:
title: Thing2
allOf:
- $ref: '#/components/schemas/ThingBase'
- type: object
additionalProperties: false
properties:
Thing2Property:
type: string
Thing3:
title: Thing3
allOf:
- $ref: '#/components/schemas/ThingBase'
- $ref: '#/components/schemas/Context'
Context:
type: object
title: Context
oneOf:
- type: object
additionalProperties: false
properties:
Property1:
type: string
- type: object
additionalProperties: false
properties:
Property2:
type: string
I've configured an OasValidation policy in my proxy to validate incoming requests against this spec.
Things1 and 2 validate correctly when POSTed in a request, but Thing3 fails when sending this body:
{
"ThingId": 0,
"Property1": "string"
}
The error message: