【问题标题】:I'm converting json to raml , for /alert it taking get proper response, but for /alert/{alertid}, its not taking response. Here is my raml code我正在将 json 转换为 raml ,因为 /alert 它得到了正确的响应,但对于 /alert/{alertid} ,它没有得到响应。这是我的 raml 代码
【发布时间】:2018-02-26 06:21:17
【问题描述】:

我正在将 json 转换为 raml ,以便 /alert/ 它得到正确的响应,但对于 /alert/{alertid},它没有得到响应。我想要特定 alertId API 的响应。这是我的 raml 代码。警报中有很多 id 我想要响应特定的 id 。对于特定的 id,我正在使用 API。

#%RAML 1.0
title: Test the load customer REST Services
version: 1.0
protocols: [ HTTPS ] 
baseUri: http://myapi.mysite.com/api/
mediaType: application/json
securitySchemes:
  basicAuth:
    description: Each request must contain the header
    type: Basic Authentication
    describedBy:
      headers:
        Authorization:
          description: Used to send
          type: string
      responses:
        401:
          description: |
            Provided username and password is invalid.
types: 
  alert:
    type: object
    properties: 
          id:  string
          description: string
          assetId:  string
          alertId: string
          code: integer
          ownerId?: string
          metadata: 
            type: object
            properties: 
                indicatorId: string

types:
  837a-dcf2a7d556c5:
    type: object
    properties: 
          id:  string
          description: string
          assetId:  string
          alertId: string
          code: integer
          ownerId?: string
          metadata: 
            type: object
            properties: 
                indicatorId: string
/alert:
    get:
        description: Get list of alert API.
        headers: 
        body: 
        responses: 
          200:
            body:
                type: !include alert.json
    /{alertId}:
            get:
                description: Get list of by Id.
                headers: 
                body: 
                responses: 
                    200:
                        body: 
                            type: !include 837a-dcf2a7d556c5.json

【问题讨论】:

  • 你的意思是它没有响应?此外,您不能两次声明类型,请删除第二次声明。为什么你在类型中使用 json 包含而不是使用你指定的 RAML 类型?

标签: javascript jquery json swagger raml


【解决方案1】:

你可以试试这样的:

#%RAML 1.0
title: Test the load customer REST Services
version: 1.0
protocols: [ HTTPS ] 
baseUri: http://myapi.mysite.com/api/
mediaType: application/json
securitySchemes:
  basicAuth:
    description: Each request must contain the header
    type: Basic Authentication
    describedBy:
      headers:
        Authorization:
          description: Used to send
          type: string
      responses:
        401:
          description: |
            Provided username and password is invalid.
types: 
  alert:
    type: object
    properties: 
          id:  string
          description: string
          assetId:  string
          alertId: string
          code: integer
          ownerId?: string
          metadata: 
            type: object
            properties: 
                indicatorId: string

  837a-dcf2a7d556c5:
    type: object
    properties: 
          id:  string
          description: string
          assetId:  string
          alertId: string
          code: integer
          ownerId?: string
          metadata: 
            type: object
            properties: 
                indicatorId: string
/alert:
    get:
        description: Get list of alert API.
        headers: 
        body: 
        responses: 
          200:
            body:
                application/json:
                    type: alert
    /{alertId}:
            get:
                description: Get list of by Id.
                headers: 
                body: 
                responses: 
                    200:
                        body:
                            application/json:
                                type: 837a-dcf2a7d556c5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多