0

在 RAML 1.0、API 平台 2.0 上使用连字符分隔的资源名称“/songs-list”创建 API Notebook 时,会出现以下错误: APINotebook 错误

API.createClient('client', '9c2861a1-b**b-401e-****-1ec*****b20c', 'testhyphen', '1.0.2');

$0=客户端已成功创建

client.songs-list.post[{"msg":"succ"}];

$1=ReferenceError: list is not defined
at eval (eval at <anonymous> (eval at value (https://cdn.anypoint.mulesoft.com/artifacts/exchange-ui/main.efc15523965187f6c807.js:1:998504)), <anonymous>:1:14)
at Object.eval (eval at value (https://cdn.anypoint.mulesoft.com/artifacts/exchange-ui/main.efc15523965187f6c807.js:1:998504), <anonymous>:3:8)
at e.value (https://cdn.anypoint.mulesoft.com/artifacts/exchange-ui/main.efc15523965187f6c807.js:1:998611)
at https://cdn.anypoint.mulesoft.com/artifacts/exchange-ui/main.efc15523965187f6c807.js:1:2212756
at h.run (https://cdn.anypoint.mulesoft.com/artifacts/exchange-ui/main.efc15523965187f6c807.js:1:282445)
at p (https://cdn.anypoint.mulesoft.com/artifacts/exchange-ui/main.efc15523965187f6c807.js:1:281939)
at nrWrapper (https://anypoint.mulesoft.com/exchange/9c2861a1-b**b-401e-****-1ec*****b20c/testhyphen/minor/1.0/:1:24554)

上述资产的 RAML 如下,资源名称为“/songs-list”:

     #%RAML 1.0
     title: testhyphen
     /songs-list:
        post:
          body:
            application/json:
          responses:
            200:
              body:
                application/json:
                  example: {"messgae": "Success"}

如果资源名称不包含“-”(连字符),例如当资源为 -“/songs”时,则 API 笔记本按预期运行。 API Notebook 成功

API.createClient('client', '9c2861a1-b**b-401e-****-1ec*****b20c', 'testset', '1.0.1');

$0=Client has been successfully created

client.songs.post[{"msg":"succ"}];

Code snippet executed with no results

4

1 回答 1

0

您可以使用此格式成功运行它:

clients['songs-list'].post[{"msg":"succ"}];

如果没有这种格式,它会将连字符视为减法运算符。由于 APINotebook 在 JavaScript 上运行,并且支持任何 JavaScript 语法,因此您可以查看如何在 JavaScript 中执行操作,它们应该可以与 APINotebook 一起使用。

于 2020-07-16T17:01:49.750 回答