Closed
Description
Describe the bug
DTO class defined as follows:
public class Item extends RepresentationModel<Item> {
@NonNull private String description;
}
A rest controller returning a collection of Items:
@GetMapping(produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<CollectionModel<Item>> getAllItems() {
...
}
Application property to prevent application/hal+json responses
spring.hateoas.use-hal-as-default-json-media-type=false
spring.jackson.default-property-inclusion=NON_ABSENT
Plain json response from the application as expected (response properties are links and content):
{
"links": [
{
"rel": "self",
"href": "http://localhost:8080/v1/items"
}
],
"content": [
{
"description": "foo",
"links": []
},
{
"description": "bar",
"links": []
}
]
}
- What is the actual and the expected result using OpenAPI Description (yml or json)?
Json produced by http://localhost:8080/v3/api-docs
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"tags": [
{
"name": "Item",
"description": "The Item API"
}
],
"paths": {
"/v1/items": {
"get": {
"tags": [
"Item"
],
"summary": "Get all items",
"operationId": "getAllItems",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CollectionModelItem"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"CollectionModelItem": {
"type": "object",
"properties": {
"_embedded": {
"type": "object",
"properties": {
"itemList": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Item"
}
}
}
},
"_links": {
"$ref": "#/components/schemas/Links"
}
}
},
"Item": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"_links": {
"$ref": "#/components/schemas/Links"
}
}
},
"Links": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Link"
}
},
"Link": {
"type": "object",
"properties": {
"href": {
"type": "string"
},
"hreflang": {
"type": "string"
},
"title": {
"type": "string"
},
"type": {
"type": "string"
},
"deprecation": {
"type": "string"
},
"profile": {
"type": "string"
},
"name": {
"type": "string"
},
"templated": {
"type": "boolean"
}
}
}
}
}
}
Note the hal representation, e.g. see _links in Item , expecting links
And properties for CollectionModelItem are _embedded and _links, expecting content and links
To Reproduce
Steps to reproduce the behavior:
-
spring-boot 2.3.3.RELEASE
-
spring-boot-starter-hateoas
-
spring-boot-starter-web
-
springdoc-openapi-ui:1.4.5
-
springdoc-openapi-hateoas:1.4.5
-
Example project attached
demo.zip
Expected behavior
- I would expect the generated json/Swagger-UI to match what the application is returning