Require form-urlencoded request body with swagger-core - swagger

Using Dropwizard with swagger-core and swagger-jaxrs2 2.2.6, how can you mark the requestBody of a x-www-form-urlencoded request as required?
#POST
#Path("/do-something")
#Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
#Operation(summary = "Does something")
public void doSomething(#NotNull #FormParam("what") String what) {
// ...
}
This generates the following:
"/do-something" : {
"post" : {
"summary" : "Does something",
"operationId" : "doSomething",
"requestBody" : {
/* missing here: "required": true */
"content" : {
"application/x-www-form-urlencoded" : {
"schema" : {
"required" : [ "what" ],
"type" : "object",
"properties" : {
"what" : {
"type" : "string"
}
}
}
}
}
},
"responses" : { /* ... */ }
}
},
Parameter what is required, however the requestBody as a whole is not marked as required. Generated TypeScript clients therefore allow to omit it.
I could annotate the operation with something like #RequestBody(required = true), but this disables the auto detection of the parameters.
Do you have any idea how to solve this without rewriting half the documentation manually?

Related

How to read an aggregated entity from Odata Service SAP ui5

In OData Model V2, I'm struggling by reading the odata of my mocked server:
I want to get access to the child entity which is associated with a Parent entity.
From Open_Station I can navigate to_Order_Header:
[{
"results": [
{
"__metadata": {
"id": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"type": "cds_zui_check_dialog.Open_StationType"
},
"Station": "CHE1",
"Task": "5246",
"to_Order_Header": {
"__deferred": {
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"
}
}
}
]
}
]
And from to_Order_Header, I can navigate to Order_Item or Stock:
[{
"__metadata" : {
"id" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"type" : "cds_zui_check_dialog.Order_HeaderType"
},
"OrderNumber" : "00000000100000000853",
"Station" : "CHE1",
"OrderIndicator" : "",
"to_Order_Items" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Order_Items"
}
},
"to_Stock" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Stock"
}
}
]
In my controller, I have a metho ReadOdata read data like this:
ReadOdata: function()
{
var oModel = new sap.ui.model.odata.v2.ODataModel("http://WebService");
return new Promise(function(resolve, reject)
{
oModel.read("Open_Station(Station='CHE1',Task='5246')/to_Order_Header", {
success : function (data) {
resolve(data);
},
error: function (oError) {
reject(oError);
}
});
});
},
I always get a failure like this:
Request failed with status code 404: GET Open_Station(Station='CHE1',Task='5246')/to_Order_Header
- [{"code":404,"message":"Resource not found","persistent":false,"targets":["/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"],"type":"Error"}]
sap.ui.model.odata.ODataMessageParser
I think the way I want to read the associated entity is wrong. Please help me.
I found a solution. It was a failure in the annotation of the Path:
Instead of writing:
oModel.read("**to_Open_Station**(Station='CHE1',Task='5246')/to_Order_Header", {
I was writing:
oModel.read("*Open_Station*(Station='CHE1',Task='5246')/to_Order_Header", {
In the MetaData, the NavigationProperty was called to_Open_Station.

How to query specific branch build number from Jenkins JSON Remote Access API

Within the browser for my jenkins job I'm running the following query.
lastStableBuild/api/json?pretty=true&tree=actions[buildsByBranchName[*[*]]]
Results from the above query
{
"_class" : "hudson.model.FreeStyleBuild",
"actions" : [
{
"_class" : "hudson.model.CauseAction"
},
{
},
{
"_class" : "jenkins.metrics.impl.TimeInQueueAction"
},
{
},
{
"_class" : "hudson.plugins.git.util.BuildData",
"buildsByBranchName" : {
"my-branch-name" : {
"_class" : "hudson.plugins.git.util.Build",
"buildNumber" : 587,
"buildResult" : null,
"marked" : {
"SHA1" : "***",
"branch" : [
{
}
]
},
"revision" : {
"SHA1" : "***",
"branch" : [
{
}
]
}
},
"my-other-branch-name" : {
"_class" : "hudson.plugins.git.util.Build",
"buildNumber" : 1373,
"buildResult" : null,
"marked" : {
"SHA1" : "***",
"branch" : [
{
}
]
},
"revision" : {
"SHA1" : "***",
"branch" : [
{
}
]
}
},
I would like to be able to narrow it down to just the build number like you would get with
/lastSuccessBuild/buildNumber
using the api but I would settle for just everything inside of the branch name key so that I wouldn't have to loop through all branches and compare the name. I'm assuming I can narrow it down more where I have my "*" specified but can't figure out the right syntax to use.
I got that info from here instead.
tree=actions[lastBuiltRevision[*,branch[*]]]
Either way, if you want the branch info, from inside the buildsByBranchName section of the tree, you will have to query it as I did above.
If you don't mind getting your answer back in xml, xpath works very well.
For the url:
/lastStableBuild/api/xml?xpath=//buildsByBranchName&wrapper=meep
Creates an xml that looks like:
<meep>
<buildsByBranchName>
...
</buildsByBranchName>
</meep>
And will be populated with the buildsByBranchName (NOTE: there may be more than one if there are multiple git remotes, hence the need for a wrapper) for the specified last successful build of the job specified in the url. You can substitute anything for the word "meep", that will become the wrapper object for the newly created xml object.

modeshape binarycontent search

I am trying modeshape 4, want binary content search, I am able to search nodes other than node containing binary content. Need help with search binary content. Are there any examples?
Code to create node
static void addFile(byte[] filebytes, String filename) throws Exception{
Session session=openSession();
Node root = session.getRootNode();
if(!root.hasNode("files")){
Node n = root.addNode("files");
}
Node files=root.getNode("files");
Node newFileNode=files.addNode(String.valueOf(helper.rnd.nextInt()));
newFileNode.setProperty("fileName", filename);
newFileNode.setProperty("owner", "test");
newFileNode.setProperty("binaryContent", session.getValueFactory().createBinary(new ByteArrayInputStream(filebytes)));
session.save();
closeSession(session);
}
Search code
static void search()throws Exception{
javax.jcr.query.QueryManager queryManager = openSession().getWorkspace().getQueryManager();
javax.jcr.query.Query query = queryManager.createQuery("select * from [nt:base] as s where contains(s.binaryContent,'Finan') ",Query.JCR_SQL2);
javax.jcr.query.QueryResult result = query.execute();
javax.jcr.NodeIterator nodeIter = result.getNodes();
while ( nodeIter.hasNext() ) {
javax.jcr.Node node = nodeIter.nextNode();
System.out.println(node.getProperty("fileName")+" "+node.getProperty("owner"));
}
}
modeshape configuration
{
"name" : "Persisted-Repository",
"workspaces" : {
"predefined" : ["otherWorkspace"],
"default" : "default",
"allowCreation" : true
},
"security" : {
"anonymous" : {
"roles" : ["readonly","readwrite","admin"],
"useOnFailedLogin" : false
}
},
"storage" : {
"cacheConfiguration" : "infinispan-configuration-async-eviction.xml",
"cacheName" : "persisted_repository",
"binaryStorage" : {
"type" : "database",
"driverClass" : "oracle.jdbc.driver.OracleDriver",
"url" : "jdbc:oracle:thin:#xxx.xx.xx.xx:1521:sid",
"username" : "user",
"password" : "password"
}
},
"indexProviders": {
"lucene": {
"classname": "lucene",
"directory": "target/indexes"
}
},
"indexes": {
"textFromFiles": {
"kind": "text",
"provider": "lucene",
"nodeType": "nt:resource",
"columns": "jcr:data(BINARY)"
}
},
"textExtraction": {
"extractors" : {
"tikaExtractor":{
"name" : "Tika content-based extractor",
"classname" : "tika"
}
}
}
}
node structure
+---> -1731357696 /files/-1731357696
owner test
filename attachment-a.docx
binaryContent binary (14.39KB, SHA1=3941f73eab403accc1779af293afadd0c03e0c15)

Escaping # at symbol in Ruby Elastic Search gem?

I have the following code in the custom ES 'where' wrapper method
filter: { term: params }
Then we have a sample ES document that contains:
"emails" => { "email" => "johndoe#email.com" }
It is returned when my search is:
query.where("emails.email" => "johndoe")
but I get no results when:
query.where("emails.email" => "johndoe#email.com")
It seems like I have to escape at symbol somehow when using ES gem?
It's probably because your field is analyzed using the default standard analyzer and is thus tokenized at the # sign.
You can see what ES has indexed by running the command below:
curl -XGET 'localhost:9200/_analyze?analyzer=standard&pretty' -d 'johndoe#email.com'
And the result is
{
"tokens" : [ {
"token" : "johndoe",
"start_offset" : 0,
"end_offset" : 7,
"type" : "<ALPHANUM>",
"position" : 1
}, {
"token" : "email.com",
"start_offset" : 8,
"end_offset" : 17,
"type" : "<ALPHANUM>",
"position" : 2
} ]
}
As you can see, your email field has been tokenized as two different tokens and that's probably why searching for johndoe works, while searching for the full email address doesn't.
There are a few ways out from here, but one way that would work is to create your own analyzer based on a pattern_capture token filter and use it as index_analyzer for your emails.email field.
{
"settings" : {
"analysis" : {
"filter" : {
"email" : {
"type" : "pattern_capture",
"preserve_original" : 1,
"patterns" : [ "([^#]+)", "(\\p{L}+)", "(\\d+)", "#(.+)" ]
}
},
"analyzer" : {
"email" : {
"tokenizer" : "uax_url_email",
"filter" : [ "email", "lowercase", "unique" ]
}
}
}
},
"mappings": {
"emails": {
"properties": {
"email": {
"type": "string",
"analyzer": "email" <-- use the analyzer here
}
}
}
}
}
At indexing time, that analyzer will produce all of the following tokens, which will allow you to search for any parts of your email address:
johndoe#email.com
johndoe
email.com
email
com

How to set "search_type" to "count" in elasticsearch-rails?

Here's the query I'd like to get working with elasticsearch-rails. (The query works in Sense). My goal is to return all the buckets for items that have a person whose name begins with the letter B. My first stumbling block is that I can't figure out how to specify that the search_type should be set to count.
GET _search?search_type=count
{
"query": {
"prefix": {
"person": "B"
}
},
"aggs" : {
"facets" : {
"terms" : {
"field" : "person",
"size" : 0,
"order" : { "_term" : "asc" }
}
}
}
}
According to this issue, this doesn't seem supported yet.
An alternative that works is simply setting size: 0 in your query, like this:
{
"size": 0, <--- add this
"query": {
"prefix": {
"person": "B"
}
},
"aggs" : {
"facets" : {
"terms" : {
"field" : "person",
"size" : 0,
"order" : { "_term" : "asc" }
}
}
}
}
It is worth noting, though, that search_type=count is going to be deprecated is now deprecated in ES 2.0 and the recommendation will be to simply set size: 0 in your query as mentioned above. Doing so would make you ES 2.0-compliant... at least for that query, that is :)

Resources