heyile commented on issue #1688: [SCB-1828] Support @JSONVIEW 
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1688#issuecomment-609416298
 
 
   > ```java
   > (@RequestBody
   > ```
   
   
   > > > 
org.apache.servicecomb.swagger.generator.core.AbstractOperationGenerator#fillBodyParameter
 里调用的readAsProperty(type)是不是也应该改成 readAsProperty(type, JsonView), 
org.apache.servicecomb.swagger.generator.core.processor.annotation.AnnotationUtils#generateResponseProperty
 同理~
   > > 
   > > 
   > > 遗漏了一个场景.
   > > ```java
   > >   @PostMapping("/postUser")
   > >   public String userWithDefault(@RequestBody 
@JsonView(Person.Summary.class) Person person) {
   > >     return person.toString();
   > >   }
   > > ```
   > 
   > 这个如果不考虑swagger问题就不大 考虑swagger生成的话还得补上, 当前响应能够带jsonView感觉可以满足90%的使用场景了~~
   
   
   已经支持 @RequestBody @JsonView 的写法了.  关于契约这部分得在考虑下. swagger 对jsonview的支持有点怪异. 
使用 **swagger-core 1.5.22** 测试如下
   
   ```java
   
       @POST
       @Consumes({"application/json", "application/xml"})
       @Produces({"application/xml", "application/json"})
       public Response addPet(
               @ApiParam(value = "Pet object that needs to be added to the 
store", required = true) @JsonView(Person.Summary.class) Person body
               , @Context SecurityContext securityContext)
               throws NotFoundException {
           return Response.noContent().build();
       }
   
       @GET
       @Path("/findByStatus2")
       @Produces({"application/xml", "application/json"})
       @JsonView(Person.SummaryWithDetails.class)
       public Person findPetsByStatus2(
               @ApiParam(value = "Status values that need to be considered for 
filter", required = true, allowableValues = "available, pending, sold") 
@QueryParam("status") List<String> status
               , @Context SecurityContext securityContext)
               throws NotFoundException {
           return Person.generatePerson();
       }
   
   
   ```
   
   对应的swagger 如下, 也就是作为参数 @Jsonview 没有任何 swagger 上的变化,只是json系列化的时候做了特殊处理. 
但是作为返回, swagger 会根据view 生成 不通的definition.  **契约是基于swagger**的, 理想状态是和swagger 
标准保持一致.  
   
   ```
     /pet:
       post:
         operationId: "addPet"
         consumes:
         - "application/json"
         - "application/xml"
         produces:
         - "application/xml"
         - "application/json"
         parameters:
         - in: "body"
           name: "body"
           description: "Pet object that needs to be added to the store"
           required: true
           schema:
             $ref: "#/definitions/Person"
         responses:
           default:
             description: "successful operation"
     /pet/findByStatus2:
       get:
         operationId: "findPetsByStatus2"
         produces:
         - "application/xml"
         - "application/json"
         parameters:
         - name: "status"
           in: "query"
           description: "Status values that need to be considered for filter"
           required: true
           type: "array"
           items:
             type: "string"
             enum:
             - "available"
             - "pending"
             - "sold"
           collectionFormat: "multi"
         responses:
           200:
             description: "successful operation"
             headers: {}
             schema:
               $ref: "#/definitions/Person_SummaryWithDetails"
   definitions:
     Person:
       type: "object"
       properties:
         name:
           type: "string"
         age:
           type: "integer"
           format: "int32"
         account:
           type: "string"
         address:
           type: "string"
     Person_SummaryWithDetails:
       type: "object"
       properties:
         name:
           type: "string"
         age:
           type: "integer"
           format: "int32"
         account:
           type: "string"
         address:
           type: "string"
   
   ```
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to