Skip to content

Explicit additionalProperties: false should be emitted in OpenAPI 3.1 when AdditionalPropertiesAllowed = false #2646

@codijk

Description

@codijk

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 additionalProperties defaults to an empty schema ({}), which allows any additional properties.
  • Only explicitly setting "additionalProperties": false prevents 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:

Describe the solution you'd like
When AdditionalPropertiesAllowed = false is explicitly set on a schema:

  • OpenAPI.NET should emit "additionalProperties": false in 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": false manually 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    goodfirstissueStandard GitHub label used for easy to resolve issues targeting beginner contributorshelp wantedtype:bugA broken experience

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions