Skip to content

Spring Data REST Excerpt projections are missing from spec #2581

Open
@janjouketjalsma

Description

@janjouketjalsma

Describe the bug
Spring Data REST allows you to define an excerpt projection for an entity. Adding this will automatically embed this projection whenever the entity is shown as part of a parent collection.

From the docs:

(...) The preceding example directs Spring Data REST to use the NoAddresses projection when embedding Person resources into collections or related resources.

It looks like this excerpt projection functionality is not (correctly) covered by Spring Doc because the embed is not showing up in the generated OpenAPI spec.

To Reproduce
Steps to reproduce the behavior:

  • Spring Boot: 3.2.5
  • Packages:
    • org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0
    • org.springdoc:springdoc-openapi-starter-webmvc-api:2.5.0
    • org.springdoc:springdoc-openapi-starter-common:2.5.0
  • Steps
    • Create an entity with a relationship to another entity
    • Create an excerpt projection for the second entity
    • Check the OpenAPI spec for the first entity and verify if the excerpt projection is part of it

Reproducer project: https://github.com/janjouketjalsma/spring-doc-excerpt-projection-issue-reproducer

Current behaviour
Only the direct properties of the main entity end up in the spec.

      "EntityModelBookStoreEntity": {
        "required": [
          "books",
          "name"
        ],
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "_links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },

Expected behavior
I expect the excerpt projection to be part of the spec for the main entity.

Example: (Bookstore is the main entity, Book is the one with the excerpt projection)

      "EntityModelBookStoreEntity": {
        "required": [
          "books",
          "name"
        ],
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "_embedded" : {
            "type": "object",
            "properties": {
              "books": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "_links": {
                      "$ref": "#/components/schemas/Links"
                    }
                  }
                }
              }
            }
          }
          "_links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },

(or maybe with a $ref, not sure what would be the implementation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions