mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 13:44:54 +03:00
feat: add summary and indentifier to license
This commit is contained in:
parent
17d05667af
commit
33ddbbd9f0
|
@ -38,7 +38,7 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
|
||||||
const license =
|
const license =
|
||||||
(info.license && (
|
(info.license && (
|
||||||
<InfoSpan>
|
<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>
|
</InfoSpan>
|
||||||
)) ||
|
)) ||
|
||||||
null;
|
null;
|
||||||
|
@ -100,7 +100,8 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
|
||||||
)) ||
|
)) ||
|
||||||
null}
|
null}
|
||||||
</StyledMarkdownBlock>
|
</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} />}
|
{externalDocs && <ExternalDocumentation externalDocs={externalDocs} />}
|
||||||
</MiddlePanel>
|
</MiddlePanel>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
|
@ -145,7 +145,10 @@ export class AppStore {
|
||||||
|
|
||||||
if (idx === -1 && IS_BROWSER) {
|
if (idx === -1 && IS_BROWSER) {
|
||||||
const $description = document.querySelector('[data-role="redoc-description"]');
|
const $description = document.querySelector('[data-role="redoc-description"]');
|
||||||
|
const $summary = document.querySelector('[data-role="redoc-summary"]');
|
||||||
|
|
||||||
if ($description) elements.push($description);
|
if ($description) elements.push($description);
|
||||||
|
if ($summary) elements.push($summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.marker.addOnly(elements);
|
this.marker.addOnly(elements);
|
||||||
|
|
|
@ -34,5 +34,17 @@ describe('Models', () => {
|
||||||
const info = new ApiInfoModel(parser);
|
const info = new ApiInfoModel(parser);
|
||||||
expect(info.description).toEqual('Test description\nsome text\n');
|
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## Heading\n test');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ export class ApiInfoModel implements OpenAPIInfo {
|
||||||
version: string;
|
version: string;
|
||||||
|
|
||||||
description: string;
|
description: string;
|
||||||
|
summary: string;
|
||||||
termsOfService?: string;
|
termsOfService?: string;
|
||||||
contact?: OpenAPIContact;
|
contact?: OpenAPIContact;
|
||||||
license?: OpenAPILicense;
|
license?: OpenAPILicense;
|
||||||
|
@ -17,6 +18,7 @@ export class ApiInfoModel implements OpenAPIInfo {
|
||||||
constructor(private parser: OpenAPIParser) {
|
constructor(private parser: OpenAPIParser) {
|
||||||
Object.assign(this, parser.spec.info);
|
Object.assign(this, parser.spec.info);
|
||||||
this.description = parser.spec.info.description || '';
|
this.description = parser.spec.info.description || '';
|
||||||
|
this.summary = parser.spec.info.summary || '';
|
||||||
|
|
||||||
const firstHeadingLinePos = this.description.search(/^##?\s+/m);
|
const firstHeadingLinePos = this.description.search(/^##?\s+/m);
|
||||||
if (firstHeadingLinePos > -1) {
|
if (firstHeadingLinePos > -1) {
|
||||||
|
|
2
src/types/open-api.d.ts
vendored
2
src/types/open-api.d.ts
vendored
|
@ -18,6 +18,7 @@ export interface OpenAPIInfo {
|
||||||
version: string;
|
version: string;
|
||||||
|
|
||||||
description?: string;
|
description?: string;
|
||||||
|
summary?: string;
|
||||||
termsOfService?: string;
|
termsOfService?: string;
|
||||||
contact?: OpenAPIContact;
|
contact?: OpenAPIContact;
|
||||||
license?: OpenAPILicense;
|
license?: OpenAPILicense;
|
||||||
|
@ -272,4 +273,5 @@ export interface OpenAPIContact {
|
||||||
export interface OpenAPILicense {
|
export interface OpenAPILicense {
|
||||||
name: string;
|
name: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
|
identifier?: string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user