swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.61k stars 8.96k forks source link

Support syntaxHighlight prop in swagger-ui-react #8404

Open be-a-sid opened 1 year ago

be-a-sid commented 1 year ago

Q&A (please complete the following information)

Content & configuration

Swagger-UI configuration options:

import Swagger from "swagger-ui-react"
import "swagger-ui-react/swagger-ui.css"

const RenderSwaggerUI = () =>{
   return <Swagger
      key={SWAGGER_URL}
      url={SWAGGER_URL}
      deepLinking
      syntaxHighlight={false}
    />
}

Describe the bug you're encountering

Because syntaxHighlight prop is not supported by swagger-ui-react, the agate theme is always used by default for syntax highlighting.

Expected behavior

Support syntaxHighlight prop in swagger-ui-react

Additional context or thoughts

The swagger page becomes unresponsive when syntax highlighting is enabled and the response payload is huge (swagger-ui open issues related to this #8260 #3832 ). Workaround for this is to disable the syntax highlighting by setting the syntaxHighLight prop to false.

Since swagger-ui already supports configuring this prop, I believe appending the following line to constructor block in swagger-ui-reactshould do the trick.

// Modify the https://github.com/swagger-api/swagger-ui/blob/master/flavors/swagger-ui-react/index.jsx

const ui = swaggerUIConstructor({
...,
syntaxHighlight: this.props.syntaxHighlight
})

SwaggerUI.propTypes = {
syntaxHighlight: PropTypes.oneOfType([ PropTypes.bool, PropTypes.object ]),
}
laurismurans commented 1 year ago

Is there a workaround for this while this is not implemented?

heller-tobias commented 7 months ago

Hi this is an issue for us, since it would help us with big payloads

imshashank commented 3 months ago

Any updates on this?

jounii commented 2 months ago

Since 5.17.14 the swagger-ui-react seems to export "config" property. Thus before using the you can write something like:

import SwaggerUI from 'swagger-ui-react';

SwaggerUI.config.defaults.syntaxHighlight.activated = false;

...

<SwaggerUI spec={...} />

Mind any TypeScript type issues, if you need to disable linter or any type access.