CAMEL-24118: Fix RestOpenApiReader to emit valid OpenAPI 3.x#24784
Conversation
… OpenAPI 3.x Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
gnodet
left a comment
There was a problem hiding this comment.
LGTM — comprehensive OAS 3.x compliance fixes.
Verification of key fixes:
-
formData → requestBody ✅ —
"in":"formData"is indeed illegal in OAS 3.x (onlyquery/header/path/cookieare valid). The new code correctly collects formData params and emits them as arequestBodywith an object schema under the appropriate media type. Themultipart/form-datadetection from theconsumeslist is a nice touch. -
collectionFormat mapping ✅ —
multi→DEEPOBJECTwas wrong;deepObjectis for bracket notation (filter[name]=value), not multi-value params. The fix (multi→FORM+explode: true,csv→FORM+explode: false) matches the OAS 3.x Parameter Serialization spec. -
boolean outType ✅ —
NumberSchema().format("boolean")→BooleanSchema()is clearly correct."type": "number", "format": "boolean"is not a valid JSON Schema type. -
Primitive-array outTypes ✅ — The old code discarded the computed typed schema and used empty items (
new Schema<>()). Now correctly wrapsprop(the typed schema) as array items when there's no$ref. -
byte[] outType ✅ —
ByteArraySchemafrom swagger-core correctly emitstype: string, format: byte, not the oldtype: number, format: byte. -
Response header typed schemas ✅ — Using
IntegerSchema/NumberSchema/BooleanSchemaclasses which populate bothtype(3.0) andtypesset (3.1), instead ofnew Schema().type(...)which only sets the 3.0 field. -
Array response headers ✅ —
setHeaderSchemaOas30now wraps items inArraySchemainstead of setting the inner type directly as the header schema.
Minor observations (non-blocking):
- The
openApiparameter increateHeaderTypedSchema()andcreateTypedSchema()is unused in those methods. The typed schema classes handle versioning internally. Not a bug — just a minor style note. - No new tests are added for these 8 fixes. The existing 97 tests pass, and the changes are structural (correct schema classes vs. raw schemas), but dedicated tests for formData-to-requestBody conversion and the collectionFormat mapping would strengthen confidence for future refactors.
Static analysis: Only pre-existing broad-exception-catch warnings. Nothing introduced by this PR.
Reviewed with Claude Code on behalf of @gnodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 56 tested, 29 compile-only — current: 56 all testedMaveniverse Scalpel detected 85 affected modules (current approach: 56).
|
Summary
Claude Code on behalf of davsclaus
Fixes a family of 7+ related defects in
RestOpenApiReaderwhere the generated OpenAPI 3.x documents are invalid or semantically wrong. All defects predate the swagger-core migration and were faithfully ported from the apicurio-era code.Fixes included
formData params — no longer emit illegal
"in":"formData". Instead, formData params are collected and emitted as arequestBodywithapplication/x-www-form-urlencoded(ormultipart/form-data) object schema, per OAS 3.x spec.collectionFormat -> style mapping —
multinow maps tostyle: form, explode: true(was incorrectlydeepObject).csvnow maps tostyle: form, explode: false(was missingexplode: false, silently getting multi semantics).boolean outType —
outType("boolean")now emitsBooleanSchema(type: boolean) instead ofNumberSchema.format("boolean")(type: number, format: boolean).Primitive-array outTypes —
outType("int[]"),outType("string[]")etc. now use the computed typed schema as array items instead of discarding it. Previously emitted{"type":"array","items":{}}.Response header types —
long,float,doublenow map to valid JSON Schema types:long->integer/int64,float->number/float,double->number/double. Previously emitted raw type strings which are not valid OAS 3.x types.Array response headers —
setHeaderSchemaOas30now wraps the inner type in anArraySchema. Previously set the inner type directly as the header schema, losing the array wrapper.OAS 3.1 type loss — response header schemas and byte[] now use typed schema classes (
IntegerSchema,NumberSchema,BooleanSchema,StringSchema) which correctly populate both thetypefield (3.0) andtypesset (3.1). Previously used rawnew Schema().type(...)which only sets the 3.0 field.byte[] outType — now uses
ByteArraySchema(type: string, format: byte) instead ofnew Schema().type("number").format("byte").Test plan
camel-openapi-javatests passCo-Authored-By: Claude Opus 4.6 noreply@anthropic.com