New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ApiModelProperty required field seems to get ignored #542
Comments
Hi, it seems like there are some combinations of "where" annotations live that is causing some annotations to be ignored. For example, having @xmlelement annotations seem to cause headaches for the @ApiModelProperty annotations. Can you please post more details on your pojos? From the petstore sample, this: @XmlRootElement(name = "Pet")
public class Pet {
private long id;
@ApiModelProperty(value = "pet id", required=true)
public long getId() {
return id;
} appears correct: "Pet": {
"id": "Pet",
"required": [
"id"
],
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "pet id"
},
|
@fehguy , thanks for your reply, it gave me quite an insight on how to make it work actually. From what I noticed is that the difference between our annotations is that I had put the annotations above the variable and not above the getter method. @ApiModel(value = "Model", description = "Model description")
public class Model {
@ApiModelProperty(value = "variable0", required = true)
private String variable0;
...
public String getVariable0(){
return variable0;
}
...
} to: @ApiModel(value = "Model", description = "Model description")
public class Model {
private String variable0;
...
@ApiModelProperty(value = "variable0", required = true)
public String getVariable0(){
return variable0;
}
...
} it showed the required ones. To me this seems that the annotation directly above a variable does not work properly. So there is a work-around available (or this is working as intended and we were implementing it wrongly.) the json returned looks like this now (a shorter version than i previously posted though): "models" : {
"Model" : {
"id" : "Model",
"description" : "Model description",
"required" : [ "variable0" ],
"extends" : "",
"properties" : {
"variable0" : {
"type" : "string",
"description" : "variable0"
},
It also looks like that the "value = variable0" was ignored as well when putting the annotation above the variables as it now shows two extra fields in the json file;
The pojos that we have annotated are basically nothing more than shown here, just a class with variables,a getter and a setter. |
Hi, I just wrote a unit test to see if we get the right thing from your model. This what I see: [
{
"id": "AnnotatedPOJO",
"required": [
"variable0",
"variable1",
"variable3"
],
"properties": {
"variable0": {
"type": "string",
"description": "variable0"
},
"variable1": {
"type": "string",
"description": "variable1"
},
"variable2": {
"type": "string",
"description": "variable2"
},
"variable3": {
"type": "integer",
"format": "int32",
"description": "variable3"
}
}
}
] So something else is going on. What version of swagger-core are you using? Can you try 1.3.5? Are you using OSGi or something else? |
Hi, I had send the same issue to the guys from swagger-spring-mvc and it seems that they have not implemented this yet. The output I receive is exactly the same for me, to bad that this is more of a work around for their library. Other variables besides "required" and "value" are not working(, yet I presume.) Thanks again for your help as it made the "required" fields on the variables work, which was the most important thing for us to have. |
thanks for the follow-up--I'll reference the issue in swagger-spring MVC for others, and close this: |
… those fields which have public accessory method (getter)
… those fields which have public accessory method (getter)
We noticed that the models in Swagger UI is always showing optional behind the datatype;
Our model looks like this;
The json that gets returned from api-docs/my-controller;
As can be seen, the json returned is lacking any kind of field to show that the fields in the model are required. However it does show the "required" field we have defined in the method in our controller.
Now this is quite a blocker for us as some values truly are required and we would love to use this in our swagger but can't as of now. We were discussing if this was a problem caused by swagger-springmvc or by swagger-core but we are not sure which one it is.
Any help would be very much appreciated!
The text was updated successfully, but these errors were encountered: