Skip to content

Java wire tests fail when OpenAPI examples include additionalProperties fields #14545

@gavinsharp

Description

@gavinsharp

Bug Description

When an OpenAPI schema uses additionalProperties: true and the request body example includes fields that come from additionalProperties (not explicitly defined in the schema), the generated wire tests fail. The test generator uses the full example as the expected request body, but the generated typed builder only exposes methods for the explicit schema properties — so the actual serialized request never includes the additional fields from the example.

Reproduction

Given a schema like:

FHIRResource:
  type: object
  required:
    - resourceType
  properties:
    resourceType:
      type: string
    id:
      type: string
  additionalProperties: true

And a request body example like:

requestBody:
  content:
    application/fhir+json:
      schema:
        $ref: '#/components/schemas/FHIRResource'
      examples:
        create_patient:
          value:
            resourceType: "Patient"
            name:
              - family: "Doe"
                given: ["Jane"]
            gender: "female"
            birthDate: "1990-01-01"

The generated wire test expects the full example body (resourceType, name, gender, birthDate), but the generated builder call only sets resourceType:

FhirResource.builder()
    .resourceType("Patient")
    .build()

The builder does support .additionalProperty(key, value), but the test generator doesn't use it for the extra example fields.

Expected Behavior

Either:

  1. The test generator should use .additionalProperty() to set example fields that aren't explicit schema properties, or
  2. The expected request body in wire tests should only include fields that the builder actually sets

Environment

  • Fern CLI: 4.54.1
  • Java SDK generator: 4.0.9
  • enable-wire-tests: true

Workaround

We worked around this by removing additionalProperties fields from our OpenAPI examples, so the examples only reference explicitly-defined schema properties.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions