Skip to content

[BUG] [Spring] openapi-generator generates an incorrect stub for types named "Resource" #1680

@ErikGrimes

Description

@ErikGrimes
Description

openapi-generator generates an incorrect spring stub for types named "Resource"

openapi-generator version

3.3.4

OpenAPI declaration file content or url

api.yaml

openapi: 3.0.0
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
paths:
  /resources:
    get:
      summary: Returns a list of Resources.
      description: Optional extended description in Markdown.
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: "schema.json#/definitions/Resource"

schema.json

{
    "definitions": {
        "Resource": {
            "allOf": [
                {
                    "properties": {
                        "id": {
                            "type": "string"
                        }
                    }
                }
            ]
        }
    }
}
Command line used for generation
openapi-generator generate -g spring -i api.yaml -o generated -DdelegatePattern=true,hideGenerationTimestamp=true
Steps to reproduce

Invoke the command line above using the included api definitions.

Expected output

ResourcesApi

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (3.3.4).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
package org.openapitools.api;

import org.openapitools.model.Resource1;
import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
import java.util.Map;

@Validated
@Api(value = "resources", description = "the resources API")
public interface ResourcesApi {

    default ResourcesApiDelegate getDelegate() {
        return new ResourcesApiDelegate() {};
    }

    @ApiOperation(value = "Returns a list of Resources.", nickname = "resourcesGet", notes = "Optional extended description in Markdown.", response = Resource.class, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK", response = Resource.class) })
    @RequestMapping(value = "/resources",
        produces = { "application/json" }, 
        method = RequestMethod.GET)
    default ResponseEntity<Resource> resourcesGet() {
        return getDelegate().resourcesGet();
    }

}

Resource.java

package org.openapitools.model;

import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.Valid;
import javax.validation.constraints.*;

/**
 * Resource
 */

public class Resource   {
  @JsonProperty("id")
  private String id;

  public Resource id(String id) {
    this.id = id;
    return this;
  }

  /**
   * Get id
   * @return id
  */
  @ApiModelProperty(value = "")


  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }


  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    Resource resource = (Resource) o;
    return Objects.equals(this.id, resource.id);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Resource {\n");
    
    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(java.lang.Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }
}
Actual output

The generated code is missing the Resource.java file. ResourcesAPI.resourcesGet instead refers to

org.springframework.core.io.Resource

ResourcesApi

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (3.3.4).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
package org.openapitools.api;

import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
import java.util.Map;

@Validated
@Api(value = "resources", description = "the resources API")
public interface ResourcesApi {

    default ResourcesApiDelegate getDelegate() {
        return new ResourcesApiDelegate() {};
    }

    @ApiOperation(value = "Returns a list of Resources.", nickname = "resourcesGet", notes = "Optional extended description in Markdown.", response = org.springframework.core.io.Resource.class, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK", response = org.springframework.core.io.Resource.class) })
    @RequestMapping(value = "/resources",
        produces = { "application/json" }, 
        method = RequestMethod.GET)
    default ResponseEntity<org.springframework.core.io.Resource> resourcesGet() {
        return getDelegate().resourcesGet();
    }

}

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