我有一个rest资源扩展,我在其中指定了参数类型..但是我注意到我在POST或GET中得到的params与我的metadata.xml中的参数类型的类型不同。都是xs:string。但是,当我查看开箱即用的搜索API时,它确实尊重参数类型。我正在深入挖掘,我注意到在get-rsrc-list-query-rule()
中declare function conf:get-rsrc-list-query-rule() as element(rest:request) {
<rest:request
allow-post-alias="true"
fast-match="/*/config/resources"
uri="^/(v1|get-rsrc-list-query-ruleLATEST)/config/resources/?$"
endpoint="/MarkLogic/rest-api/endpoints/resource-list-query.xqy">
<rest:http method="GET">
<rest:param name="format" required="false" values="json|xml"/>
<rest:param name="refresh" required="false" as="boolean"/>
</rest:http>
</rest:request>
};
没有得到我的元数据规则我在metadata.xml中指定,但对于开箱即用的搜索休息api,它确实得到了正确的规则..
declare function conf:get-search-query-request-rule() as element(rest:request) {
<rest:request
allow-post-alias="true"
fast-match="/*/search"
uri="^/(v1|LATEST)/search(/)?$"
endpoint="/MarkLogic/rest-api/endpoints/search-list-query.xqy"
user-params="allow-dups">
<rest:http method="GET">
<rest:param name="q" required="false"/>
<rest:param name="format" required="false" values="json|xml"/>
<rest:param name="start" as="unsignedLong" required="false"/>
<rest:param name="pageLength" as="unsignedLong" required="false"/>
<rest:param name="category" required="false" repeatable="true"
values="content|metadata|{string-join(docmodcom:list-metadata-categories(),"|")}"/>
<rest:param name="options" as="string" required="false"/>
<rest:param name="collection" as="string" required="false" repeatable="true"/>
<rest:param name="directory" as="string" required="false" repeatable="false"/>
<rest:param name="view" as="string" values="metadata|results|facets|all|none"/>
<rest:param name="txid" as="string" required="false"/>
<rest:param name="database" required="false"/>
<rest:param name="transform" required="false"/>
<rest:param name="structuredQuery" required="false"/>
<rest:auth>
<rest:privilege>http://marklogic.com/xdmp/privileges/rest-reader</rest:privilege>
<rest:kind>execute</rest:kind>
</rest:auth>
</rest:http>
<rest:http method="POST">
<rest:param name="q" required="false"/>
<rest:param name="format" required="false" values="json|xml"/>
<rest:param name="category" required="false" repeatable="true"
values="content|metadata|{string-join(docmodcom:list-metadata-categories(),"|")}"/>
<rest:param name="start" as="unsignedLong" required="false"/>
<rest:param name="pageLength" as="unsignedLong" required="false"/>
<rest:param name="options" as="string" required="false"/>
<rest:param name="collection" as="string" required="false" repeatable="true"/>
<rest:param name="directory" as="string" required="false" repeatable="false"/>
<rest:param name="view" as="string" values="metadata|results|facets|all|none"/>
<rest:param name="txid" as="string" required="false"/>
<rest:param name="database" required="false"/>
<rest:param name="transform" required="false"/>
<rest:content-type>text/xml</rest:content-type>
<rest:content-type>text/json</rest:content-type>
<rest:content-type>application/xml</rest:content-type>
<rest:content-type>application/json</rest:content-type>
<rest:auth>
<rest:privilege>http://marklogic.com/xdmp/privileges/rest-reader</rest:privilege>
<rest:kind>execute</rest:kind>
</rest:auth>
</rest:http>
<rest:http method="HEAD"/>
<rest:http method="OPTIONS"/>
</rest:request>
};
而对于开箱即用的搜索休息api,会发送正确的规则
{{1}}
我想当我指定我的参数类型时,资源rest api将强制执行类型,否则会引发错误,但事实并非如此..它与开箱即用的api相关。
我不理解这个吗?我弄错了吗?如何告知其余资源扩展以遵守我的metadata.xml
中指定的参数类型答案 0 :(得分:1)
元数据是有关资源服务扩展的可选信息,您可以查看可用的扩展名。
文档以这种方式表达:
“如果扩展服务需要参数,您可以选择在安装扩展时使用请求参数'声明'参数。此信息是可以通过GET请求返回到/ config / resources的元数据。它不用于检查对扩展的请求的参数。“
http://docs.marklogic.com/guide/rest-dev/extensions#id_59112
“MarkLogic Server以XML或JSON格式返回已安装扩展的摘要....有关给定扩展的可用信息量取决于安装扩展时提供的元数据量。”
http://docs.marklogic.com/guide/rest-dev/extensions#id_73853
您可以将字符串强制转换为扩展中的任何类型,例如通过调用xs:int()或xs:double()。
希望有帮助,