Skip to content

SpringDoc - Adding extra object's wrong property #2959

Closed
@rksvtln

Description

@rksvtln

Describe the bug

  • Similar problem with this issue but there was no follow up from the reporter, hence, I created a new one SpringDoc - Adding extra object's properties #2824
  • In addition to issue described above, it happens on all object with an attribute name starts with 'set'.
  • This is the sample object generated by springdoc: "ting" was added incorrectly
    "SampleResponse":{"type":"object","properties":{"ting":{"$ref":"#/components/schemas/SampleResponse"},"id":{"type":"string","description":"ID"},"description":{"type":"string","description":"Description"},"setting":{"type":"string","description":"Setting"}}}

To Reproduce
Steps to reproduce the behavior:

  • I'm using org.springdoc:springdoc-openapi-starter-webmvc-ui-2.2.0 (tried to upgrade to 2.6.0 as well, but the issue is still there)
  • Sample code that produces the issue:

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController {

  @GetMapping("/sample")
  public ResponseEntity<SampleResponse> getSampleResponse() {
      return ResponseEntity.ok(new SampleResponse().id("12345").description("sample response").setting("sample setting"));
  }
}

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.swagger.v3.oas.annotations.media.Schema;

@JsonTypeName("sampleResponse")
public class SampleResponse {

  private String id;
  private String description;
  private String setting;

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

  @Schema(name = "id", description = "ID", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
  @JsonProperty("id")
  public String getId() {
      return id;
  }

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

  public SampleResponse description(String description) {
      this.description = description;
      return this;
  }

  @Schema(name = "description", description = "Description", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
  @JsonProperty("description")
  public String getDescription() {
      return description;
  }

  public void setDescription(String description) {
      this.description = description;
  }

  public SampleResponse setting(String setting) {
      this.setting = setting;
      return this;
  }
  @Schema(name = "setting", description = "Setting", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
  @JsonProperty("setting")
  public String getSetting() {
      return setting;
  }

  public void setSetting(String setting) {
      this.setting = setting;
  }
}

The sampleResponse in openapi json:
"SampleResponse": { "type":"object", "properties":{ "ting": { "$ref":"#/components/schemas/SampleResponse"}, "id": {"type":"string","description":"ID"}, "description": {"type":"string","description":"Description"}, "setting":{"type":"string","description":"Setting"} } }

Expected behavior

  • The incorrect extra field should not be shown

Additional context

  • I'm still using SpringBoot 3.3.x, so I cannot upgrade to latest at the moment
  • I'm using openapi-generator to generate the objects (the object above is an example how the object were generated)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions