Springfox: Description with headings - swagger

How can we get multiple headings inside description as following:
description: |
The Engine API ....
# Errors
The API uses standard HTTP status codes ...
# Versioning
Some other text
In the above example, Errors and Versioning are two headers.
Currently, I am adding description as following:
ApiInfoBuilder().description(" ... ")

You can go with markdown like that:
String description = "# The Engine API ...\n" +
"## Errors\n" +
"The API uses standard HTTP status codes ...\n" +
"## Versioning\n" +
"Some other text\n";
The \n new lines are important here.
Or simply use plain HTML:
String description = "<h2>The Engine API ....</h2>" +
"<h3>Errors</h3>" +
"<p>The API uses standard HTTP status codes ...</p>" +
"<h3>Versioning</h3>" +
"<p>Some other text</p>";
Then add the string to the API info:
ApiInfoBuilder().description(description)

Related

How to send array (a text with commas) as HTTP-param using Rest Assured (Java)

I use Rest Assured framework (Java).
I need to send integer array as http-param in get request: http://example.com:8080/myservice?data_ids=11,22,33
Integer[] ids = new Integer[] {11, 22, 33};
...
RequestSpecificationImpl request = (RequestSpecificationImpl)RestAssured.given();
request.baseUri("http://example.com");
request.port(8080);
request.basePath("/myservice");
...
String ids_as_string = Arrays.toString(ids).replaceAll("\\s|[\\[]|[]]", "");
request.params("data_ids", ids_as_string);
System.out.println("Params: " + request.getRequestParams().toString());
System.out.println("URI" + request.getURI());
What I see in the console:
Params: {data_ids=11,22,33}
URI: http://example.com:8080/myservice?data_ids=11%2C22%2C33
Why do my commas transform into '%2C'?
What needs to be done to ensure that commas are passed as they should?
Disable URL encoding, simple as that
given().urlEncodingEnabled(false);
Official documentation
Verified locally,

Performing OData V2 methods with "Edm.DateTime" as part of primary keys

I have the problem, that I want to update a table via HTTP-request. But I always get an error-message on the Edm.DateTime attributes in the table.
Error: Invalid URI-Segment '00:00',ValdTo=datetime'2019-04-03T00:00:00')'"}
Even the value is already converted to Edm.DateTime.
valdfrom_edit = encodeURI(sap.ui.model.odata.ODataUtils.formatValue(new Date(values.ValdFrom), "Edm.DateTime"));
var update = "/ZSCORDERINGSet(Mandt='010',Vkorg='" + vkorg_Edit + "',ZzscSpSas='" + suppl_edit + "',ValdFrom=" + valdfrom_edit + ",ValdTo=" + valdto_edit + ")";
Try with:
// ... After metadata loaded:
// Create the sPath:
const sPath = "/" + myV2ODataModel.createKey("ZSCORDERINGSet", {
//<key>s for ZSCORDERING as described in $metadata:
Mandt: "010",
Vkorg: vkorg_Edit,
ZzscSpSas: suppl_edit,
ValdFrom: new Date(values.ValdFrom), // no need to use ODataUtils.
ValdTo: valdto_edit
});
// Call the ODataModel API with the created sPath:
myV2ODataModel.update(sPath/*, other arguments according to the API reference ... */);
API reference: v2.ODataModel#update
About the API createKey, see How to create OData V2 entity path dynamically in UI5? It will create the entity path for you according to the OData specification and always in the right order.
Note: sap.ui.core.util.MockServer doesn't support Edm.DateTime in keys.
[...] OData features that are not supported by the mock server:
Feature
Status
Edm.DateTime keys
Unsupported

Formatting posts with the Slack api

