UI show required parameter as optional.

313 views
Skip to first unread message

Fernando Gandini

unread,
Feb 10, 2016, 11:13:47 AM2/10/16
to Swagger
Hi guys, I´m using the annotation on my beans to set required and non required parameters, but Swagger UI seems not reading the properties correctly. Here is my bean and what Swagger show.
Can anyone help me please?
Thanks

BEAN :
@JsonInclude(JsonInclude.Include.NON_NULL) 
public class ProcessoInsert {
    
    @NotNull
    @ApiParam(required = true)
    @JsonProperty("id_ocorrencia")
    public Integer idOcorrencia;
    
    @NotEmpty
    @ApiParam(required = true)
    @JsonProperty("descricao")
    public String dsDescricao;
    
    @NotNull
    @ApiParam(required = true)
    @JsonProperty("id_status")
    public Integer idStatus;
    
    @Email
    @ApiParam(required = true)
    @JsonProperty("email_usuario")
    public String dsEmailUsuario;
    
    @ApiParam(required = false)
    @JsonProperty("id_departamento_encaminhado")
    public Integer idDepartamentoEnc;

}

SWAGGER:
ProcessoInsert {
id_ocorrencia (integer),
descricao (string, optional),
id_status (integer),
email_usuario (string, optional),
id_departamento_encaminhado (integer, optional)
}

tony tam

unread,
Feb 10, 2016, 11:23:56 AM2/10/16
to swagger-sw...@googlegroups.com
What version of swagger and which framework are you using?

--
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.

Fernando Gandini

unread,
Feb 10, 2016, 11:26:50 AM2/10/16
to swagger-sw...@googlegroups.com
Using swagger-core/jersey2-jaxrs -1.5.6
and Dropwizard.

You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/Ltl11ipCNTw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

tony tam

unread,
Feb 10, 2016, 11:30:20 AM2/10/16
to swagger-sw...@googlegroups.com
Try 1.5.7 please

Fernando Gandini

unread,
Feb 10, 2016, 11:40:52 AM2/10/16
to swagger-sw...@googlegroups.com
Still not working. Could be a problem with swagger-ui.js?

tony tam

unread,
Feb 10, 2016, 11:56:50 AM2/10/16
to swagger-sw...@googlegroups.com
I don’t think so, my guess is that swagger-core is not reading those annotations.  The best thing to share would be the swagger definition that is produced by scanning your beans.  Can you please share that?

Fernando Gandini

unread,
Feb 10, 2016, 12:09:31 PM2/10/16
to swagger-sw...@googlegroups.com
Sorry, but what do you mean by "swagger definition that is produced by scanning your beans" where do i find it?
Thanks alot.

Fernando Gandini

unread,
Feb 10, 2016, 1:20:48 PM2/10/16
to swagger-sw...@googlegroups.com
Problem seems to be solved by using  @ApiModelProperty(required = true) insted of @ApiParam(required = true)..it´s that right?!

tony tam

unread,
Feb 10, 2016, 1:46:31 PM2/10/16
to swagger-sw...@googlegroups.com
The swagger definition is the JSON that you’re loading in your swagger-ui.   For example:  http://petstore.swagger.io/v2/swagger.json.  That tells the UI what to render.

Fernando Gandini

unread,
Feb 10, 2016, 2:07:31 PM2/10/16
to swagger-sw...@googlegroups.com
Without @ApiModelProperty(required = true) and with @ApiParam(required = true)
"ProcessoInsert":{"type":"object","required":["id_ocorrencia","id_status"],"properties":{"id_ocorrencia":{"type":"integer","format":"int32"},"descricao":{"type":"string"},"id_status":{"type":"integer","format":"int32"},"email_usuario":{"type":"string"},"id_departamento_encaminhado":{"type":"integer","format":"int32"}

With @ApiModelProperty(required = true) and without @ApiParam(required = true)
"ProcessoInsert":{"type":"object","required":["descricao","email_usuario","id_ocorrencia","id_status"],"properties":{"id_ocorrencia":{"type":"integer","format":"int32"},"descricao":{"type":"string"},"id_status":{"type":"integer","format":"int32"},"email_usuario":{"type":"string"},"id_departamento_encaminhado":{"type":"integer","format":"int32"}

Seems that  @ApiModelProperty is the right anotation?

tony tam

unread,
Feb 10, 2016, 2:11:27 PM2/10/16
to swagger-sw...@googlegroups.com
Yes, @ApiParam is for operations, not model properties.  But I did expect that @NotNull annotation would be processed by the BeanValidations.java class in swagger core.

It was added in 1.5.7 so you should try that.

Fernando Gandini

unread,
Feb 10, 2016, 2:25:04 PM2/10/16
to swagger-sw...@googlegroups.com
I think things are different, right? You can not send a parameter, but when it sends, it can not be null.

I thing one says that you must send on every request and the other says that can not 
Reply all
Reply to author
Forward
0 new messages