Swagger-core Java Add constraints to a List of Strings

34 views
Skip to first unread message

Matt Goodwin

unread,
Apr 9, 2018, 2:40:22 PM4/9/18
to Swagger
Hi, 

Swagger-core v1.5.18

compile 'io.springfox:springfox-swagger2:2.8.0'
compile
'io.swagger:swagger-core:1.5.18'
compile
'io.swagger:swagger-annotations:1.5.18'
compile
'io.swagger:swagger-models:1.5.18'
compile
'io.springfox:springfox-swagger-ui:2.8.0'

I want to be able to add constraints to ensure that elements of a List are of a certain String length and of a particular pattern such as 

My original class is as follows:

private class MyRequest {
   
@Size(max=10)
   
private List<@Size(max = 10) @Pattern("^myPattern$") String> foo;
}


However, when checking the generated Swagger JSON, i was expecting... 

type: array
items:
  type: string
  minLength: 10
  pattern: ^myPattern$ 

but the items array only contained a type property

type: array
items:
  type: string

Is this possible and if so, how i can achieve this?

Ron Ratovsky

unread,
Apr 9, 2018, 3:04:47 PM4/9/18
to swagger-sw...@googlegroups.com

If you’re using springfox – you need to check with them by filing a ticket directly with the project.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Matt Goodwin

unread,
Apr 9, 2018, 3:56:52 PM4/9/18
to Swagger
ive tried without spring fox and its still the same problem :(

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Apr 9, 2018, 4:05:47 PM4/9/18
to swagger-sw...@googlegroups.com

This doesn’t make sense. Either you need to use Springfox or you need to use swagger-core, they serve different frameworks.

Which REST framework do you use?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--

You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Matt Goodwin

unread,
Apr 9, 2018, 4:17:22 PM4/9/18
to Swagger
i have also used the maven swagger plugin and the gradle swagger plugin to both generate the swagger json file and they all return the swagger json without the minLength and Pattern on the Items attribute

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Apr 9, 2018, 4:51:26 PM4/9/18
to swagger-sw...@googlegroups.com

That doesn’t answer my question though, and there’s a reason I ask.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Matt Goodwin

unread,
Apr 9, 2018, 5:16:59 PM4/9/18
to swagger-sw...@googlegroups.com
REST framework is Spring boot

Ron Ratovsky

unread,
Apr 10, 2018, 4:25:15 AM4/10/18
to swagger-sw...@googlegroups.com

If it’s Spring boot, then you have to use Springfox (can’t use swagger-core directly).

I don’t know if Springfox parses constraint annotations but it does not depend on swagger-core for that business logic.

Would suggest filing a ticket with Springfox.

Matt Goodwin

unread,
Apr 10, 2018, 4:44:58 AM4/10/18
to Swagger
Ok, well i've also got a project without the Springfox dependency that generates the swagger json in a gradle build using the Swagger gradle plugin and I have the same problem there too 

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Apr 10, 2018, 4:46:34 AM4/10/18
to swagger-sw...@googlegroups.com

Which is why you need to address that project.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Matt Goodwin

unread,
Apr 10, 2018, 5:13:50 AM4/10/18
to Swagger
ok so you're suggesting me raising this problem with both Springfox and the Swagger gradle plugin as these two projects both experience the same problem?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Apr 10, 2018, 5:48:03 AM4/10/18
to swagger-sw...@googlegroups.com

I don’t know how the gradle plugin works, so I can’t say whether it fully depends on springfox or not.

If you experience the issue with springfox solo, I’d start by filing a ticket on that project.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages