-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XML response rendering indentation algorithm problem #1918
Comments
@bodnia if you have time, this may be worth checking out |
Sorry, what I was seeing is real, but my analysis was wrong. I'm not entirely sure why the But what was really breaking the formatting in my case was that my XML was being produced by Java on windows, and all the line ends were It turns out the line typing was categorizing these lines as "closing" not "opening" and so the indentation was going negative. What I hadn't realized is that the indenting code, through some very convoluted logic, computes an indentation string whose length is the absolute value of the indent value. Hence the results I included above. So bottom line is I can work around this by removing CR chars from my output before passing it on to swagger-ui. But it would probably be helpful for swagger-ui to do this as well, to prevent others hitting this issue. |
Hi, thanks for the feedback. We want to be equal-opportunity so we'll make sure this is working with documents from windows and others as well. |
Should be fixed now. |
In a "Try It Now" scenario, if the response contains XML content, the rendering algorithm may fail to indent the content properly in its rendering, due to greedy regex matching.
Here's an example:
The content supplied by the web service is:
The rendering in swagger-ui is:
As can be seen, each line of the form
<xxx>...</xxx>
causes the next line to be indented progressively further than itself. This is due, I believe, to greedy matching in regular expressions in the rendering code.The code appears to operate something like this:
The preprocessing regular expressions are faulty, e.g. they're not splitting the tags out of the above lines because of greedy matches. For example, consider this pattern:
It is used to insert newlines after tags. However, to this pattern, a line like
<xxx>...</xxx>
looks like one big tag. If the pattern were non-greedy (/(<.+?>)(.*\n)/g
) this would not be the case. (Note that I've also changed+
to*
near the end of the pattern to fix another minor bug - there's really no requirement for another char before the newline here, is there?)Later, the line-typing algorithm will again use greedy matches and consider this line to be of type "opening" which causes the prevailing indentation to be increased by 1.
Hopefully this is enough for the right person to fix this code. I apologize that I'm not currently able to spare the time to do it myself.
The text was updated successfully, but these errors were encountered: