-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: menu items from tags + md extension for Schema Definition (#681)
* add section menus for tags and object description * bundle and test * add depth calculation * add object descriptions to test * enable operations spacing for operations as well * bring back section rule, as this could be solved better * update read/writeonly filter rule to be able to filter both * add showReadOnly and showWriteOnly options to object-description * update demo to show use cases * remove forgotten console.log * adjust demo test with newly added items * do the right match with the menu items :/ * chore: refactor + jsxify md tags * chore: simplify demo spec * fix: dropdown fixes related to object description
- Loading branch information
Showing
11 changed files
with
183 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import * as React from 'react'; | ||
|
||
import { DarkRightPanel, MiddlePanel, MimeLabel, Row, Section } from '../../common-elements'; | ||
import { MediaTypeModel, OpenAPIParser, RedocNormalizedOptions } from '../../services'; | ||
import styled from '../../styled-components'; | ||
import { OpenAPIMediaType } from '../../types'; | ||
import { DropdownOrLabel } from '../DropdownOrLabel/DropdownOrLabel'; | ||
import { MediaTypeSamples } from '../PayloadSamples/MediaTypeSamples'; | ||
import { InvertedSimpleDropdown } from '../PayloadSamples/styled.elements'; | ||
import { Schema } from '../Schema'; | ||
|
||
export interface ObjectDescriptionProps { | ||
schemaRef: string; | ||
exampleRef?: string; | ||
showReadOnly?: boolean; | ||
showWriteOnly?: boolean; | ||
parser: OpenAPIParser; | ||
options: RedocNormalizedOptions; | ||
} | ||
|
||
export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps> { | ||
private static getMediaType(schemaRef: string, exampleRef?: string): OpenAPIMediaType { | ||
if (!schemaRef) { | ||
return {}; | ||
} | ||
|
||
const info: OpenAPIMediaType = { | ||
schema: { $ref: schemaRef }, | ||
}; | ||
|
||
if (exampleRef) { | ||
info.examples = { example: { $ref: exampleRef } }; | ||
} | ||
|
||
return info; | ||
} | ||
|
||
private _mediaModel: MediaTypeModel; | ||
|
||
private get mediaModel() { | ||
const { parser, schemaRef, exampleRef, options } = this.props; | ||
if (!this._mediaModel) { | ||
this._mediaModel = new MediaTypeModel( | ||
parser, | ||
'json', | ||
false, | ||
SchemaDefinition.getMediaType(schemaRef, exampleRef), | ||
options, | ||
); | ||
} | ||
|
||
return this._mediaModel; | ||
} | ||
|
||
render() { | ||
const { showReadOnly = true, showWriteOnly = false } = this.props; | ||
return ( | ||
<Section> | ||
<Row> | ||
<MiddlePanel> | ||
<Schema | ||
skipWriteOnly={!showWriteOnly} | ||
skipReadOnly={!showReadOnly} | ||
schema={this.mediaModel.schema} | ||
/> | ||
</MiddlePanel> | ||
<DarkRightPanel> | ||
<MediaSamplesWrap> | ||
<MediaTypeSamples renderDropdown={this.renderDropdown} mediaType={this.mediaModel} /> | ||
</MediaSamplesWrap> | ||
</DarkRightPanel> | ||
</Row> | ||
</Section> | ||
); | ||
} | ||
|
||
private renderDropdown = props => { | ||
return <DropdownOrLabel Label={MimeLabel} Dropdown={InvertedSimpleDropdown} {...props} />; | ||
}; | ||
} | ||
|
||
const MediaSamplesWrap = styled.div` | ||
background: ${({ theme }) => theme.codeSample.backgroundColor}; | ||
& > div, | ||
& > pre { | ||
padding: ${props => props.theme.spacing.unit * 4}px; | ||
margin: 0; | ||
} | ||
& > div > pre { | ||
padding: 0; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters