fix: description is not rendered if doesn't containt markdown headings

fixes #591
This commit is contained in:
Roman Hotsiy 2018-08-07 11:27:41 +03:00
parent 2ecc8bc58e
commit 90ed717bb5
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 42 additions and 1 deletions

View 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');
});
});
});

View File

@ -14,7 +14,10 @@ export class ApiInfoModel implements OpenAPIInfo {
constructor(private parser: OpenAPIParser) {
Object.assign(this, parser.spec.info);
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 {