File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change @@ -14,7 +14,10 @@ export class ApiInfoModel implements OpenAPIInfo {
14
14
constructor ( private parser : OpenAPIParser ) {
15
15
Object . assign ( this , parser . spec . info ) ;
16
16
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
+ }
18
21
}
19
22
20
23
get downloadLink ( ) : string | undefined {
You can’t perform that action at this time.
0 commit comments