Equivalent annotation when migrating swagger 1.5.x to 2.2.x - spring-boot

I am stuck with a version compatibility issue between springboot 2.6.x and springfox 2.9.2. I tried multiple solutions but nothing seems to work thus defaulting back to the suggestions from Spring where we need to migrate springfox to springdoc
I am updating all the swagger annotation as suggested here.
In my old annotation of #ApiResponse I am using response as below:
#ApiResponses(value = [
ApiResponse(code = 200, message = "Successful", response = MyResponse::class)
Swagger 2.x.x does not seem to have any alternative to response that I have as above.
Any suggestions on what can be used instead to maintain the same behaviour ?

Posting for others.
It can be done in the following manner:
#ApiResponse(responseCode = "200", description = "Successful",
content = #Content(schema = #Schema(implementation = MyResponse.class)))

Related

Swagger on Spring Boot Actuator

I'm documenting my API with Swagger and I'm applying the following annotation to all of my REST Controllers:
#Api(value = "Some value", description = "Some Description", tags = {"Tag Tag Tag"})
However, I also want to include the endpoints provided by Spring Boot Actuator (/health, /info) on Swagger (and they are being included), however I can't seem to find a way to change their default description, tags, and title, among other swagger properties.
Is there a way to do this? Thanks in advance.

generate sample example in swagger UI (in Spring boot project)

I am using a spring boot application and have configured using Swagger UI.
I want to know whether we could pre-populate the example value with sample value so we can hit the "Try it out!" button without having to type in some sample values to get a response.
It must be present there.
Is there a way we can do this using annotations or a separate file which Swagger uses?
I am using a spring boot project with springfox-swagger2:2.7.0 and springfox-swagger-ui:2.7.0 with dependencies added using gradle.
Since the #ApiParam properties example and examples are not working (see this issue on GitHub), support for adding examples is limited/non existing.
What you can do for simple parameters (#RequestParam) is to add the #ApiParam annotation with the defaultValue property, like this:
#GetMapping
public List<Foo> findAll(
#RequestParam(required = false)
#ApiParam(defaultValue = "foo") // Put the default value here
String input) {
// ...
}
However, there is no support yet for doing this with #RequestBody parameters.
A possible workaround for #RequestBody parameters is by clicking on the code box at the right side of the Swagger tester, where it says Example value. If you click on it, it will insert that example into the field itself.
Here is a workaround for providing an example:
Inject html into swagger
#ApiParam(
name="whatever",
value="whatever",
defaultValue="none</p><p>Example: xyz</p>"
)
They don't protect against it in the latest version 2.9.2.

Spring boot with SpringFox Swagger UI Generates all Verbs

I enabled API documentation using Swagger 2.6.1 in my spring boot app. The page(swagger-ui.html) loads fine but controller documentation contains all the verbs(PUT, GET, PATCH, POST, etc) even if my controller only has a GET operation. How can I disable the other verbs in the UI doc?
This happens when you have mapping like this in your controller
#RequestMapping(value = "/productDetails")
Springfox cannot identify what is the requestMethod hence it provides all mapping.(Eventhough the default is GET)
If you change this to
#RequestMapping(value = "/productDetails", method = RequestMethod.GET)
Then you will see only GET mapping and not others.
If you use newer versions of Sprinboot, you can use #GetMapping or #PostMapping instead of #RequestMapping

Setting max-file-size for multipart uploads in spring boot using Jersey-multipart

I've tried setting this with the spring properties:
spring.http.multipart.file-size-threshold=0
spring.http.multipart.max-file-size=10Mb
spring.http.multipart.max-request-size=10Mb
...but that doesn't seem to do anything when using jersey multipart.
How can I set this max-file-size when using jersey?
EDIT: added code
application.properties
multipart.max-file-size=30MB
multipart.max-request-size=30MB
resource.java
#POST
#Consumes(MediaType.MULTIPART_FORM_DATA)
public TmpFileInfoDto store(
#NotNull #Valid #FormDataParam("file") final File file,
#FormDataParam("file") final FormDataBodyPart formDataBodyPart) throws IOException {
// upload to S3, add DB record, etc
}
#VelNaga have anwser in the comments for me, to make easy to find this answer I am reposting the comment on the answers.
Which spring-boot version are you
using?spring.http.multipart.max-file-size=10Mb will work only for
spring-boot 1.4.0 and above.For spring-boot version less than 1.4 use
multipart.max-file-size=10Mb.If you are using jersey client then
please share the code otherwise we could not help you.

spring-integration-dsl-groovy-http return null when i use httpGet method

I use spring integration 4.1.4 and spring integration dsl groovy 1.1.0
I included spring integration core, http in dependency.
When i am executing spring integration dsl groovy http sample, it throwing null value in console. I am not sure what i missed.
Here is my code looks like
IntegrationBuilder builder = new IntegrationBuilder("http");
def flow = builder.messageFlow {
transform {"http://www.google.com/finance/info?q=$it"}
httpGet(url:{"${it}"},responseType:String)
}
Object result = flow.sendAndReceive("vmw");
Can someone please help me?
This has been fixed on the master branch. Meanwhile a simple work-around is
url:{"http://www.google.com/finance/info?q=$it".toString()}
or
url:{"http://www.google.com/finance/info?q=$it" as String}
What version of the DSL? You need to build from master to use with Spring Integration 4.1.x.
I will warn you that the groovy DSL has had little attention done for several years; it was never really gained any traction in the community.
The Java DSL is preferred; it is actively maintained and enhanced.
I've just tested your case and haven't seen any null value, but there was another error like this:
Caused by: java.lang.IllegalStateException: 'uriExpression' evaluation must result in a 'String' or 'URI' instance, not: class org.codehaus.groovy.runtime.GStringImpl
So, it is really a bug and feel free to raise a JIRA ticket and will take care soon.
From other side, please, let me ask the question to you: what is the reason to be on this non-stable, unmaintained stuff, when we have already Java DSL. From other side we can use any Spring Integration namespace from the regular Spring Groovy Configuration support, for example:
beans {
xmlns([si: 'http://www.springframework.org/schema/integration'])
def headers = environment.getProperty('headers')
def parser = new JsonSlurper()
def result = parser.parseText(headers)
si.channel(id:'input')
si.channel(id:'output')
si.'header-enricher'('input-channel':'input','output-channel':'output') {
result.each {k,v->
si.'header'(name:k,expression:v)
}
}
}

Resources