Displaying line breaks in the response text - swagger

I use Swagger UI v2.2.0. I have a RESTful method which returns plain text. I want to display this text with line breaks.
At the moment, the returned text contains new line characters, but they are displayed as \n. The Content-Type response header is text/plain.
I can return the text with something else inserted of new line characters (e.g., <br> tags). I also can change the Content-Type. I just need actual line breaks in the displayed text.
Is there a way to achieve this?

Not sure if it helps, but I also faced the same issue.
I wanted to execute the following code in nodejs server:
app.post('/xyz', function (req, res) {
res.status(400).send("MyError\nMyErrorStack:\nStackLine1\nStackline2")
}
and wanted output like:
"MyError
MyErrorStack:
StackLine1
Stackline2"
but got :
"MyError\nMyErrorStack:\nStackLine1\nStackline2"
so instead i split the string into array as shown used following:
err.error = errObj.stack.split("\n")
app.post('/xyz', function (req, res) {
res.status(400).send(err)
}
and this printed
"Error": {
"error": [
"Error: ENOENT: no such file or directory, open 'c:\\....'",
" at Error (native)",
" at Object.fs.openSync (fs.js:584:18)",
" at Object.fs.writeFileSync (fs.js:1224:33)",
" at Object.fs.appendFileSync (fs.js:1283:6)",
" at ...",
" at ...",
" at ...",
" at ...",
" at ...",
" at ..."
]
}
This worked for me.

This is currently not possible due to a documented bug in Swagger UI. Reference:
Inconsistent Markdown Newlines #2981
Bug in Model (Definition) Description with newline characters #3078
The second Issue listed, #3078 contains some discussion on overriding the styles used to render that part of the UI, but results appear inconsistent.
Note: I have subscribed to those issues and will update the answer and/or flag to close as no longer relevant when it is resolved.

Related

Remove all indents and spaces from JSON string except inside its value in Ruby

My problematic string is like this:
'{\n"test":"AAAA",\n"test2":"BBB\n\n\nBBB"\n}'
I want to parse it as JSON object(Hash) by JSON.parse(jsonstring)
The expecting result is:
{ "test": "AAAA", "test2": "BBB\nB"}
However, I get the error:
JSON::ParserError: 809
I happend to know that indentaion code in jsonstring be escaped,
so I tried this:
escaped_jsonstring = '{\n"test":"AAAA",\n"test2":"BBB\n\n\nBBB"\n}'.gsub(/\R/, '\\n')
JSON.parse(escaped_jsonstring)
I still have JSON::ParserError.
Indentations outside the key or value may cause this error.
How can I remove \n(or \r any indentation code) only outside the key or value in Ruby?
which means,
'{\n"test":"AAAA",\n"test2":"BBB\n\n\nBBB"\n}'
↓
'{"test":"AAAA","test2":"BBB\n\n\nBBB"}'
try this
'{\n"test":"AAAA",\n"test2":"BBB\n\n\nBBB"\n}'.gsub(/\B(\\n)+/, "")
\n" is considered inside boundary (so i use \B), meanwhile "\n is considered outside boundary (\b), (\\n)+ to fix case '...,\n\n\n"test2":...
update
turn out \s\n also be considered an inside boundary ... iam not sure there's other cases ...
for now, the updated version
'{\n"test":"AAAA",\n"test2":"BBB \n\n\n BBB"\n}'
.gsub(/([{,\"]\s*)\B(\\n)+/) { $1 }
better way
i found another way to solve your problem, also using regexp, now i will scan through the input text (valid or invalid json) then filter follow the pair pattern "<key>":"<value>" and don't care anything else outside those pairs, finally output the hash
def format(json)
matches = json.scan(/\"(?<key>[^\"]+)\":\"(?<val>[^\"]+)\",*/)
matches&.to_h
end
format('{\n "test\n parser":"AA\nAA", \n\n"test2":"BBB ? ;\n\n\n BBB" \n}')
# {"test\n parser"=>"AA\nAA", "test2"=>"BBB ? ;\n\n\n BBB"}

DOORS DXL Recreating the Main Column

I would like to create an DXL attribute in DOORS that contains the same information as the main column.
It is important to maintain the same heading font style in the attribute as in the main column as this is used for automatic creation of "Table of content" in the Word document after DOORS Publish.
I found the below dxl-script on the internet, but getCanvas does not seem to work.
All text are passed fine to my new attribute, but the heading have the same font style as normal text.
if (obj."Object Heading" "" != "")
{
font(getCanvas, level(obj), HeadingsFont)
displayRich(number(obj) " " obj."Object Heading" "")
}
if (obj."Object Text" "" != "")
{
font(getCanvas, level(obj), TextFont)
displayRich(richTextWithOle(obj."Object Text"))
}
Can anyone help?
KR
Klaus
For me, the code actually does work in a Layout-DXL column (which is not a DXL attribute).
if (obj."Object Heading" "" != "") {
DBE dbCanvas = getCanvas()
font(dbCanvas, level(obj), HeadingsFont)
displayRich(number(obj) " " obj."Object Heading" "")
}
My DOORS version is 9.6, although the methods don't seem to be that new, so DOORS version does not seem to be the issue.
If nothing else helps regarding the DXL code, I would suggest that you have a look at your target word document. There, you should be able to control anything you paste into the document via VBA code in a post-processing step. Although I didn't really get, why you are avoiding using the main column for your source content. Are you trying to show content of a linked or referenced module?
Thanks a lot for the answer. It helped me somehow.
My problem was that I was trying to enter the dxl-code in an attribute. I followed your suggestion and made an Layout-DXL Column instead and it worked almost immediately :-)
I ended up with the dxl-code as shown below.
if (obj."Object Heading" "" != "")
{
DBE dbCanvas = getCanvas()
if( dbCanvas != null )
font(dbCanvas, level(obj), HeadingsFont)
displayRich(number(obj) " " obj."Object Heading" "")
}
else
{ // insert rest of text
if ( probeAttr_(obj, "Requirement") == "Requirement" )
{ // insert requirement text from DT module
displayRich(richText(obj."DXL to DT - ID & Object Text"))
}
else
{ // insert rest of text from this module
displayRich(richTextWithOle(obj."Object Text"))
}
}
I would like to have a publish of the Test Procedure where every Test Case starts with the requirement text followed by the test steps necessary to perform the test as shown in Fig 1.
Test Procedure Publish view
The view in DOORS now looks like I want, but I get error when publishing in DOORS.
DOORS publish error
I therefore protected the line "font(dbCanvas, level(obj), HeadingsFont)", but now I get no headings in the Word document and Table of Content is empty.
Word snip
Is there a solution to this?
KR
Klaus

New line character in Information Message in SAP v730 (via message class)?

I want the Information Message to show two lines of text.
Can this be done using one message class statement. Ex.
MESSAGE i001(z56_myclass) WITH lv_cust_id.
I tried putting the string of the short text with characters \n # \r \\n etc. but nothing worked. I don't know how to use long text editor for this particular requirement. Any help would be great.
You can't control the message carriage return in MESSAGE statement.
You can try instead with the following information popup
call function 'POPUP_TO_INFORM'
exporting
titel = 'Information'
txt1 = 'Registration successful'
txt2 = 'Customer Id is 0000001234'.
You have 4 text rows at your disposal (from txt1 to txt4).

Groovy- searching and excretion xml code from log file

I have so many texts in log file but sometimes i got responses as a xml code and I have to cut this xml code and move to other files.
For example:
sThread1....dsadasdsadsadasdasdasdas.......dasdasdasdadasdasdasdadadsada
important xml code to cut and move to other file: <response><important> 1 </import...></response>
important xml code to other file: <response><important> 2 </important...></response>
sThread2....dsadasdsadsadasdasdasdas.......dasdasdasdadasdasdasdadadsada
Hindrance: xml code starting from difference numbers of sign (not always start in the same number of sign)
Please help me with finding method how to find xml code in text
Right now i tested substring() method but xml code not always start from this same sign :(
EDIT:
I found what I wanted, function which I searched was indexOf().
I needed a number of letter where String "Response is : " ending: so I used:
int positionOfXmlInLine = lineTxt.indexOf("<response")
And after this I can cut string to the end of the line :
def cuttedText = lineTxt.substring(positionOfXmlInLine);
So I have right now only a XML text/code from log file.
Next is a parsing XML value like BDKosher wrote under it.
Hoply that will help someone You guys
You might be able to leverage XmlSlurper for this, assuming your XML is valid enough. The code below will take each line of the log, wrap it in a root element, and parse it. Once parsed, it extracts and prints out the value of the <important> element's value attribute, but instead you could do whatever you need to do with the data:
def input = '''
sThread1..sdadassda..sdadasdsada....sdadasdas...
important code to cut and move to other file: **<response><important value="1"></important></response>**
important code to other file: ****<response><important value="3"></important></response>****
sThread2..dsadasd.s.da.das.d.as.das.d.as.da.sd.a.
'''
def parser = new XmlSlurper()
input.eachLine { line, lineNo ->
def output = parser.parseText("<wrapper>$line</wrapper>")
if (!output.response.isEmpty()) {
println "Line $lineNo is of importance ${output.response.important.#value.text()}"
}
}
This prints out:
Line 2 is of importance 1
Line 3 is of importance 3

OpenXML SDK: Updated text in HeaderPart not getting saved

elem is obtained by searching various document parts, both MainDocumentPart.Document and HeaderParts:
Text text = elem.GetFirstChild<Text>();
System.Console.Write("Updating content from '{0}'", text.Text);
text.Text = "blah";
System.Console.WriteLine(" to '{0}'", text.Text);
In all cases the output is exactly as expected to stdout, it looks to work perfectly. But when the file is saved, only changes to the main body text are seen... the header remains unchanged. Do I have to unlock the header or something?
Call HeaderPart.Header.Save() on the Header that contains elem.

Resources