首页 \ 问答 \ Marklogic Rest资源扩展不遵守metadata.xml(Marklogic Rest Resource extension not honoring metadata.xml)

Marklogic Rest资源扩展不遵守metadata.xml(Marklogic Rest Resource extension not honoring metadata.xml)

我有一个rest资源扩展,我在其中指定参数类型..但是我注意到我在POST或GET中得到的params与我的metadata.xml中的参数类型的类型不同。它们都是xs :串。 但是,当我查看开箱即用的搜索API时,它确实尊重参数类型。我正在深入挖掘,我注意到在/MarkLogic/rest-api/endpoints/config.xqyget-rsrc-list-query-rule()不会获取我在metadata.xml中指定的元数据规则,但是对于开箱即用的搜索休息api,它确实获得了正确的规则。

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>
};

而对于开箱即用的搜索休息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>
};

我想当我指定我的参数类型时,资源rest api将强制执行类型,否则会引发错误,但事实并非如此。它与开箱即用的api相关。

我不理解这个吗? 我弄错了吗? 如何告知其余资源扩展以遵守我的metadata.xml中指定的参数类型


I have a rest resource extension where I specify the parameter types.. But what I noticed is that params that I get in my POST or GET is of not the same type as the parameter type in my metadata.xml.. They are all xs:string. But when I look at the out-of-box search API, it does honor the parameter types.. I was digging a little deeper and I noticed that in /MarkLogic/rest-api/endpoints/config.xqy the get-rsrc-list-query-rule() does not get my metadata rules that I specified in metadata.xml, but for out-of-box search rest api, it does get the right rules..

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>
};

whereas for out-of the box search rest api, the right rules are sent

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>
};

I thought when I specified my parameter types, the resource rest api will enforce the types, else will raise an error, but that is not the case.. It does with the out-of-box rest api.

Am I not understanding this right ? Did I get all this wrong ? How do I tell the rest resource extension to honor my parameter types specified in my metadata.xml


原文:https://stackoverflow.com/questions/41875315
更新时间:2023-08-29 11:08

最满意答案

HTML5内置了很多内容,具有required属性和提供正则表达式pattern属性以进行验证的能力。 有些甚至是内置的,比如当你使用type="email"属性而不是type="text"

使用HTML5验证+ CSS3,您可以选择:invalid状态并将样式应用于该状态中的元素。

虽然这不会将disabled状态应用于提交按钮,但如果验证失败,则不会提交表单。

input,
textarea {
  margin: 5px 0;
  padding: 5px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

input:invalid,
select:invalid,
textarea:invalid {
  border-color: red;
}
<form action="" method="POST">
  <input type="date" name="date" placeholder="Registration Date" required />
  <br/>
  <input name="full_names" type="text" placeholder="Full names" required />
  <br/>
  <input name="mobile" type="tel" pattern='[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}' placeholder="Mobile" title="+99(99)9999-9999" />
  <!-- Pattern from: http://www.htmlgoodies.com/html5/tutorials/whats-new-in-html5-forms-email-url-and-telephone-input-types.html#fbid=UQp7PiVwsX2 -->
  <br/>
  <span>Select status </span>
  <select name="status" required>
    <option value="Paid">Paid</option>
    <option value="Unpaid">Unpaid</option>
  </select>
  <br/>

  <span>Select Chapter </span>
  <select name="chapter" required>
    <option value="Known">Known</option>
    <option value="Unknown">Unknown</option>
  </select>
  <br/>

  <span>Select Gender </span>
  <select name="gender" required>
    <option value="Male">Male</option>
    <option value="Female">Female</option>
  </select>
  <br/>

  <input type="email" name="email" placeholder="Email Address" />
  <br/>

  <textarea type="text" placeholder="Any Remarks" rows="2" name="remarks" required></textarea>
  <br/>

  <button type="submit">Submit</button>

</form>


HTML5 has a lot of this built in, with required attributes and the ability to provide a regex pattern attribute to validate against. Some is even built in, like when you use type="email" attribute instead of type="text".

Using HTML5 validation + CSS3, you can pick up on the :invalid state and apply styles to the elements in that state.

Although this does not apply the disabled state to the submit button, it does not submit the form if validation fails.

input,
textarea {
  margin: 5px 0;
  padding: 5px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

input:invalid,
select:invalid,
textarea:invalid {
  border-color: red;
}
<form action="" method="POST">
  <input type="date" name="date" placeholder="Registration Date" required />
  <br/>
  <input name="full_names" type="text" placeholder="Full names" required />
  <br/>
  <input name="mobile" type="tel" pattern='[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}' placeholder="Mobile" title="+99(99)9999-9999" />
  <!-- Pattern from: http://www.htmlgoodies.com/html5/tutorials/whats-new-in-html5-forms-email-url-and-telephone-input-types.html#fbid=UQp7PiVwsX2 -->
  <br/>
  <span>Select status </span>
  <select name="status" required>
    <option value="Paid">Paid</option>
    <option value="Unpaid">Unpaid</option>
  </select>
  <br/>

  <span>Select Chapter </span>
  <select name="chapter" required>
    <option value="Known">Known</option>
    <option value="Unknown">Unknown</option>
  </select>
  <br/>

  <span>Select Gender </span>
  <select name="gender" required>
    <option value="Male">Male</option>
    <option value="Female">Female</option>
  </select>
  <br/>

  <input type="email" name="email" placeholder="Email Address" />
  <br/>

  <textarea type="text" placeholder="Any Remarks" rows="2" name="remarks" required></textarea>
  <br/>

  <button type="submit">Submit</button>

</form>

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。