[Bug]: Mutual exclusion by use of `additionalProperties: false` across union types
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- api, backend-api-design
Research direction
Start by reproducing validation of {"foo": "-", "bar": "-"} with the OpenAPI specification in the issue using the pydantic integration. Trace the validation path for allOf schemas with additionalProperties: false, then determine whether combined validation should succeed or the schema should be rejected and add coverage for the selected behavior.
Written by the indexing model from the issue text.
Description
Actual Behavior
If additionalProperties: false is declared in components and being combined into one by allOf, validation unconditionally fails.
Let's say we have following OpenAPI spec:
---
openapi: 3.0.0
info:
title: Test API
description: Test
version: 0.0.1
servers:
- url: https://www.example.com
paths:
/test:
post:
summary: test
description: test
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Derived'
required: true
responses:
"200":
description: Success
components:
schemas:
Base:
required:
- foo
type: object
properties:
foo:
type: string
nullable: false
additionalProperties: false
Derived:
type: object
allOf:
- $ref: '#/components/schemas/Base'
- type: object
required:
- bar
properties:
bar:
type: string
nullable: false
additionalProperties: false
This spec compiles without any problem. But when validating actual request with this spec, validator fails with following error message:
RequestValidationResult(errors=[InvalidSchemaValue(value={'bar': '2',
'foo': '1'},
type='object',
schema_errors=(<ValidationError: "Additional properties are not allowed ('bar' was unexpected)">,
<ValidationError: "Additional properties are not allowed ('foo' was unexpected)">))],
body=None,
parameters=Parameters(query={},
header={},
cookie={},
path={}),
security={})
Expected Behavior
I think openapi-core should behave one of following:
- Validation should be successful
- Or forbid use of
additionalProperties: falsein context of union types (allOf) at schema lvel.
Steps to Reproduce
Validate {"foo": "-", "bar": "-"} with spec supplied above.
OpenAPI Core Version
0.19.0
OpenAPI Core Integration
pydantic
Affected Area(s)
validation
References
No response
Anything else we need to know?
No response
Would you like to implement a fix?
Yes
- Dominant language
- Python
- Stars
- 368
- Forks
- 140
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-openapi/openapi-core
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
python-openapi/openapi-core#1188 · 2 comments ·
-
kind/bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
python-openapi/openapi-core#1225 · 2 comments ·
-
kind/bug
Difficulty 3/5 1-2 days Newbie friendliness 76/100
python-openapi/openapi-core#1212 ·
-
[Bug]: Query parameter validation fails to match empty string when listed as a valid enum value Openkind/bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
python-openapi/openapi-core#1210 ·
-
kind/bug kind/bug/confirmed
Difficulty 3/5 1-2 days Newbie friendliness 58/100
python-openapi/openapi-core#1180 · 3 comments ·
All issues in python-openapi/openapi-core
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
learningequality/ricecooker#747 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
run-llama/llama_index#23199 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
KhronosGroup/glTF-Blender-IO#2769 ·