swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

how to use @Example。Why I use @Example no effect

Open rim-wood opened this issue 9 years ago • 8 comments

_20170512160802

i copy this code in https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs/src/test/java/io/swagger/resources/ClassWithExamplePost.java but no effect

_20170512160835

rim-wood avatar May 12 '17 08:05 rim-wood

@rim-wood can you share the swagger.json you're getting?

webron avatar May 15 '17 19:05 webron

@webron this is part of my swagger.json

"/surviveevent/external/info": { "post": { "tags": [ "surviveevent" ], "summary": "test", "description": "", "operationId": "postTest", "consumes": [ "application/json" ], "produces": [ "application/json" ], "parameters": [ { "in": "body", "name": "test", "description": "test", "required": false, "schema": { "type": "array", "items": { "type": "string" } }, "x-examples": { "application/json": "["a","b"]" } } ], "responses": { "default": { "description": "successful operation" } } } },

and x-examples is exist,but swagger-ui is not show. otherwise,use @ApiImplicitParam, for example,@ApiImplicitParam(name="id",value="幸免事件id",dataType = "String").the swagger.json does not exist description in parameters

rim-wood avatar May 18 '17 01:05 rim-wood

Right. The current version of swagger-ui doesn't support the x-example/s extensions. It should work if you provide the example through the model itself.

webron avatar May 18 '17 16:05 webron

@webron yes,if i provide the example through the model,this is work. but you know, The add and modified is different,add method may be need more param. if i use @ApiModelProperty , That means add and modified show the some param in swagger-ui. for example, the model hava 4 param in add method,and is required in addition to facilityCode. _20170519092541 _20170519095322 but in edit method, facilityCode is required,the other is not. _20170519094042 _20170519094331 I do not know whether you understand what I mean,if you hava solution,please tell me

rim-wood avatar May 19 '17 01:05 rim-wood

Yeah, I understand. However, when it comes to Swagger, there's no simple solution to it because of how JSON Schema works. Effectively you'd need to create two different classes where in one the field is required and in the other it is not. Those classes can of course inherit from each other.

webron avatar May 19 '17 18:05 webron

@webron ok,i see, thank you very much

rim-wood avatar May 22 '17 01:05 rim-wood

@webron I meet the same issue. I don't want to show the model schema because of to large. I try to use @example annotation but not work. swagger-jersey2-jaxrs:1.5.16 swaggerUI:3.3.2 swagger.json generated by annotation: wx20171024-134902 2x code: public Response registerApp(@HeaderParam("X-Auth-Token")String token, @PathParam("registeredSystem") RegisteredSystem registeredSystem, @ApiParam(value = "request", examples = @Example(value = { @ExampleProperty(mediaType="application/json", value="[\"a\",\"b\"]") })) ApplicationRegistrationCreateRequest request) {...}

huduan-D avatar Oct 24 '17 05:10 huduan-D

请问下有什么解决方案没有

Would you please tell me what the solution under no

qiaolin-li avatar Jan 13 '18 14:01 qiaolin-li