Skip to content

[BUG][JAVA][SPRING] Validating of the REST API call fails when a request with required discriminator should be sent #25837

In review

Description

@LeosBitto

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

We use openapi-generator-maven-plugin to generate interfaces for the REST clients, which we then create using RestClient and HttpServiceProxyFactory. When a request with a required discriminator should be sent the validation of this request (by ResponseValidatingMethodInterceptor) fails, because the required discriminator value is not filled in yet (it would be done later by Jackson).

openapi-generator version

7.27.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Validation Probe API
  description: >-
    Neutral test-only contract exercising the shared validation of generated HTTP interface clients.
  version: 1.0.0
paths:
  /validation-probe/request/discriminator:
    post:
      tags: [ValidationProbe]
      operationId: writeDiscriminatedRequest
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DiscriminatedRequest'
      responses:
        '200':
          description: Payload accepted
components:
  schemas:
    DiscriminatedRequest:
      type: object
      discriminator:
        propertyName: type
        mapping:
          text: '#/components/schemas/DiscriminatedTextRequest'
      required: [type, value]
      properties:
        type:
          type: string
        value:
          type: string
    DiscriminatedTextRequest:
      allOf:
        - $ref: '#/components/schemas/DiscriminatedRequest'
Generation Details

Use openapi-generator-maven-plugin with generatorName=spring useBeanValidation=true

Steps to reproduce

Use the following code to create a REST API client using the generated interface as the target:

    public static <T> T createRestClientProxy(Class<T> target, RestClient restClient) {
        var adapter = RestClientAdapter.create(restClient);
        return HttpServiceProxyFactory.builderFor(adapter).build().createClient(target);
    }

Then call restClientProxy.writeDiscriminatedRequest(new DiscriminatedTextRequest().value("valid"));

Related issues/PRs

not found

Suggest a fix

Do not generate @NotNull for discriminator when Jackson is supposed to fill in the discriminator value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions