OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA/KOTLIN] [SPRING] A reactive controller that returns a JSON array of strings does not generate an object serializable by Jackson

Open
#19,153 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

When generating a reactive controller that should return a JSON array of strings should generate a method that returns Mono<ResponseEntity<List> or Mono<ResponseEntity<Set> depending on the uniqueItems flag instead of Flux.

Related Spring documentation: https://docs.spring.io/spring-framework/reference/web/webflux/reactive-spring.html#webflux-codecs-jackson

Related Stackoverflow question: https://stackoverflow.com/questions/48421597/returning-fluxstring-from-spring-webflux-returns-one-string-instead-of-array-o

openapi-generator version

7.7.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: OpenAPI Petstore
  description: "sample to get all user id as string list and string set"
  version: 1.0.0
tags: []
paths:
  /users/id?type=set:
    get:
      operationId: getUserIdSet
      tags:
        - users
      responses:
        '200':
          description: response
          content:
            application/json:
              schema:
                type: array
                "uniqueItems": true
                "items":
                  "type": "string"

  /users/id?type=list:
    get:
      operationId: getUserIdList
      tags:
        - users
      responses:
        '200':
          description: response
          content:
            application/json:
              schema:
                type: array
                "uniqueItems": false
                "items":
                  "type": "string"

Generation Details

Maven settings used:

<configuration>
    <inputSpec>${project.basedir}/api/api.yaml</inputSpec>
    <generatorName>spring</generatorName>
    <generateApis>true</generateApis>
    <generateModels>true</generateModels>
    <!-- configuration -->
    <configOptions>
       <interfaceOnly>true</interfaceOnly>
       <sourceFolder>/src/main/java</sourceFolder>
       <useSpringBoot3>true</useSpringBoot3>
       <reactive>true</reactive>
     </configOptions>
 </configuration>

Steps to reproduce
  1. Set up project
  2. mvn clean compile
Related issues/PRs

Related but affecting the Java client
https://github.com/OpenAPITools/openapi-generator/pull/16326

Suggest a fix

In case there there is an endpoint with application/json content type, create an exception to generate a collected collection of strings, the Kotlin Spring generator is affected too

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Spring generator using the supplied OpenAPI declaration and reactive configuration, then run mvn clean compile to inspect the generated controller signatures. Done means JSON array responses use Mono<ResponseEntity<List>> or Mono<ResponseEntity<Set>> according to uniqueItems, including for the Kotlin Spring generator.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin, spring
Domain
api, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.