【问题标题】:WSO2 API Manager Two Parameters in BodyWSO2 API Manager 正文中的两个参数
【发布时间】:2020-01-31 03:40:01
【问题描述】:

我使用 API Manager 3.0.0 版。

在Resources的Publisher页面中,当类型为BODY时,我需要添加两个或多个参数,方法HTTP是POST,类似于,但参数为Body时只允许一个。

是否可以添加多个参数 BODY?以及如何?

编辑:

在 BODY 中可能有两个参数,在 API Publisher-> API Definition -> Edit 中使用此表单,编辑您需要的服务,类似于:

/v1/nipCliente: 
      post: 
        requestBody: 
          content: 
            application/x-www-form-urlencoded: 
              schema: 
                type: "object"
                properties: 
                  id_usuario: 
                    type: "string"
                  password: 
                    type: "string"
                  nip: 
                    type: "string"
          required: false
        responses: 
          200: 
            description: "ok"
        security: 
          - 
            default: []
        x-auth-type: "None"
        x-throttling-tier: "Unlimited"

在同一页面中看起来:

在 API Developer->Try Out 中,看起来类似于:

【问题讨论】:

    标签: wso2 wso2-am


    【解决方案1】:

    POST 中的多个正文参数,PUT 请求是不允许设计允许的,因为请求只能有一个有效负载。 [1]

    如果请求正文包含多个参数,可以将其作为单个 json 对象发送。

    应该修改后端服务方法以接受特定的对象模型。

    例如:假设我想将以下内容作为正文发送。

    {
       "name" : "Joe",
       "age" : 23,
       "grade" : 9
    }
    

    需要 Student 对象的后端服务方法。

    @POST
    public Response studentPost(Student student) {
    
    }
    

    学生对象

    public class Student{
       String name;
       int age;
       int grade;
    
       ... getters/ setters ...
    
    }
    

    或者,您可以使用不同的参数。即查询参数 + 正文 + 标题参数。

    [1]https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      • 2018-04-06
      • 1970-01-01
      相关资源
      最近更新 更多