OpenAPITools / OpenAPITools/openapi-generator
[BUG] Not possible to ever read object that sent as query parameter
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
Using OpenApi 3.0 and defining a query parameter that has object as value:
paths:
/archived-documents:
get:
tags:
- "Archived documents"
operationId: "getArchivedDocuments"
parameters:
- $ref: "#/components/parameters/documentId"
- $ref: "#/components/parameters/documentMetadata"
...
documentMetadata:
name: documentMetadata
in: query
schema:
$ref: "#/components/schemas/documentMetadata"
....
schemas:
documentMetadata:
description: The metadata associated with the document as key/value pairs
type: object
additionalProperties:
type: object
example:
metadataKey1: metadataValue1
metadataKey2: metadataValue2
metadataKey3: metadataValue3
The Maven plugin will generate server code that I use in my Spring Boot project.
The specific field is generated as:
@JsonProperty("documentMetadata")
@Valid
private Map<String, Object> documentMetadata = null;
Every other fields works OK except the documentMetadata field. There seems to be no way of sending this as query parameter to the server and get it properly made available in the code. My expectation is that the key/value-pairs are populated in this map.
I have tried various ways to send data to the server:
http://myapp/myservice?param1=A¶m2=B&documentMetadata[lookupkey]=123
This one fails with illegal character. If I URL encode it, the field on serverside has null value.
http://myapp/myservice?param1=A¶m2=B&documentMetadata={"partnerId":"123"} (and also URL encoded tried)
This one gives me error that it cannot cast String to Map: "Cannot convert value of type 'java.lang.String' to required type 'java.util.Map': no matching editors or conversion strategy found]"
openapi-generator version
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
OpenAPI declaration file content or url
See above.
Generation Details
No special usage.
Steps to reproduce
Create openapi 3 Swagger file as shown above. Generate code. Observe that there are no way to actually send these values to the server.
Related issues/PRs
Suggest a fix
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 the OpenAPI 3 query-parameter generation used by the Maven plugin for Spring Boot server code, using the provided documentMetadata object schema and request examples as the reproduction. Trace how the generated Map<String, Object> parameter is bound from query input, then verify that key/value pairs are available on the server without String-to-Map conversion errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100