springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

Class in List<Class> is not published to the Schema since OAS 3.1

Open learnerbyheart opened this issue 1 year ago • 1 comments

Describe the bug

Since OpenApi Specificiation 3.1 springdoc does not publish a class (e.g. Member) to the schema in Swagger UI when the class is used in a collection (e.g. List<Member) members). Swagger UI shows the error: Could not resolve reference: JSON Pointer evaluation failed while evaluating token "Member" against an ObjectElement

This does not occur with OpenApi Specifiction 3.0.

To Reproduce

Minimal Spring application with spring-boot-starter-web (3.2.2) from Spring Initializr, springdoc-openapi-starter-webmvc-ui (2.3.0) and springdoc.api-docs.version=openapi_3_1: https://github.com/learnerbyheart/spring-doc

  • Provide with a sample code (HelloController) or Test that reproduces the problem
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping
    public List<String> test(@RequestBody Test test) {
        return List.of("1");
    }
}

public record Test(List<Member> members) {
}


public record Member(String name) {
}

application.properties springdoc.api-docs.version=openapi_3_1

  • What version of spring-boot you are using? Spring Boot 3.2.2
  • What modules and versions of springdoc-openapi are you using? springdoc-openapi-starter-webmvc-ui 2.3.0
  • What is the actual and the expected result using OpenAPI Description (yml or json)?

Actual JSON


{
  "openapi": "3.1.0",
  "info": {
    "title": "OpenAPI definition",
    "version": "v0"
  },
  "servers": [
    {
      "url": "http://localhost:8080",
      "description": "Generated server url"
    }
  ],
  "paths": {
    "/test": {
      "get": {
        "tags": [
          "test-controller"
        ],
        "operationId": "test",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Test"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Test": {
        "properties": {
          "members": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Member"
            }
          }
        }
      }
    }
  }
}

Expected behavior

The Member class should be added to the schema.

Expected JSON

{
  "openapi": "3.1.0",
  "info": {
    "title": "OpenAPI definition",
    "version": "v0"
  },
  "servers": [
    {
      "url": "http://localhost:8080",
      "description": "Generated server url"
    }
  ],
  "paths": {
    "/test": {
      "get": {
        "tags": [
          "test-controller"
        ],
        "operationId": "test",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Test"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Member": {
        "properties": {
          "name": {
            "type": "string"
          }
        }
      },
      "Test": {
        "properties": {
          "members": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Member"
            }
          }
        }
      }
    }
  }
}

Screenshots

grafik

learnerbyheart avatar Feb 05 '24 14:02 learnerbyheart

Hi, this should be same as #2448

GooDer avatar Feb 06 '24 07:02 GooDer

@learnerbyheart,

this is an issue related to swagger-core as shared in https://github.com/springdoc/springdoc-openapi/issues/2448

bnasslahsen avatar Mar 03 '24 09:03 bnasslahsen