toedter / spring-hateoas-jsonapi

A JSON:API media type implementation for Spring HATEOAS
Apache License 2.0
106 stars 15 forks source link

JsonApiModelBuilder return parameterized RepresentationModel<T> #52

Closed gaoyang-projects closed 2 years ago

gaoyang-projects commented 2 years ago

Spring HATEOAS and swagger.

use case: put something like requestid, timestamp into meta .

@GetMapping("/")
public RepresentationModel<?> someRequest(){

JsonApiModelBuilder builder = JsonApiModelBuilder.jsonApiModel().model(model);
RepresentationModel<?> build = builder.meta("timestamp", System.currentTimeMillis()).fields("user", "id","name").build();
return build;

}

when retuen RepresentationModel<?>, response body structure cannot be recognized by swagger

toedter commented 2 years ago

What is the JSON output of this request?

gaoyang-projects commented 2 years ago

JSON output structure is right on server.

just swagger cannot recognize problem. swagger example response : { "_links": { "empty": true } } if method return parameterized object swagger example reponse: @GetMapping("/") public User someRequest(){} { id": "1", "enabled": false }

because return type is '?', responsebody structure cannot be found through reflection by swagger

toedter commented 2 years ago

OK, I understand what you mean. Sorry, but you cannot use Swagger reflection here. And as you see in your example, the response is not valid JSON:API at all, but HAL representation.

gaoyang-projects commented 2 years ago

so in my case, i want use JSON:API structure and expand meta object or other property . if JsonApiModelBuilder return parameterized RepresentationModel like User user = new User(); JsonApiModel<User> build = JsonApiModelBuilder.jsonApiModel().model(user ).meta(...).build(); developer can see responsebody in swagger ui ,have any solutions?