import React, { PureComponent } from "react" import PropTypes from "prop-types" import { getList } from "core/utils" import { getExtensions, sanitizeUrl, escapeDeepLinkPath } from "core/utils" import { safeBuildUrl } from "core/utils/url" import { Iterable, List } from "immutable" import ImPropTypes from "react-immutable-proptypes" import RollingLoadSVG from "core/assets/rolling-load.svg" export default class Operation extends PureComponent { static propTypes = { specPath: ImPropTypes.list.isRequired, operation: PropTypes.instanceOf(Iterable).isRequired, summary: PropTypes.string, response: PropTypes.instanceOf(Iterable), request: PropTypes.instanceOf(Iterable), toggleShown: PropTypes.func.isRequired, onTryoutClick: PropTypes.func.isRequired, onResetClick: PropTypes.func.isRequired, onCancelClick: PropTypes.func.isRequired, onExecute: PropTypes.func.isRequired, getComponent: PropTypes.func.isRequired, getConfigs: PropTypes.func.isRequired, authActions: PropTypes.object, authSelectors: PropTypes.object, specActions: PropTypes.object.isRequired, specSelectors: PropTypes.object.isRequired, oas3Actions: PropTypes.object.isRequired, oas3Selectors: PropTypes.object.isRequired, layoutActions: PropTypes.object.isRequired, layoutSelectors: PropTypes.object.isRequired, fn: PropTypes.object.isRequired } static defaultProps = { operation: null, response: null, request: null, specPath: List(), summary: "" } render() { let { specPath, response, request, toggleShown, onTryoutClick, onResetClick, onCancelClick, onExecute, fn, getComponent, getConfigs, specActions, specSelectors, authActions, authSelectors, oas3Actions, oas3Selectors } = this.props let operationProps = this.props.operation let { deprecated, isShown, path, method, op, tag, operationId, allowTryItOut, displayRequestDuration, tryItOutEnabled, executeInProgress } = operationProps.toJS() let { description, externalDocs, schemes } = op const externalDocsUrl = externalDocs ? safeBuildUrl(externalDocs.url, specSelectors.url(), { selectedServer: oas3Selectors.selectedServer() }) : "" let operation = operationProps.getIn(["op"]) let responses = operation.get("responses") let parameters = getList(operation, ["parameters"]) let operationScheme = specSelectors.operationScheme(path, method) let isShownKey = ["operations", tag, operationId] let extensions = getExtensions(operation) const Responses = getComponent("responses") const Parameters = getComponent( "parameters" ) const Execute = getComponent( "execute" ) const Clear = getComponent( "clear" ) const Collapse = getComponent( "Collapse" ) const Markdown = getComponent("Markdown", true) const Schemes = getComponent( "schemes" ) const OperationServers = getComponent( "OperationServers" ) const OperationExt = getComponent( "OperationExt" ) const OperationSummary = getComponent( "OperationSummary" ) const Link = getComponent( "Link" ) const { showExtensions } = getConfigs() // Merge in Live Response if(responses && response && response.size > 0) { let notDocumented = !responses.get(String(response.get("status"))) && !responses.get("default") response = response.set("notDocumented", notDocumented) } let onChangeKey = [ path, method ] // Used to add values to _this_ operation ( indexed by path and method ) const validationErrors = specSelectors.validationErrors([path, method]) return (
{ (operation && operation.size) || operation === null ? null : } { deprecated &&

Warning: Deprecated

} { description &&
} { externalDocsUrl ?

Find more details

{externalDocs.description && } {externalDocsUrl}
: null } { !operation || !operation.size ? null : } { !tryItOutEnabled ? null : } {!tryItOutEnabled || !allowTryItOut ? null : schemes && schemes.size ?
: null } { !tryItOutEnabled || !allowTryItOut || validationErrors.length <= 0 ? null :
Please correct the following validation errors and try again.
    { validationErrors.map((error, index) =>
  • { error }
  • ) }
}
{ !tryItOutEnabled || !allowTryItOut ? null : } { (!tryItOutEnabled || !response || !allowTryItOut) ? null : }
{executeInProgress ?
: null} { !responses ? null : } { !showExtensions || !extensions.size ? null : }
) } }