Swagger-ui: Feature request: Syntax Highlighting

Created on 6 Jun 2017  路  5Comments  路  Source: swagger-api/swagger-ui

Swagger 2 had a nice syntax highlighting for json/xml samples.

I might be missing something, but I don't see it in the "Known Issues" section of the README.md, is this planned or is there a way to enable it on swagger-ui 3?

Good first issue Needs community contribution P2 feature 3.x

Most helpful comment

swagger-ui currently uses microlight and has a component named HighlightCode . I tried to modify it with highlight.js and am going through several problems currently:

  • highlight.js requires type of language, which is not known yet in this component
  • some styles are marked important and have to be
  • need to find a way to "alter" component and styles as a plugin
  • and a method to avoid dangerouslySetInnerHTML (maybe in a react way using react-lowlight )

visual effect:

image

All 5 comments

Thanks for bringing it up. As we're focused on OAS3 support, this will not be high on the priority list for now. That said, contributions are always welcome.

npm has some nice react components that handle syntax highlighting: https://www.npmjs.com/search?q=react+syntax+highlighting

a community PR that adds this functionality would be wonderful, and not difficult to implement!

swagger-ui currently uses microlight and has a component named HighlightCode . I tried to modify it with highlight.js and am going through several problems currently:

  • highlight.js requires type of language, which is not known yet in this component
  • some styles are marked important and have to be
  • need to find a way to "alter" component and styles as a plugin
  • and a method to avoid dangerouslySetInnerHTML (maybe in a react way using react-lowlight )

visual effect:

image

馃帀 Implemented in Swagger UI 3.30.0 (PR https://github.com/swagger-api/swagger-ui/pull/6236).

See also the relevant configuration parameters:
https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#user-content-syntaxhighlight

This works beautifully, thanks to everyone who worked on it. Responses are much more readable now.

Don't mean to be noisy, just wanted to leave some confirmation in the thread for other users searching around. I just upgraded swagger-ui-bundle.js/swagger-ui.css and voila:

image

The defaults look great.

Was this page helpful?
0 / 5 - 0 ratings