【问题标题】:RAML Code understandingRAML 代码理解
【发布时间】:2018-05-23 08:11:21
【问题描述】:

我对设计simple RAML 有以下要求。我是RAML 编码的新手,所以想知道我的代码是否符合要求

要求:

  • 至少有 1 个带有 GET 和 POST 方法的端点。
  • 包括 API 的描述属性
  • 包括方法的描述属性
  • GET 请求采用“mulesoft”查询参数
  • 使用包含至少一个字符串和 整数数据类型
  • 包括一个 200 响应代码的示例,它与 上面定义的响应对象

我的代码:

#%RAML 1.0
title: Coding_Champions
version: 1.0.development
baseUri: http://localhost:8004/api
description: This API displays and adds Organisation with details

types:
  Org:
    type: object
    properties:
      name: string
      address: string
      pincode: integer
/details:
  displayName: Company Details
  description: Coding challenge which takes query parameter of "mulesoft"

  get:
    description: Retrieve a list of all the Orgs
    queryParameters:
      mulesoft: 
       description: Specify the Org name that you want to retrieve
       type:    boolean
       required: true
    responses:
      200:
        body:
          application/json:
            type: Org
            examples:
              MuleSoft:
                name: MuleSoft
                address: 77 Geary Street, Suite 400
                pincode: 94108
  post:
      description: Add a Org to list
      body: 
        application/json: 
            type: Org
            examples:
              Cognizant:
                name: Cognizant
                address: DLF
                pincode: 9771
      responses: 
        201:
          body: 
            application/json:
              example: |
                {
                "message":"New Org updated but not really"
                }                    

我更关心需求中的一点

"The GET request takes a query parameter of “mulesoft”

这是否意味着我应该在我的url 中动态地将mulesoft 作为参数传递,如果是,那么除了mulesoft 作为参数传递之外,它应该会引发错误?

(或)

这是否意味着我需要像现在一样在我的RAML 代码中硬编码“mulesoft”

你能澄清一下吗?

【问题讨论】:

  • 查询参数 mulesoft 的描述显示“指定要检索的组织名称”但类型为“布尔”。名称如何为布尔值?
  • 感谢您的回复..描述部分可以忽略..我写完了一些东西...

标签: mule raml


【解决方案1】:

这是否意味着我需要在我的 RAML 代码中硬编码“mulesoft” 现在完成了吗?

是的。您应该像现在一样在 RAML 中定义它。由于它是必需的参数,因此可以在实现中验证它的存在。

【讨论】:

  • 应该是布尔类型吗?
  • @Rahul,你的 api 请求 url 是什么,你会从客户端获取请求? A. :localhost:8004/api/details?mulesoft=abcxyz B:localhost:8004/api/details?orgName=mulesoft A 还是 B?
  • @Rahul,您是否假设在请求中发送“True”/“false”。如“mulesoft=true”。如果您将类型设置为布尔值,它会将值设置为 true/false 。但是,如果您希望它成为客户端必须发送的强制查询参数。然后属性“required=true”,就像您在 RAML 中已有的那样。
  • 我不确定我的问题实际上是关于它的。我对此感到困惑..它应该作为动态查询参数还是应该直接在 RAML 中定义
  • @Rahul ,您应该直接在 RAML 中定义,因为这将帮助客户了解究竟需要在请求中发送什么作为查询参数。如果您有查询参数的具体“键”,它的值可以在实现中进行检查和验证。就像有人想要检索所有使用 mulesoft 的组织一样。你可以有类似 "localhost:8004/api/details?mulesoft=true" 的东西。是的,它可以是布尔值。
猜你喜欢
  • 1970-01-01
  • 2015-02-25
  • 2012-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-13
相关资源
最近更新 更多