数组的开放API可选查询参数值

问题描述

解决

在 YAML 之下似乎是表达我想要的东西的正确方式。

  '/user/{userId}/{parameters}':
    get:
      tags:
        - User
      summary: Get data for a user by ID
      operationId: getUserById
      parameters:
        - name: userId
          in: path
          description: The user ID required to fetch user data
          required: true
          schema:
            type: string
        - name: parameters
          in: path
          description: Parameters that Could be sent
          required: true
          schema:
            type: array
            items: 
              type: string
              enum:
                - balance
                - walletAddress
                - userId
                - email
                - name

原始问题

假设我有一个类似的 api 端;

/api/v1/users/{userid}?fields={listofFields}

所以用户可以传递一个查询,如;

/api/v1/users/123?fields=username,email,phonenumber => returns username,email and phone number of the user

但是,如果只传递了 username,它也应该返回响应

/api/v1/users/123?fields=username => returns username only

我无法确定这是否有效。如何记录/定义此类端点?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)