Skip to content

Commit 90ed717

Browse files
committed
fix: description is not rendered if doesn't containt markdown headings
fixes #591
1 parent 2ecc8bc commit 90ed717

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ApiInfoModel } from '../../models/ApiInfo';
2+
import { OpenAPIParser } from '../../OpenAPIParser';
3+
import { RedocNormalizedOptions } from '../../RedocNormalizedOptions';
4+
5+
const opts = new RedocNormalizedOptions({});
6+
describe('Models', () => {
7+
describe('ResponseModel', () => {
8+
let parser: OpenAPIParser;
9+
10+
beforeEach(() => {
11+
parser = new OpenAPIParser({ openapi: '3.0.0' } as any, undefined, opts);
12+
});
13+
14+
test('should correctly populate description field without md headings', () => {
15+
parser.spec = {
16+
openapi: '3.0.0',
17+
info: {
18+
description: 'Test description',
19+
},
20+
} as any;
21+
22+
const info = new ApiInfoModel(parser);
23+
expect(info.description).toEqual('Test description');
24+
});
25+
26+
test('should correctly populate description up to the first md heading', () => {
27+
parser.spec = {
28+
openapi: '3.0.0',
29+
info: {
30+
description: 'Test description\nsome text\n## Heading\n test',
31+
},
32+
} as any;
33+
34+
const info = new ApiInfoModel(parser);
35+
expect(info.description).toEqual('Test description\nsome text\n');
36+
});
37+
});
38+
});

src/services/models/ApiInfo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export class ApiInfoModel implements OpenAPIInfo {
1414
constructor(private parser: OpenAPIParser) {
1515
Object.assign(this, parser.spec.info);
1616
this.description = parser.spec.info.description || '';
17-
this.description = this.description.substring(0, this.description.search(/^##?\s+/m));
17+
const firstHeadingLinePos = this.description.search(/^##?\s+/m);
18+
if (firstHeadingLinePos > -1) {
19+
this.description = this.description.substring(0, firstHeadingLinePos);
20+
}
1821
}
1922

2023
get downloadLink(): string | undefined {

0 commit comments

Comments
 (0)