I'm trying to create Posts with botkit using the Slack api, but I can't find any documentation on how to format a Post file in Slack.
bot.api.files.upload({
content: "# Heading",
filename: "test.md",
filetype: "post",
channels: "random"
});
Markdown formatting doesn't work for this, is there any syntax to formatting Slack Posts?
Trying with HTML the response from the created file is like this:
<document><p><document><h1>H1<\/h1><p><\/p><h2>H2<\/h2><p><\/p><h3>H3<\/h3><p><\/p><p>Text <i>italic<\/i> <b>bold<\/b> <a href="<a href=\"http:\/\/www.slack.com%22%3Elink%3C\/a%3E\">http:\/\/www.slack.com">link<\/a><\/a> <u>underline<\/u><\/p><p><\/p><p><strike>strikethrough<\/strike><\/p><p><\/p><p><code>Code Block;<\/code><\/p><\/document><\/p><\/document>
so it's escaping html tags.
Posts support markdown formatting.
E.g., try setting the following content:
# A Post Header
### Subheading
An image? ![Funny](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4jlx3aktZVFKAkaNB7fvy67BFQuaO3HedVQ6VIXeR5OLnfbOOEbrcp-G4)
[A link to google](https://www.google.com)
* A list item
* Another list item
`a code block`
You then post with filetype="post", and get the following:
I tested and slack appears to support most markdown features but not all. Make sure to test your formatting!

Activation link web api using angular.js

I have a website using angular.js and my backend is using asp.net web api. When a new user register a e-mail is send with an activation link and a token inside it like this :
localhost:51426/#/activation?userid=test&code=FCuuf27NzVvmwp2Ksd7IDt83C2XZmZ2paCrZPBLgr9qR8xCaXELvqKCsWlg4uiokb07XK5sQ+2BazHN1+2B74q14grkQY2OHDAVeWlin5GE8ugkyw+2BJFFzd3Q2YiVuMxkmkO6OFdhIyfzUQMV8NPipME+2FST1pa0OuQs90kRUNR5kTkPlGQYKflDOMQvDGV84fZIw
When the user click the link I have an angular controller that basically just take the parameter and call the good method inside the web.api like this :
return $http.post(baseUrl + 'api/v1/account/confirmAccount?userId=' + userId + '&code=' + code);
The problem it seems all the + are replace by space in the server side so when I try to validate the token in my web api it doesn't work.
Not sure to understand why the + it's replace by space and how to avoid this.
Thanks
The problem is that in query strings + characters are replaced by spaces:
URL Encoding:
The HTML specifies the following transformation:
SPACE is encoded as '+' or "%20" [9]
What you could do is replace the space characters with + on the server:
string newCode=code.Replace(' ','+')
One option might be to build the string first and eliminate the + altogether.

Getting 404 Not Found when doing a jira search for project

I am trying to learn RESTFul web services using Jersey
I have written some java code to return the json for a JIRA search for a project ID, the code is based on that created by Bernd Hort (BP206 at connect2014)
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter("username", "password");
client.addFilter(authFilter);
WebResource service = client.resource(getBaseURI());
String searchquery = "search?jql=id=" + id + "&maxResults=5000";
System.out.println("Query=" + searchquery);
String json = service.path(searchquery).accept(
MediaType.APPLICATION_JSON).get(String.class);
I have tested the search using both Postman and putting it into the browser url and it returns data.
http://myserver:8080/rest/api/2/search?jql=id=12408&maxResults=5000
when I try it in my java code I get the following error;
com.sun.jersey.api.client.UniformInterfaceException: GET http://myserver:8080/rest/api/2/search%3Fjql=id=12408&maxResults=5000 returned a response status of 404 Not Found
it seems to be changing the '?' to '%3f' which the search doesn't like
You're specifying that query as part of the path, so it's being escaped as such:
String json = service.path(searchquery).accept(
MediaType.APPLICATION_JSON).get(String.class);
You want to make it a query parameter:
String json = service.path("search")
.queryParam("jql", "id=" + id)
.queryParam("maxResults", "5000)
.accept(MediaType.APPLICATION_JSON).get(String.class);

Resources