Skip to content

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

@TMRGZ

Description

@TMRGZ

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
#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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions