Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External Documentation rendered for groups, operations and schemata. #595

Merged
merged 7 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/components/ApiInfo/ApiInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react';
import { AppStore } from '../../services/AppStore';

import { MiddlePanel, Row, Section } from '../../common-elements/';
import { ExternalDocumentation } from '../ExternalDocumentation/ExternalDocumentation';
import { Markdown } from '../Markdown/Markdown';
import { StyledMarkdownBlock } from '../Markdown/styled.elements';
import {
Expand Down Expand Up @@ -98,15 +99,13 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
</InfoSpanBoxWrap>
)) ||
null}

{(externalDocs && (
<p>
<a href={externalDocs.url}>{externalDocs.description || externalDocs.url}</a>
</p>
)) ||
null}
</StyledMarkdownBlock>
<Markdown source={store.spec.info.description} />
{externalDocs && (
<p>
<ExternalDocumentation externalDocs={externalDocs} />
</p>
)}
</MiddlePanel>
</Row>
</Section>
Expand Down
12 changes: 11 additions & 1 deletion src/components/ContentItems/ContentItems.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { observer } from 'mobx-react';
import * as React from 'react';

import { ExternalDocumentation } from '../ExternalDocumentation/ExternalDocumentation';
import { AdvancedMarkdown } from '../Markdown/AdvancedMarkdown';

import { H1, H2, MiddlePanel, Row, Section, ShareLink } from '../../common-elements';
Expand Down Expand Up @@ -64,7 +65,7 @@ const middlePanelWrap = component => <MiddlePanel>{component}</MiddlePanel>;
@observer
export class SectionItem extends React.Component<ContentItemProps> {
render() {
const { name, description, level } = this.props.item as GroupModel;
const { name, description, externalDocs, level } = this.props.item as GroupModel;

const Header = level === 2 ? H2 : H1;
return (
Expand All @@ -78,6 +79,15 @@ export class SectionItem extends React.Component<ContentItemProps> {
</MiddlePanel>
</Row>
<AdvancedMarkdown source={description || ''} htmlWrap={middlePanelWrap} />
{externalDocs && (
<Row>
<MiddlePanel>
<p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a <p> here?

Copy link
Contributor Author

@m-mohr m-mohr Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's on purpose. The p adds a margin between the External Documentation link and the description. Without the margin in looks odd. The div is chosen in the schema as it seems to be designed to be very small and therefore without margin, like most other elements in there, too. So I think your suggestion makes things look worse without introducing additional styling per place that it's added to.

<ExternalDocumentation externalDocs={externalDocs} />
</p>
</MiddlePanel>
</Row>
)}
</>
);
}
Expand Down
27 changes: 27 additions & 0 deletions src/components/ExternalDocumentation/ExternalDocumentation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { observer } from 'mobx-react';
import * as React from 'react';
import styled from '../../styled-components';
import { OpenAPIExternalDocumentation } from '../../types';
import { linksCss } from '../Markdown/styled.elements';

const Link = styled.span`
${linksCss};
`;

@observer
export class ExternalDocumentation extends React.Component<{
externalDocs: OpenAPIExternalDocumentation;
}> {
render() {
const { externalDocs } = this.props;
if (!externalDocs || !externalDocs.url) {
return null;
}

return (
<Link>
<a href={externalDocs.url}>{externalDocs.description || externalDocs.url}</a>
</Link>
);
}
}
6 changes: 6 additions & 0 deletions src/components/Fields/FieldDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TypePrefix,
TypeTitle,
} from '../../common-elements/fields';
import { ExternalDocumentation } from '../ExternalDocumentation/ExternalDocumentation';
import { Markdown } from '../Markdown/Markdown';
import { EnumValues } from './EnumValues';
import { FieldProps } from './Field';
Expand Down Expand Up @@ -53,6 +54,11 @@ export class FieldDetails extends React.PureComponent<FieldProps> {
<div>
<Markdown dense={true} source={description} />
</div>
{schema.externalDocs && (
<div>
<ExternalDocumentation externalDocs={schema.externalDocs} />
</div>
)}
{(renderDiscriminatorSwitch && renderDiscriminatorSwitch(this.props)) || null}
</div>
);
Expand Down
8 changes: 7 additions & 1 deletion src/components/Operation/Operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OptionsContext } from '../OptionsProvider';

import { ShareLink } from '../../common-elements/linkify';
import { Endpoint } from '../Endpoint/Endpoint';
import { ExternalDocumentation } from '../ExternalDocumentation/ExternalDocumentation';
import { Markdown } from '../Markdown/Markdown';
import { Parameters } from '../Parameters/Parameters';
import { RequestSamples } from '../RequestSamples/RequestSamples';
Expand Down Expand Up @@ -38,7 +39,7 @@ export class Operation extends React.Component<OperationProps> {
render() {
const { operation } = this.props;

const { name: summary, description, deprecated } = operation;
const { name: summary, description, deprecated, externalDocs } = operation;
return (
<OptionsContext.Consumer>
{options => (
Expand All @@ -50,6 +51,11 @@ export class Operation extends React.Component<OperationProps> {
</H2>
{options.pathInMiddlePanel && <Endpoint operation={operation} inverted={true} />}
{description !== undefined && <Description source={description} />}
{externalDocs && (
<p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

<ExternalDocumentation externalDocs={externalDocs} />
</p>
)}
<SecurityRequirements securities={operation.security} />
<Parameters parameters={operation.parameters} body={operation.requestBody} />
<ResponsesList responses={operation.responses} />
Expand Down
1 change: 1 addition & 0 deletions src/components/Schema/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
name: '',
required: false,
description: schema.description,
externalDocs: schema.externalDocs,
deprecated: false,
toggle: () => null,
expanded: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat
"displayType": "number",
"enum": Array [],
"example": undefined,
"externalDocs": undefined,
"format": undefined,
"isCircular": undefined,
"isPrimitive": true,
Expand Down Expand Up @@ -72,6 +73,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat
"displayType": "string",
"enum": Array [],
"example": undefined,
"externalDocs": undefined,
"format": undefined,
"isCircular": undefined,
"isPrimitive": true,
Expand Down
4 changes: 3 additions & 1 deletion src/services/models/Schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { action, observable } from 'mobx';

import { OpenAPISchema, Referenced } from '../../types';
import { OpenAPIExternalDocumentation, OpenAPISchema, Referenced } from '../../types';

import { OpenAPIParser } from '../OpenAPIParser';
import { RedocNormalizedOptions } from '../RedocNormalizedOptions';
Expand All @@ -25,6 +25,7 @@ export class SchemaModel {
typePrefix: string = '';
title: string;
description: string;
externalDocs?: OpenAPIExternalDocumentation;

isPrimitive: boolean;
isCircular: boolean = false;
Expand Down Expand Up @@ -101,6 +102,7 @@ export class SchemaModel {
this.example = schema.example;
this.deprecated = !!schema.deprecated;
this.pattern = schema.pattern;
this.externalDocs = schema.externalDocs;

this.constraints = humanizeConstraints(schema);
this.displayType = this.type;
Expand Down
2 changes: 1 addition & 1 deletion src/types/open-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export interface OpenAPITag {

export interface OpenAPIExternalDocumentation {
description?: string;
url?: string;
url: string;
}

export interface OpenAPIContact {
Expand Down