-
Notifications
You must be signed in to change notification settings - Fork 279
Labels
goodfirstissueStandard GitHub label used for easy to resolve issues targeting beginner contributorsStandard GitHub label used for easy to resolve issues targeting beginner contributorshelp wantedtype:bugA broken experienceA broken experience
Description
Is your feature request related to a problem? Please describe.
Currently, when serializing OpenAPI 3.1 documents, setting AdditionalPropertiesAllowed = false on a schema does not emit "additionalProperties": false.
This causes a semantic issue in OpenAPI 3.1 because schemas follow JSON Schema 2020-12, where:
- Omitting
additionalPropertiesdefaults to an empty schema ({}), which allows any additional properties. - Only explicitly setting
"additionalProperties": falseprevents extra properties, matching the user's intent.
Currently, OpenAPI.NET only emits additionalProperties: false for OpenAPI 3.0 documents, as demonstrated in #2631 and related tests. While this behavior is intentional per #2630, it does not preserve the explicit intent when targeting OpenAPI 3.1.
Official spec references:
- OpenAPI 3.1 Schema Object: inherits JSON Schema 2020-12 semantics
- JSON Schema 2020-12 `additionalProperties semantics: omission allows any additional properties
Describe the solution you'd like
When AdditionalPropertiesAllowed = false is explicitly set on a schema:
- OpenAPI.NET should emit
"additionalProperties": falsein OpenAPI 3.1 output. - This ensures that the generated document accurately preserves user intent and aligns with JSON Schema 2020-12 semantics.
- Emitting this explicitly is safe and non-breaking for downstream consumers, as it only reinforces the intended constraint.
Describe alternatives you've considered
- Post-processing the OpenAPI 3.1 JSON/YAML to inject
"additionalProperties": falsemanually for closed schemas.- This works but is a workaround and adds extra steps for consumers.
- Leaving the current behavior as-is.
- This preservers the existing design choice, but loses semantic fidelity when targeting OpenAPI 3.1
Additional context
- Current behavior is explicitly tested in fix/additional properties to v3 #2631, which shows emission only for 3.0.
- fix: additional properties serialization should not emit a schema in v2 fix: additional properties serialization should not emit booleans in v3.1+ #2630 confirms that this behavior is intentional, but it does not account for JSON Schema 2020-12 semantics in OpenAPI 3.1.
- Explicitly emittion
"additionalProperties": falsewould align the serializer with the official OpenAPI 3.1 spec and JSON Schema 2020-12 behavior, avoiding silent loss of user intent.
Metadata
Metadata
Assignees
Labels
goodfirstissueStandard GitHub label used for easy to resolve issues targeting beginner contributorsStandard GitHub label used for easy to resolve issues targeting beginner contributorshelp wantedtype:bugA broken experienceA broken experience