OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][Spring] delegate pattern in combination with response wrapper generate code without delegate

Open
#17,261 2 comments 6 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
  • [ x] Have you provided a full/minimal spec to reproduce the issue?
  • [ x] Have you validated the input using an OpenAPI validator (example)?
  • [ x] Have you tested with the latest master to confirm the issue still exists?
  • [ x] Have you searched for related issues/PRs?
  • [ x] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version
  1. 6.6.0
  2. 7.1.0
  3. 7.2.0-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Bug Report
  version: 1.0.0
servers:
  - url: /api/v1
paths:
  /bug:
    get:
      summary: Simple method
      operationId: getBug
      responses:
        200:
          description: "OK"
          content:
            'application/json':
              schema:
                type: string
Generation Details

Maven configuration

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.1.0</version>
                <executions>
                    <execution>
                        <id>Generate sample</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/spec/sample.yml</inputSpec>
                            <apiPackage>com.sample.rest</apiPackage>
                            <modelPackage>com.sample.rest</modelPackage>
                            <generatorName>spring</generatorName>
                            <configOptions>
                                <sourceFolder>java</sourceFolder>
                                <dateLibrary>java8</dateLibrary>
                                <interfaceOnly>true</interfaceOnly>
                                <delegatePattern>true</delegatePattern>
                                <responseWrapper>DeferredResult</responseWrapper>
                            </configOptions>
                            <library>spring-boot</library>
                            <output>${project.build.directory}/generated-sources/server</output>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce
  1. Generate code
  2. Correct code with delegate is expected, here is what I got:
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-11-30T11:16:24.335072+01:00[Europe/Vienna]")
@Validated
@Tag(name = "bug", description = "the bug API")
public interface BugApi {

    /**
     * GET /bug : Simple method
     *
     * @return OK (status code 200)
     */
    @Operation(
        operationId = "getBug",
        summary = "Simple method",
        responses = {
            @ApiResponse(responseCode = "200", description = "OK", content = {
                @Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
            })
        }
    )
    @RequestMapping(
        method = RequestMethod.GET,
        value = "/bug",
        produces = { "application/json" }
    )
    
    org.springframework.web.context.request.async.DeferredResult<ResponseEntity<String>> _getBug(
        
    );
}

Expected result:

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-11-30T11:16:24.335072+01:00[Europe/Vienna]")
@Validated
@Tag(name = "bug", description = "the bug API")
public interface BugApi {

    /**
     * GET /bug : Simple method
     *
     * @return OK (status code 200)
     */
    @Operation(
        operationId = "getBug",
        summary = "Simple method",
        responses = {
            @ApiResponse(responseCode = "200", description = "OK", content = {
                @Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
            })
        }
    )
    @RequestMapping(
        method = RequestMethod.GET,
        value = "/bug",
        produces = { "application/json" }
    )
    
    default org.springframework.web.context.request.async.DeferredResult<ResponseEntity<String>> _getBug() {
        return getBug();
    }

    default org.springframework.web.context.request.async.DeferredResult<ResponseEntity<String>> getBug() {
        org.springframework.web.context.request.async.DeferredResult<ResponseEntity<String>> result =
                new org.springframework.web.context.request.async.DeferredResult<ResponseEntity<String>>();
        result.setResult(ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build());
        return result;
    }
}
Related issues/PRs
Suggest a fix

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 supplied OpenAPI declaration and Maven plugin configuration, generating the spring generator with the spring-boot library, interfaceOnly, delegatePattern, and DeferredResult responseWrapper options. Compare the generated BugApi interface with the expected output; done means the delegate methods and response wrapper are generated together without losing the delegate implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.