@@ -2,26 +2,26 @@ import marked from 'marked';
2
2
import { getTypeInfo , schemaToModel , schemaToPdf , removeCircularReferences } from '@/utils/common-utils' ;
3
3
4
4
//Info Def
5
- export function getInfoDef ( spec , bookTitle ) {
5
+ export function getInfoDef ( spec , bookTitle , localize ) {
6
6
let content ;
7
7
if ( spec . info ) {
8
8
let contactDef = [ ] , contactName , contactEmail , contactUrl , termsOfService ;
9
9
10
10
if ( spec . info . contact ) {
11
11
if ( spec . info . contact . name ) {
12
- contactName = { text :[ { text :'Name: ' , style :[ 'b' , 'small' ] } , { text :spec . info . contact . name , style :[ 'small' ] } ] } ;
12
+ contactName = { text :[ { text :`\n ${ localize . name } : ` , style :[ 'b' , 'small' ] } , { text :spec . info . contact . name , style :[ 'small' ] } ] } ;
13
13
}
14
14
if ( spec . info . contact . email ) {
15
- contactEmail = { text :[ { text :'Email: ' , style :[ 'b' , 'small' ] } , { text :spec . info . contact . email , style :[ 'small' ] } ] } ;
15
+ contactEmail = { text :[ { text :`\n ${ localize . email } : ` , style :[ 'b' , 'small' ] } , { text :spec . info . contact . email , style :[ 'small' ] } ] } ;
16
16
}
17
17
if ( spec . info . contact . url ) {
18
- contactUrl = { text :[ { text :'URL: ' , style :[ 'b' , 'small' ] } , { text :spec . info . contact . url , style :[ 'small' , 'blue' ] , link :spec . info . contact . url } ] } ;
18
+ contactUrl = { text :[ { text :`\n ${ localize . url } : ` , style :[ 'b' , 'small' ] } , { text :spec . info . contact . url , style :[ 'small' , 'blue' ] , link :spec . info . contact . url } ] } ;
19
19
}
20
20
if ( spec . info . termsOfService ) {
21
- termsOfService = { text :[ { text :'\nTerms of service: ' , style :[ 'b' , 'small' ] } , { text :spec . info . termsOfService , style :[ 'small' , 'blue' ] , link :spec . info . termsOfService } ] } ;
21
+ termsOfService = { text :[ { text :`\n ${ localize . termsOfService } : ` , style :[ 'b' , 'small' ] } , { text :spec . info . termsOfService , style :[ 'small' , 'blue' ] , link :spec . info . termsOfService } ] } ;
22
22
}
23
23
contactDef = [
24
- { text :'CONTACT' , style :[ 'p' , 'b' , 'topMargin3' ] } ,
24
+ { text :localize . contact , style :[ 'p' , 'b' , 'topMargin3' ] } ,
25
25
{ text :[
26
26
contactName ,
27
27
contactEmail ,
@@ -44,9 +44,9 @@ export function getInfoDef(spec, bookTitle){
44
44
}
45
45
46
46
content = [
47
- { text : bookTitle ? bookTitle :'API Reference' , style :[ 'h2' , 'primary' , 'right' , 'b' , 'topMargin1' ] } ,
47
+ { text : bookTitle ? bookTitle :localize . apiReference , style :[ 'h2' , 'primary' , 'right' , 'b' , 'topMargin1' ] } ,
48
48
( spec . info . title ? { text :spec . info . title , style :[ 'title' , 'right' ] } : '' ) ,
49
- ( spec . info . version ? { text :`API Version : ${ spec . info . version } ` , style :[ 'p' , 'b' , 'right' , 'alternate' ] } : '' ) ,
49
+ ( spec . info . version ? { text :`${ localize . apiVersion } : ${ spec . info . version } ` , style :[ 'p' , 'b' , 'right' , 'alternate' ] } : '' ) ,
50
50
specInfDescrMarkDef ,
51
51
...contactDef ,
52
52
{ text :'' , pageBreak :'after' }
@@ -55,20 +55,20 @@ export function getInfoDef(spec, bookTitle){
55
55
}
56
56
else {
57
57
content = [
58
- { text :bookTitle ?bookTitle :'API Reference' , style :[ 'h1' , 'bold' , 'primary' , 'right' , 'topMargin1' ] }
58
+ { text :bookTitle ?bookTitle :apiVersion . apiReference , style :[ 'h1' , 'bold' , 'primary' , 'right' , 'topMargin1' ] }
59
59
] ;
60
60
}
61
61
return content ;
62
62
} ;
63
63
64
64
//Security Def
65
- export function getSecurityDef ( spec , tableLayout ) {
65
+ export function getSecurityDef ( spec , tableLayout , localize ) {
66
66
let content = [ ]
67
67
if ( spec . securitySchemes ) {
68
- content . push ( { text :'Security and Authentication' , style :[ 'h3' , 'b' , 'primary' , 'right' , 'topMargin3' ] } ) ;
69
- content . push ( { text :'SECURITY SCHEMES' , style :[ 'b' , 'tableMargin' ] } ) ;
68
+ content . push ( { text :localize . securityAndAuthentication , style :[ 'h3' , 'b' , 'primary' , 'right' , 'topMargin3' ] } ) ;
69
+ content . push ( { text :localize . securitySchemes , style :[ 'b' , 'tableMargin' ] } ) ;
70
70
let tableContent = [
71
- [ { text : 'TYPE' , style : [ 'small' , 'b' ] } , { text : 'DESCRIPTION' , style : [ 'small' , 'b' ] } ]
71
+ [ { text : localize . type , style : [ 'small' , 'b' ] } , { text : localize . description , style : [ 'small' , 'b' ] } ]
72
72
] ;
73
73
for ( const key in spec . securitySchemes ) {
74
74
tableContent . push ( [
@@ -90,8 +90,7 @@ export function getSecurityDef(spec, tableLayout){
90
90
} ;
91
91
92
92
// API details def
93
- export function getApiDef ( spec , filterPath , sectionHeading , tableLayout ) {
94
-
93
+ export function getApiDef ( spec , filterPath , sectionHeading , tableLayout , localize ) {
95
94
let content = [ { text : sectionHeading , style :[ 'h2' , 'b' ] , pageBreak :'before' } ] ;
96
95
let tagSeq = 0 ;
97
96
@@ -148,13 +147,12 @@ export function getApiDef(spec, filterPath, sectionHeading, tableLayout){
148
147
const headerParams = path . parameters ? path . parameters . filter ( param => param . in === 'header' ) :null ;
149
148
const cookieParams = path . parameters ? path . parameters . filter ( param => param . in === 'cookie' ) :null ;
150
149
151
- const pathParamTableDef = getParameterTableDef ( pathParams , 'path' , tableLayout ) ;
152
- const queryParamTableDef = getParameterTableDef ( queryParams , 'query' , tableLayout ) ;
153
- const requestBodyTableDefs = getRequestBodyDef ( path . requestBody , tableLayout ) ;
154
- const headerParamTableDef = getParameterTableDef ( headerParams , 'header' , tableLayout ) ;
155
- const cookieParamTableDef = getParameterTableDef ( cookieParams , 'cookie' , tableLayout ) ;
156
-
157
- operationContent . push ( { text : 'REQUEST' , style :[ 'p' , 'b' , 'alternate' ] , margin :[ 0 , 10 , 0 , 0 ] } ) ;
150
+ const pathParamTableDef = getParameterTableDef ( pathParams , 'path' , tableLayout , localize ) ;
151
+ const queryParamTableDef = getParameterTableDef ( queryParams , 'query' , tableLayout , localize ) ;
152
+ const requestBodyTableDefs = getRequestBodyDef ( path . requestBody , tableLayout , localize ) ;
153
+ const headerParamTableDef = getParameterTableDef ( headerParams , 'header' , tableLayout , localize ) ;
154
+ const cookieParamTableDef = getParameterTableDef ( cookieParams , 'cookie' , tableLayout , localize ) ;
155
+ operationContent . push ( { text : localize . request , style :[ 'p' , 'b' , 'alternate' ] , margin :[ 0 , 10 , 0 , 0 ] } ) ;
158
156
if ( pathParamTableDef || queryParamTableDef || headerParamTableDef || cookieParamTableDef || requestBodyTableDefs ) {
159
157
if ( pathParamTableDef ) {
160
158
requestSetDef . push ( pathParamTableDef ) ;
@@ -183,10 +181,8 @@ export function getApiDef(spec, filterPath, sectionHeading, tableLayout){
183
181
stack :requestSetDef ,
184
182
margin :[ 10 , 0 , 0 , 0 ]
185
183
} ) ;
186
-
187
-
188
- let respDef = getResponseDef ( path . responses , tableLayout )
189
- operationContent . push ( { text : 'RESPONSE' , style :[ 'p' , 'b' , 'alternate' ] , margin :[ 0 , 10 , 0 , 0 ] } ) ;
184
+ let respDef = getResponseDef ( path . responses , tableLayout , localize )
185
+ operationContent . push ( { text : localize . response , style :[ 'p' , 'b' , 'alternate' ] , margin :[ 0 , 10 , 0 , 0 ] } ) ;
190
186
operationContent . push ( {
191
187
stack :respDef ,
192
188
margin :[ 10 , 5 , 0 , 5 ]
@@ -231,7 +227,7 @@ export function getApiDef(spec, filterPath, sectionHeading, tableLayout){
231
227
232
228
233
229
//Request Body Def
234
- function getRequestBodyDef ( requestBody , tableLayout ) {
230
+ function getRequestBodyDef ( requestBody , tableLayout , localize ) {
235
231
if ( ! requestBody ) {
236
232
return ;
237
233
}
@@ -242,7 +238,7 @@ function getRequestBodyDef(requestBody, tableLayout){
242
238
let contentTypeObj = requestBody . content [ contentType ] ;
243
239
let requestBodyTableDef ;
244
240
if ( ( contentType . includes ( 'form' ) || contentType . includes ( 'multipart-form' ) ) && contentTypeObj . schema ) {
245
- formParamTableDef = getParameterTableDef ( contentTypeObj . schema . properties , "FORM DATA" , tableLayout ) ;
241
+ formParamTableDef = getParameterTableDef ( contentTypeObj . schema . properties , "FORM DATA" , tableLayout , localize ) ;
246
242
content . push ( formParamTableDef ) ;
247
243
}
248
244
else {
@@ -259,7 +255,7 @@ function getRequestBodyDef(requestBody, tableLayout){
259
255
table : {
260
256
widths :[ '*' ] ,
261
257
body : [
262
- [ { text :'REQUEST BODY ' + contentType , style :[ 'small' , 'b' ] } ] ,
258
+ [ { text :` ${ localize . requestBody } ${ contentType } ` , style :[ 'small' , 'b' ] } ] ,
263
259
requestBodyTableDef
264
260
]
265
261
}
@@ -276,16 +272,16 @@ function getRequestBodyDef(requestBody, tableLayout){
276
272
}
277
273
278
274
//Parameter Table
279
- function getParameterTableDef ( parameters , paramType , tableLayout ) {
275
+ function getParameterTableDef ( parameters , paramType , tableLayout , localize ) {
280
276
//let filteredParams= parameters ? parameters.filter(param => param.in === paramType):[];
281
277
if ( parameters . length == 0 ) {
282
278
return ;
283
279
}
284
280
let tableContent = [
285
281
[
286
- { text : 'NAME' , style : [ 'sub' , 'b' , 'alternate' ] } ,
287
- { text : 'TYPE' , style : [ 'sub' , 'b' , 'alternate' ] } ,
288
- { text : 'DESCRIPTION' , style : [ 'sub' , 'b' , 'alternate' ] }
282
+ { text : localize . name , style : [ 'sub' , 'b' , 'alternate' ] } ,
283
+ { text : localize . type , style : [ 'sub' , 'b' , 'alternate' ] } ,
284
+ { text : localize . description , style : [ 'sub' , 'b' , 'alternate' ] }
289
285
]
290
286
] ;
291
287
@@ -314,19 +310,19 @@ function getParameterTableDef(parameters, paramType, tableLayout){
314
310
text :[
315
311
{ text :paramSchema . required ?'*' :'' , style :[ 'small' , 'b' , 'red' , 'mono' ] } ,
316
312
{ text :param . name , style :[ 'small' , 'mono' ] } ,
317
- ( paramSchema . depricated ?{ text :'\nDEPRICATED' , style :[ 'small' , 'red' , 'b' ] } :undefined )
313
+ ( paramSchema . depricated ?{ text :'\n' + localize . deprecated , style :[ 'small' , 'red' , 'b' ] } :undefined )
318
314
]
319
315
} ,
320
316
{
321
317
stack :[
322
318
{ text : `${ paramSchema . type === 'array' ? paramSchema . arrayType :paramSchema . type } ${ paramSchema . format ? `(${ paramSchema . format } )` :'' } ` , style :[ 'small' , 'mono' ] } ,
323
319
( paramSchema . constrain ? { text : paramSchema . constrain , style :[ 'small' , 'gray' ] } :'' ) ,
324
320
( paramSchema . allowedValues ? { text :[
325
- { text : ' allowed: ', style :[ 'b' , 'small' ] } ,
321
+ { text : localize . allowed + ' : ', style :[ 'b' , 'small' ] } ,
326
322
{ text : paramSchema . allowedValues , style :[ 'small' , 'gray' ] }
327
323
] } : ''
328
324
) ,
329
- ( paramSchema . pattern ? { text : `pattern: ${ paramSchema . pattern } ` , style :[ 'small' , 'gray' ] } :'' ) ,
325
+ ( paramSchema . pattern ? { text : `${ localize . pattern } : ${ paramSchema . pattern } ` , style :[ 'small' , 'gray' ] } :'' ) ,
330
326
]
331
327
} ,
332
328
{ text :param . description , style :[ 'small' ] , margin :[ 0 , 2 , 0 , 0 ] } ,
@@ -335,7 +331,7 @@ function getParameterTableDef(parameters, paramType, tableLayout){
335
331
}
336
332
337
333
return [
338
- { text : `${ paramType } Parameters ` . toUpperCase ( ) , style :[ 'small' , 'b' ] , margin :[ 0 , 10 , 0 , 0 ] } ,
334
+ { text : `${ paramType } ${ localize . parameters } ` . toUpperCase ( ) , style :[ 'small' , 'b' ] , margin :[ 0 , 10 , 0 , 0 ] } ,
339
335
{
340
336
table : {
341
337
headerRows : 1 ,
@@ -351,7 +347,7 @@ function getParameterTableDef(parameters, paramType, tableLayout){
351
347
}
352
348
353
349
//Response Def
354
- function getResponseDef ( responses , tableLayout ) {
350
+ function getResponseDef ( responses , tableLayout , localize ) {
355
351
let respDef = [ ] ;
356
352
let allResponseModelTabelDefs = [ ] ;
357
353
for ( let statusCode in responses ) {
@@ -370,7 +366,7 @@ function getResponseDef(responses, tableLayout){
370
366
table : {
371
367
widths :[ '*' ] ,
372
368
body : [
373
- [ { text :`RESPONSE MODEL (${ contentType } )` , style :[ 'small' , 'b' ] } ] ,
369
+ [ { text :`${ localize . responseModel } (${ contentType } )` , style :[ 'small' , 'b' ] } ] ,
374
370
reponseModelTableDef
375
371
]
376
372
}
@@ -382,7 +378,7 @@ function getResponseDef(responses, tableLayout){
382
378
383
379
respDef . push ( {
384
380
text :[
385
- { text : `STATUS CODE - ${ statusCode } : ` , style :[ 'small' , 'b' ] } ,
381
+ { text : `${ localize . statusCode } - ${ statusCode } : ` , style :[ 'small' , 'b' ] } ,
386
382
{ text : responses [ statusCode ] . description , style :[ 'small' ] }
387
383
] ,
388
384
margin :[ 0 , 10 , 0 , 0 ]
@@ -396,11 +392,11 @@ function getResponseDef(responses, tableLayout){
396
392
}
397
393
398
394
//API List Def
399
- export function getApiListDef ( spec , sectionHeading , tableLayout ) {
395
+ export function getApiListDef ( spec , sectionHeading , tableLayout , localize ) {
400
396
let content = [ { text : sectionHeading , style :[ 'h3' , 'b' ] , pageBreak :'before' } ] ;
401
397
spec . tags . map ( function ( tag , i ) {
402
398
let tableContent = [
403
- [ { text : 'METHOD' , style : [ 'small' , 'b' ] } , { text : 'API' , style : [ 'small' , 'b' ] } ]
399
+ [ { text : localize . method , style : [ 'small' , 'b' ] } , { text : localize . api , style : [ 'small' , 'b' ] } ]
404
400
] ;
405
401
406
402
tag . paths . map ( function ( path ) {
0 commit comments