fix(java): serialize JSON header parameter content

Merged
AN
2mo ago
+838-2

Fixes #25055

Problem

For Java okhttp-gson clients, a header parameter defined using:

content:
  application/json:
    schema:
      type: object

was serialized through ApiClient.parameterToString(...).

For model objects, that produces the generated model's debug toString() representation instead of JSON.

Fix

  • Preserve whether a header parameter uses a JSON media type.
  • Serialize JSON-content header parameters through a dedicated JSON serialization path.
  • Escape non-ASCII characters as \uXXXX for ASCII-safe HTTP header values.
  • Preserve existing parameterToString(...) behavior for non-JSON headers.

Tests

Added:

  • DefaultCodegen regression coverage for JSON header parameter metadata
  • Java okhttp-gson generation regression coverage
  • a minimal OpenAPI 3.1 fixture

Verified:

  • generated header code uses parameterToJsonString(...)
  • {"path":"/x"} is produced for ASCII input
  • non-ASCII input such as /тест is escaped as \uXXXX
  • generated Java client compiles successfully

Summary by cubic

Fixes Java okhttp-gson clients sending JSON-content header parameters as the model's debug toString() output instead of JSON, in both static and dynamic operations paths.

  • Flags JSON media type headers on CodegenParameter via headerIsJsonMimeType.
  • Serializes flagged headers through a new parameterToJsonString(...), returning an empty string for null values and escaping non-ASCII characters as \uXXXX to keep headers ASCII-safe.
  • Static methods dispatch on the flag; dynamic operations check the parameter content for application/json.
  • Non-JSON headers keep the existing parameterToString(...) behavior.
  • Adds DefaultCodegen, generated-output, and sample ApiClient regression tests, plus an OpenAPI 3.1 fixture, and regenerates the okhttp-gson samples.