Skip to content

Commit

Permalink
(fix) #400 readonly with single required prop fails
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Oct 26, 2020
1 parent 1bd1bee commit 89ce676
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test/oneof.readonly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('one.of readonly', () => {
app.use(
express
.Router()
.post(`${app.basePath}/any_of_one_required`, (req, res) =>
res.status(200).json({ success: true }),
)
.post(`${app.basePath}/any_of`, (req, res) =>
res.status(200).json({ success: true }),
)
Expand Down Expand Up @@ -46,6 +49,13 @@ describe('one.of readonly', () => {
expect(error.message).to.include('to one of the allowed values: C, D');
}));

it('post type anyof without providing the single required readonly property should pass', async () =>
request(app)
.post(`${app.basePath}/one_of`)
.send({ type: 'C' }) // do not provide id
.set('Content-Type', 'application/json')
.expect(200));

it('post type oneOf (without readonly id) should pass', async () =>
request(app)
.post(`${app.basePath}/one_of`)
Expand Down
39 changes: 38 additions & 1 deletion test/oneof.readonly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ info:
servers:
- url: /v1
paths:
/any_of_one_required:
post:
requestBody:
content:
application/json:
schema:
anyOf:
- $ref: '#/components/schemas/subE'
- $ref: '#/components/schemas/subF'
discriminator:
propertyName: type
mapping:
A: '#/components/schemas/subE'
B: '#/components/schemas/subF'
responses:
200:
description: successful operation
/any_of:
post:
requestBody:
Expand Down Expand Up @@ -57,6 +74,18 @@ components:
- id
- type

one_required:
type: object
properties:
id:
readOnly: true
type: string
type:
type: string
enum: [A, B]
required:
- id

subA:
allOf:
- $ref: '#/components/schemas/common'
Expand Down Expand Up @@ -91,4 +120,12 @@ components:
enum: [C, D]
required:
- id
- type
- type

subE:
allOf:
- $ref: '#/components/schemas/one_required'

subF:
allOf:
- $ref: '#/components/schemas/one_required'

0 comments on commit 89ce676

Please sign in to comment.