Skip to content

Use AllowMultiple as signal for array query parameters#620

Open
rithwik-01 wants to merge 3 commits into
kubernetes:masterfrom
rithwik-01:fix-array-query-param-type
Open

Use AllowMultiple as signal for array query parameters#620
rithwik-01 wants to merge 3 commits into
kubernetes:masterfrom
rithwik-01:fix-array-query-param-type

Conversation

@rithwik-01

@rithwik-01 rithwik-01 commented Jun 27, 2026

Copy link
Copy Markdown

Use AllowMultiple() as the signal for emitting type: array in OpenAPI schemas instead of detecting a [] prefix on DataType. When AllowMultiple() is true, the [] prefix is only stripped to derive the element type.

Changes:

  • pkg/builder/openapi.go (v2): array detection via AllowMultiple(), CollectionFormat: "multi" always set for array params
  • pkg/builder3/openapi.go (v3): same, with Style: "form" + Explode: true for array params
  • []byte stays scalar naturally through OpenAPITypeFormat: no special guard needed
  • []string without AllowMultiple intentionally errors as a misconfiguration
  • Tests: table-driven, uses restfuladapter.ParamAdapter (same adapter as runtime)

Relationship to kubernetes/kubernetes#140050

This PR is a necessary precondition for fixing that issue, but does not close it alone. The Kubernetes apiserver's typeToJSON function (staging/src/k8s.io/apiserver/pkg/endpoints/installer.go) explicitly strips []string"string" and []int32"integer" with a TODO referencing the go-restful limitation this PR addresses. A companion PR to remove those cases from typeToJSON is needed to fully resolve the issue.

Refs: kubernetes/kubernetes#140050

When a restful parameter DataType is prefixed with '[]' (e.g. '[]string',
'[]integer'), emit type: array with the correct items sub-schema instead
of treating it as a scalar type.

This allows upstream callers to pass compound DataType values through
restful plumbing without losing the array semantics, fixing OpenAPI spec
generation for parameters like PodExecOptions.Command []string.

Related: kubernetes/kubernetes#140050
@kubernetes-prow kubernetes-prow Bot requested review from jpbetz and sttts June 27, 2026 05:02
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rithwik-01
Once this PR has been reviewed and has the lgtm label, please assign sttts for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 27, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @rithwik-01!

It looks like this is your first PR to kubernetes/kube-openapi 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-openapi has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 27, 2026
@rithwik-01

Copy link
Copy Markdown
Author

@jpbetz / @sttts Can you please review this PR? Happy to provide more context or make changes if needed.

…le/Explode for AllowMultiple

- Check OpenAPITypeFormat(dataType) before stripping [] prefix so known
  scalar types like "[]byte" (base64-encoded string) aren't incorrectly
  emitted as array[uint8].
- V2: set CollectionFormat="multi" when array parameter has AllowMultiple.
- V3: set Style="form", Explode=true when array parameter has AllowMultiple.

@Jefftree Jefftree left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if you can align to use AllowMultiple instead.

Replace []-prefix-based array detection with AllowMultiple() as the
canonical signal for emitting type: array in OpenAPI schemas. The []
prefix is only stripped to derive the element type.

V2: Always set CollectionFormat="multi" for AllowMultiple params.
V3: Always set Style="form" and Explode=true for AllowMultiple params.
[]string without AllowMultiple is treated as a misconfiguration.
@kubernetes-prow kubernetes-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 7, 2026
@rithwik-01

Copy link
Copy Markdown
Author

@Jefftree Thank you for the suggestion.
Updated to use AllowMultiple() as the sole signal for array detection:

  • AllowMultiple()=true → emits type: array with items; [] prefix is only stripped to derive the element type, not for detection
  • []byte stays scalar naturally through OpenAPITypeFormat — no special guard needed
  • []string without AllowMultiple intentionally errors as a misconfiguration (returns to pre-PR behavior rather than silently masking it)
  • V2: CollectionFormat: "multi" always set for AllowMultiple params
  • V3: Style: "form" + Explode: true always set for AllowMultiple params

@rithwik-01 rithwik-01 requested a review from Jefftree July 7, 2026 02:54
@rithwik-01

Copy link
Copy Markdown
Author

/assign

@rithwik-01 rithwik-01 changed the title Detect array query parameter types in OpenAPI builders Use AllowMultiple as signal for array query parameters Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants