Skip to content

fix: explain nested arrays in styled parameters - #192

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/nested-array-style-error
Nov 22, 2026
Merged

mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/nested-array-style-error

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Closes #191
Refs oapi-codegen/oapi-codegen#2109

Problem

Styling an object that has an array property fails with unsupported type []T, which gives no hint about the cause. OpenAPI only defines style-based serialization for primitives, arrays of primitives, and flat objects, so an array nested inside a styled object has no wire format, the same as a nested object (#52). Nested objects already get an explicit error; nested arrays fell through to the generic branch.

Change

primitiveToString now returns an explicit error for a slice or array nested in a struct field, map value, or another array:

cannot serialize nested array of type []T: style-based parameter serialization ('style'/'schema') is only defined for primitives, arrays of primitives, and flat objects; declare the parameter with 'content: application/json' or 'style: deepObject' instead, or map the schema to a Go type implementing fmt.Stringer

[]byte keeps the previous message, since it is a string in OpenAPI terms and not an array.

Nothing that serialized before changes; this only replaces the error text for a case that already failed.

Testing

TestStyleParamNestedArrayError covers a struct field across the form, simple, label, and matrix styles in both explode modes, a map value, an array of arrays, and confirms deepObject still serializes the same struct.

🤖 Generated with Claude Code

An array nested inside a styled object, map, or array has no wire format
defined by OpenAPI, the same as a nested object. It failed with a bare
"unsupported type []T", which gave no hint about the cause. Return an
error naming the limitation and the alternatives (a `content` parameter
or `style: deepObject`), matching the existing nested-object error.

Closes oapi-codegen#191
Refs oapi-codegen/oapi-codegen#2109

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mromaszewicz
mromaszewicz requested a review from a team as a code owner November 22, 2026 04:52
@mromaszewicz mromaszewicz added the documentation Improvements or additions to documentation label Nov 22, 2026
@mromaszewicz
mromaszewicz merged commit b6aa2b1 into oapi-codegen:main Nov 22, 2026
10 checks passed
@mromaszewicz
mromaszewicz deleted the fix/nested-array-style-error branch November 22, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested arrays in styled parameters fail with a bare "unsupported type" error

1 participant