swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Support syntaxHighlight prop in swagger-ui-react

Open be-a-sid opened this issue 2 years ago • 4 comments

Q&A (please complete the following information)

  • OS: MacOS
  • Browser: Chrome
  • Version: 110.0.5481.100
  • Method of installation: npm i swagger-ui-react
  • Swagger-UI version: 4.15.5
  • Swagger/OpenAPI version: OpenAPI 3.0

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-react should 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 ]),
}

be-a-sid avatar Feb 23 '23 08:02 be-a-sid

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

laurismurans avatar Nov 15 '23 11:11 laurismurans

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

heller-tobias avatar Apr 11 '24 12:04 heller-tobias

Any updates on this?

imshashank avatar Jul 27 '24 05:07 imshashank

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.

jounii avatar Sep 02 '24 11:09 jounii