Skip to content

Commit

Permalink
feat: add summary and indentifier to license
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk committed May 21, 2021
1 parent 17d0566 commit 16549db
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/ApiInfo/ApiInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
const license =
(info.license && (
<InfoSpan>
License: <a href={info.license.url}>{info.license.name}</a>
License: {info.license.identifier ? info.license.identifier : (<a href={info.license.url}>{info.license.name}</a>)}
</InfoSpan>
)) ||
null;
Expand Down Expand Up @@ -100,7 +100,8 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
)) ||
null}
</StyledMarkdownBlock>
<Markdown source={store.spec.info.description} data-role="redoc-description" />
<Markdown source={store.spec.info.description} data-role="redoc-description"/>
<Markdown source={store.spec.info.summary} data-role="redoc-summary"/>
{externalDocs && <ExternalDocumentation externalDocs={externalDocs} />}
</MiddlePanel>
</Row>
Expand Down
3 changes: 3 additions & 0 deletions src/services/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ export class AppStore {

if (idx === -1 && IS_BROWSER) {
const $description = document.querySelector('[data-role="redoc-description"]');
const $summary = document.querySelector('[data-role="redoc-summary"]');

if ($description) elements.push($description);
if ($summary) elements.push($summary);
}

this.marker.addOnly(elements);
Expand Down
12 changes: 12 additions & 0 deletions src/services/__tests__/models/ApiInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,17 @@ describe('Models', () => {
const info = new ApiInfoModel(parser);
expect(info.description).toEqual('Test description\nsome text\n');
});

test('should correctly populate summary up to the first md heading', () => {
parser.spec = {
openapi: '3.1.0',
info: {
summary: 'Test summary\nsome text\n## Heading\n test',
},
} as any;

const info = new ApiInfoModel(parser);
expect(info.summary).toEqual('Test summary\nsome text\n');
});
});
});
2 changes: 2 additions & 0 deletions src/services/models/ApiInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class ApiInfoModel implements OpenAPIInfo {
version: string;

description: string;
summary: string;
termsOfService?: string;
contact?: OpenAPIContact;
license?: OpenAPILicense;
Expand All @@ -17,6 +18,7 @@ export class ApiInfoModel implements OpenAPIInfo {
constructor(private parser: OpenAPIParser) {
Object.assign(this, parser.spec.info);
this.description = parser.spec.info.description || '';
this.summary = parser.spec.info.summary || '';

const firstHeadingLinePos = this.description.search(/^##?\s+/m);
if (firstHeadingLinePos > -1) {
Expand Down
2 changes: 2 additions & 0 deletions src/types/open-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface OpenAPIInfo {
version: string;

description?: string;
summary?: string;
termsOfService?: string;
contact?: OpenAPIContact;
license?: OpenAPILicense;
Expand Down Expand Up @@ -272,4 +273,5 @@ export interface OpenAPIContact {
export interface OpenAPILicense {
name: string;
url?: string;
identifier?: string;
}

0 comments on commit 16549db

Please sign in to comment.