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.xqy
中get-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
theget-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
最满意答案
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 regexpattern
attribute to validate against. Some is even built in, like when you usetype="email"
attribute instead oftype="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>
相关问答
更多-
谢谢@karthikr: from django import forms class ContactForm(forms.Form): # Everything as before. ... def clean(self): cleaned_data = super(ContactForm, self).clean() cc_myself = cleaned_data.get("cc_myself") subject = clea ...
-
这是我在没有做任何肮脏工作的情况下能够做到的最多。 https://jsfiddle.net/mankinchi/uupytLh2/ pattern="\d{4}" if ((number < 1900) || (number > 2016)) 这使用具有模式的组合来检查(仅在提交时为4位)和javascript(我使用jquery)来检查数字范围。 该组合将允许您不要处理低级别的模式(限制要输入的确切数字)。 但是,如果您仍想限制用户输入,而不是之后检查,您仍然可以使用oninput并手动限制下一个可 ...
-
这是我解决它的方式。 如果有人有更好的解决方案,请告诉我们。 private boolean isParsable = false; public void validateTextFieldLong2 (TextField textField, PseudoClass errorClass){ textField.focusedProperty().addListener((arg0, oldValue, newValue) -> { try {Long.parse ...
-
如何在document.forms[0].submit = validateFunction;添加事件处理程序,如document.forms[0].submit = validateFunction; 其中validateFunction可能如下所示: function validateFunction() { var allIns = this.getElementsByTagName('input'); if(allIns.namedItem('putime').value == '' ...
-
当值为空且颜色为样式时,所需的输入字段会获得边框(Required input field gets border when value is empty and color is styled)[2023-02-17]
required的HTML5属性显然被firefox解释为包含红色边框,下面是关于删除它的答案 Firefox 4需要输入形式红色边框/轮廓 所以只需要: [required] { color:red; box-shadow: none; } 固定 The HTML5 attribute required is obviously being interpreted by firefox to include a red border, here's an answer about rem ... -
empty()函数(PHP手册) 如果var存在且具有非空的非零值,则返回FALSE。 否则返回TRUE。 以下内容被认为是空的: "" (an empty string) 0 (0 as an integer) 0.0 (0 as a float) "0" (0 as a string) NULL FALSE array() (an empty array) $var; (a variable declared, but without a value) 在您的情况下,使用: if (!strlen($ ...
-
目前还不清楚你想要实现什么(为什么在显然它有效时验证字段),但为什么不简单$('input[name="phone_prefix"]').parsley().validate() ? It's not clear what you are trying to achieve (why validate the field when it's clear it will be valid), but why not simple $('input[name="phone_prefix"]').parsley( ...
-
HTML5内置了很多内容,具有required属性和提供正则表达式pattern属性以进行验证的能力。 有些甚至是内置的,比如当你使用type="email"属性而不是type="text" 。 使用HTML5验证+ CSS3,您可以选择:invalid状态并将样式应用于该状态中的元素。 虽然这不会将disabled状态应用于提交按钮,但如果验证失败,则不会提交表单。 input, textarea { margin: 5px 0; padding: 5px 10px; border: ...
-
使用JQUERY验证表单字段(Validate Form Field using JQUERY)[2023-07-23]
您可能正在寻找的事件是blur()事件,该事件在用户离开输入字段时被调用(例如,通过按Tab键或单击下一个输入) 例: $(document).ready(function(){ $('input#myInput').blur(function(){ myValidator($(this), $(this).val()); }); }); function myValidator($element, value) { ... -
如何将红色边框与必需属性一起添加到输入字段?(How can I add a red border to an input field along with the required attribute?)[2022-07-04]
你可以像这样实现它: $("form").submit(function(e) { e.preventDefault(); // .... }); $("form input").on("invalid", function(event) { $('#title').addClass('error'); setTimeout(function() { $('#title').removeClass('error'); }, 500); }); .error ...