【问题标题】:Can we use $ref in x-mediation-script?我们可以在 x-mediation-script 中使用 $ref 吗?
【发布时间】:2019-11-05 11:56:35
【问题描述】:

我将使用 x-mediation-script 对一些数据进行硬编码。我想在哪里使用将在 setPayloadjson 中调用的 $ref。这有可能我们可以做到吗?需要任何样品的建议

"x-mediation-script": "mc.setProperty('CONTENT_TYPE', 'application/json');mc.setPayloadJSON('$ref', '#/definitions/out');"

"definitions":{
  "out":{
    "type" : "object",
    "required": ["NAME"],
    "properties": {
      "NAME2": {"type": "string"},
      "NAME3": {"type": "string"},
      "NAME3": {"type": "string"},
      "NAME4": {"type": "string"},

    }
    }
  }

【问题讨论】:

  • swagger中的定义是一个payload对象,需要提供参数。为什么要在脚本中使用定义本身?

标签: wso2 wso2esb wso2-am wso2dss swagger-editor


【解决方案1】:

由于,

  1. x-mediation-script 在 JS 中,无法在代码中使用 swagger 语法。
  2. API 管理器不处理脚本。因此,在发布 API 时,只会将 x-mediation-script 内容复制到 synapse 文件中。

作为解决方案,在x-mediation-script中创建一个JS变量并使用它。

    mc.setProperty('CONTENT_TYPE', 'application/json'); // Set the content type of the payload to the message context
    var town = mc.getProperty('uri.var.town');          // Get the path parameter 'town' and store in a variable
    mc.setPayloadJSON('{ "Town" : "'+town+'"}');        // Set the new payload to the message context.

【讨论】:

    猜你喜欢
    • 2018-05-27
    • 2019-12-14
    • 2018-10-31
    • 2020-03-21
    • 2011-08-21
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多