import * as React from 'react'; import { ShelfIcon } from '../../common-elements'; import { OperationModel } from '../../services'; import { Markdown } from '../Markdown/Markdown'; import { OptionsContext } from '../OptionsProvider'; import { SelectOnClick } from '../SelectOnClick/SelectOnClick'; import { expandDefaultServerVariables, getBasePath } from '../../utils'; import { EndpointInfo, HttpVerb, OperationEndpointWrap, ServerItem, ServerRelativeURL, ServersOverlay, ServerUrl, } from './styled.elements'; export interface EndpointProps { operation: OperationModel; hideHostname?: boolean; inverted?: boolean; compact?: boolean; } export interface EndpointState { expanded: boolean; } export class Endpoint extends React.Component { constructor(props) { super(props); this.state = { expanded: false, }; } toggle = () => { this.setState({ expanded: !this.state.expanded }); }; render() { const { operation, inverted, hideHostname } = this.props; const { expanded } = this.state; // TODO: highlight server variables, e.g. https://{user}.test.com return ( {options => ( {operation.httpVerb} {operation.path} {operation.servers.map(server => { const normalizedUrl = options.expandDefaultServerVariables ? expandDefaultServerVariables(server.url, server.variables) : server.url; const basePath = getBasePath(normalizedUrl); return ( {hideHostname || options.hideHostname ? basePath === '/' ? '' : basePath : normalizedUrl} {operation.path} ); })} )} ); } }