Skip to content

Conversation

@peter-goldstein
Copy link
Contributor

@peter-goldstein peter-goldstein commented Jan 9, 2026

Summary

Fixes an issue where required field overrides in allOf schemas were being ignored when the base schema was referenced. Properties inherited from a base schema can now be correctly marked as required in derived schemas.

Problem

When using allOf with a reference to a base schema and then marking fields as required in a second schema, the generator was ignoring the required override. For example:

components:
  schemas:
    FooBase:
      type: object
      properties:
        bar:
          type: string
        baz:
          type: string
    FooCreate:
      allOf:
        - $ref: '#/components/schemas/FooBase'
        - type: object
          required:
            - bar

New behavior

A field will be required if it was marked required in the base schema or the derived schema. There is no way to remove a required restriction in a derived schema. This is because for a message to be valid under an allOf, it must be valid under all of the parent schemas.

When using allOf with a reference to a base schema and then marking
fields as required in a second schema, those fields are now correctly
generated as required in the derived class.

Properties inherited from referenced models are now updated to reflect
required field overrides from the containing schema after all allOf
schemas and their required fields are collected.
Add test_allof_required_override to verify that properties inherited
from a base schema via allOf can be correctly marked as required in
the derived schema's required list.
Add AllOfRequiredBase and AllOfRequiredDerived schemas to baseline
specs to verify the generated code correctly handles required field
overrides in allOf schemas. Update golden records accordingly.
@peter-goldstein peter-goldstein marked this pull request as draft January 9, 2026 13:34
@peter-goldstein peter-goldstein marked this pull request as ready for review January 9, 2026 13:34
@dbanty dbanty added this pull request to the merge queue Jan 10, 2026
Merged via the queue into openapi-generators:main with commit e428569 Jan 10, 2026
22 checks passed
@knope-bot knope-bot bot mentioned this pull request Jan 10, 2026
github-merge-queue bot pushed a commit that referenced this pull request Jan 10, 2026
> [!IMPORTANT]
> Merging this pull request will create this release

## Fixes

- Apply required overrides from allOf schemas (#1384)
- Sort lazy imports to increase stability of generated code (#1378)

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants