OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Kotlin-Spring]: Free-form parameter should not generate a @RequestParam annotation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Free-form query param spec generated spring @RequestParam annotation when it should not.
openapi-generator version
Using version 6.4.0
Technically not a regression since the issue which was supposed to fix it did fix it only partially (see #8080).
OpenAPI declaration file content or url
Could be reproduce with both definitions below
Inline schema definition
openapi: 3.0.0
servers:
- url: 'localhost:8080'
info:
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pony:
get:
operationId: list
parameters:
- in: query
name: pageQuery
schema:
type: object
additionalProperties:
type: string
Separate schema definition
openapi: 3.0.0
servers:
- url: 'localhost:8080'
info:
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pony:
get:
operationId: list
parameters:
- in: query
name: pageQuery
required: false
style: form
explode: true
schema:
$ref: '#/components/schemas/SearchCriteria'
components:
schemas:
SearchCriteria:
type: object
additionalProperties:
type: string
Generation Details
Maven plugin
Steps to reproduce
Run KotlinSpringServerCodegenTest.doNotGenerateRequestParamForObjectQueryParam with either of the definitions listed above.
The test will fail.
Related issues/PRs
Issue #8080 was supposed to fix it but it only works when the model definition is fixed.
We target a dynamic Map<String, String> (hence the additionalProperties) to implement a dynamic search: we can't possibly list all possible criteria.
Suggest a fix
Looks like the mustache template is src/main/resources/kotlin-spring/queryParams.mustache but my knowledge ends there. I don't know how to add additional condition to mustache.
A condition which would involve something along the lines:
- query parameter
- schema is an object no matter how it's defined
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/main/resources/kotlin-spring/queryParams.mustache and run KotlinSpringServerCodegenTest.doNotGenerateRequestParamForObjectQueryParam using either OpenAPI definition from the issue. Trace how object query parameters with additionalProperties are rendered. Done means the test passes and the generated parameter no longer has an unnecessary @RequestParam annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100