shashank created CAMEL-25510:
--------------------------------

             Summary: camel-openapi-java - the allowable values of an array 
parameter are generated as the enum of the array instead of its items, so the 
parameter accepts no value
                 Key: CAMEL-25510
                 URL: https://issues.apache.org/jira/browse/CAMEL-25510
             Project: Camel
          Issue Type: Bug
          Components: camel-openapi-java
            Reporter: shashank


For a Rest DSL parameter with {{dataType("array")}}, {{arrayType(...)}} and 
{{allowableValues(...)}}, {{RestOpenApiReader.defineSchemas}} (lines 812-854 at 
main c578a42a776d) sets the allowable values as the {{enum}} of the parameter 
schema, which is the array schema, and then adds an {{items}} schema without 
enum:

{code}
"schema" : { "type" : "array", "enum" : [ "red", "green", "blue" ], "items" : { 
"type" : "string" } }
{code}

In OpenAPI 3.0/3.1 (JSON Schema validation) {{enum}} constrains the whole 
value: an array is valid only if it is equal to one of the listed values, and 
those are strings or numbers, so no array is valid. Request validators built 
from the document reject every request with the parameter, and client 
generators produce a wrong type. The values restrict the items 
({{items.enum}}); camel-swagger-java was fixed for the same problem in 
CAMEL-12420, and the OpenAPI 2.0 path of camel-openapi-java (Camel 3.x) also 
set them on the items. The OpenAPI 3.0 path already set them on the parameter 
schema in Camel 3.20 (with the helper {{convertAndSetItemsEnum}}); CAMEL-20156 
later added the {{items}} schema next to that enum. The existing 
{{RestOpenApiReaderTest}} only checks that the enum text appears somewhere in 
the JSON.

h3. Reproduction

New {{RestOpenApiReaderArrayAllowableValuesTest}} (OpenAPI 3.0 and 3.1): a 
string array and an integer array with allowable values, and a string parameter 
with allowable values as the control. On main:
{noformat}
the array schema of 'colors' must not have an enum ==> expected: <null> but 
was: <[red, green, blue]>
{noformat}

h3. Proposed fix

{{defineSchemas}} creates the items schema first and sets the enum (converted 
to the item type as before) on the items. Parameters that are not arrays, and 
array parameters without allowable values, generate the same schema as before. 
Upgrade guide note for 4.23 (the generated document changes). 
camel-openapi-java tests with the fix: 99, 0 failures.

Found with a Lean 4 model of the generated parameter schema and JSON Schema 
validation (type, enum, items): "the schema accepts exactly the values the 
parameter allows" fails for {{["red"]}}, and main's schema is proved to reject 
every value of an array parameter with allowable values; the fix is proved to 
satisfy the property for all parameters and to generate the same schema as main 
for non-array parameters and arrays without allowable values. Confirmed with 
the real reader.

Affected: main, camel-4.22.x, camel-4.18.x, camel-4.14.x (same code, GitHub 
contents API; latest releases 4.22.1, 4.18.4, 4.14.9).

Duplicate check (2026-10-09, repeated in review): JIRA text "allowableValues" 
(CAMEL-12420 is the same problem in camel-swagger-java, CAMEL-20156 the 
NoSuchMethodException for non-JDK item types, CAMEL-9537 enum not output at 
all), "openapi" + "enum" (unrelated), component camel-openapi-java since 2025 
(13: CAMEL-24118 fixed seven other defects of the generated document, not this 
one); GitHub pull requests "openapi allowableValues", "openapi array enum", 
"RestOpenApiReader enum", "defineSchemas", "allowable values array": none. No 
open pull request changes {{RestOpenApiReader}}.

_Filed with Claude Code on behalf of allthingssecurity._




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to