mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-07 21:40:32 +03:00
fix: description is not rendered if doesn't containt markdown headings
fixes #591
This commit is contained in:
parent
2ecc8bc58e
commit
90ed717bb5
38
src/services/__tests__/models/ApiInfo.test.ts
Normal file
38
src/services/__tests__/models/ApiInfo.test.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { ApiInfoModel } from '../../models/ApiInfo';
|
||||||
|
import { OpenAPIParser } from '../../OpenAPIParser';
|
||||||
|
import { RedocNormalizedOptions } from '../../RedocNormalizedOptions';
|
||||||
|
|
||||||
|
const opts = new RedocNormalizedOptions({});
|
||||||
|
describe('Models', () => {
|
||||||
|
describe('ResponseModel', () => {
|
||||||
|
let parser: OpenAPIParser;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
parser = new OpenAPIParser({ openapi: '3.0.0' } as any, undefined, opts);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should correctly populate description field without md headings', () => {
|
||||||
|
parser.spec = {
|
||||||
|
openapi: '3.0.0',
|
||||||
|
info: {
|
||||||
|
description: 'Test description',
|
||||||
|
},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
const info = new ApiInfoModel(parser);
|
||||||
|
expect(info.description).toEqual('Test description');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should correctly populate description up to the first md heading', () => {
|
||||||
|
parser.spec = {
|
||||||
|
openapi: '3.0.0',
|
||||||
|
info: {
|
||||||
|
description: 'Test description\nsome text\n## Heading\n test',
|
||||||
|
},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
const info = new ApiInfoModel(parser);
|
||||||
|
expect(info.description).toEqual('Test description\nsome text\n');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -14,7 +14,10 @@ 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.description = this.description.substring(0, this.description.search(/^##?\s+/m));
|
const firstHeadingLinePos = this.description.search(/^##?\s+/m);
|
||||||
|
if (firstHeadingLinePos > -1) {
|
||||||
|
this.description = this.description.substring(0, firstHeadingLinePos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get downloadLink(): string | undefined {
|
get downloadLink(): string | undefined {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user