Skip to content

Commit

Permalink
fix: description is not rendered if doesn't containt markdown headings
Browse files Browse the repository at this point in the history
fixes #591
  • Loading branch information
RomanHotsiy committed Aug 7, 2018
1 parent 2ecc8bc commit 90ed717
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/services/__tests__/models/ApiInfo.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
});
5 changes: 4 additions & 1 deletion src/services/models/ApiInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 90ed717

Please sign in to comment.