[Java][okhttp-gson] oneOf with `not: enum` does not exclude matching string enum values
Description
For the Java okhttp-gson client, a property schema using not with a string enum is not enforced by the generated validateJsonElement method.
This can make a oneOf ambiguous even when the schemas are mutually exclusive according to the OpenAPI/JSON Schema definition.
OpenAPI Generator version
7.26.0-SNAPSHOT
Generator
java with library=okhttp-gson
OpenAPI definition
openapi: 3.1.0
info:
title: oneOf not enum repro
version: 1.0.0
paths: {}
components:
schemas:
Known:
type: object
required:
- kind
properties:
kind:
type: string
enum:
- known
Other:
type: object
required:
- kind
properties:
kind:
type: string
not:
enum:
- known
Union:
oneOf:
- $ref: '#/components/schemas/Known'
- $ref: '#/components/schemas/Other'The spec validates successfully with the OpenAPI Generator CLI. The validator only reports recommendations for unused models because there are no paths.
Current behavior
For Other.kind, the generated model validates that kind is a string, but does not enforce the nested:
not:
enum:
- knownAs a result, {"kind":"known"} matches both Known and Other, and deserializing Union fails because two oneOf schemas match.
Expected behavior
The generated validation for Other.kind should reject "known", so:
{"kind":"known"}matches onlyKnown- another string value such as
{"kind":"other"}matchesOther
Reproduction
With a generated Java client, deserializing {"kind":"known"} as Union currently fails with the oneOf multiple-match error.
A regression test covering both the known and unknown tag cases demonstrates the issue.
Proposed fix
For Java okhttp-gson, propagate string enum values from a property's composedSchemas.not metadata to the parent property and generate validation that rejects those values in pojo.mustache.
The change is intentionally limited to string enums under not; it does not claim general support for all not schemas or enum types.
Source: OpenAPITools/openapi-generator