Spring

Prevent ResponseEntity being generated as OpenAPI model

Posted on by  
Tom de Vroomen

When using Springfox you can annotate your endpoints to automatically generate OpenAPI docs for your clients.
This blogpost will show how you can prevent Springfox generating a model on an endpoint with ResponseEntity as return type.
I’ll also cover how to prevent generating default responses.

Take an endpoint like below.
You want to return ResponseEntity because you want control over the status and body which is returned within your endpoint code.

Click to see the Spingfox configuration used for this example

Now your generated OpenAPI doc contains responses with a $ref to ResponseEntity.

Springfox will also generate default responses for 201, 202, 400, 401, 403, 404, which you may never need.

Click to see the generated definition for ResponseEntity (it is quite long)

Continue reading →

Spicy Spring: Create your own ResourceLoader

Posted on by  
Willem Cheizoo

As a Spring developer we know how to load a resource in a Service. The prefixes of classpath: and file: are commonly used. But what if we want to load resources from a different location like a database table RESOURCE, with our own prefix db:? The Spring Framework provides some default built-in resource implementations, which can be found in the chapter Resources in the Spring Framework Reference Guide. The URL is prefixed and handled by the corresponding ResourceLoader (JavaDoc). If we want to load a resource from a database table RESOURCE we have to create our own ResourceLoader which triggers on the prefix db:.

Let's create an interface which describes the action of getting a resource based on the resourceName.

Continue reading →

shadow-left