@@ -22,6 +22,46 @@ func NewService(log logger.Logger, repo AsdRepository) Service {
22
22
return & ServiceImpl {log : log , asdRepo : repo }
23
23
}
24
24
25
+ var asdTypeMap = map [string ]apispecproto.Type {
26
+ string (apispecdoc .TypeOpenApi ): apispecproto .Type_OPEN_API ,
27
+ }
28
+
29
+ var methodTypeMap = map [string ]apispecproto.MethodType {
30
+ string (apispecdoc .MethodConnect ): apispecproto .MethodType_CONNECT ,
31
+ string (apispecdoc .MethodGet ): apispecproto .MethodType_GET ,
32
+ string (apispecdoc .MethodPut ): apispecproto .MethodType_PUT ,
33
+ string (apispecdoc .MethodPost ): apispecproto .MethodType_POST ,
34
+ string (apispecdoc .MethodDelete ): apispecproto .MethodType_DELETE ,
35
+ string (apispecdoc .MethodOptions ): apispecproto .MethodType_OPTIONS ,
36
+ string (apispecdoc .MethodHead ): apispecproto .MethodType_HEAD ,
37
+ string (apispecdoc .MethodPatch ): apispecproto .MethodType_PATCH ,
38
+ string (apispecdoc .MethodTrace ): apispecproto .MethodType_TRACE ,
39
+ }
40
+
41
+ var schemaTypeMap = map [apispecdoc.SchemaType ]apispecproto.SchemaType {
42
+ apispecdoc .Unknown : apispecproto .SchemaType_UNKNOWN ,
43
+ apispecdoc .NotDefined : apispecproto .SchemaType_NOT_DEFINED ,
44
+ apispecdoc .Integer : apispecproto .SchemaType_INTEGER ,
45
+ apispecdoc .Boolean : apispecproto .SchemaType_BOOLEAN ,
46
+ apispecdoc .Number : apispecproto .SchemaType_NUMBER ,
47
+ apispecdoc .String : apispecproto .SchemaType_STRING ,
48
+ apispecdoc .Date : apispecproto .SchemaType_DATE ,
49
+ apispecdoc .Array : apispecproto .SchemaType_ARRAY ,
50
+ apispecdoc .Map : apispecproto .SchemaType_MAP ,
51
+ apispecdoc .OneOf : apispecproto .SchemaType_ONE_OF ,
52
+ apispecdoc .AnyOf : apispecproto .SchemaType_ANY_OF ,
53
+ apispecdoc .AllOf : apispecproto .SchemaType_ALL_OF ,
54
+ apispecdoc .Not : apispecproto .SchemaType_NOT ,
55
+ apispecdoc .Object : apispecproto .SchemaType_OBJECT ,
56
+ }
57
+
58
+ var parameterTypeMap = map [apispecdoc.ParameterType ]apispecproto.ParameterType {
59
+ apispecdoc .ParameterQuery : apispecproto .ParameterType_QUERY ,
60
+ apispecdoc .ParameterHeader : apispecproto .ParameterType_HEADER ,
61
+ apispecdoc .ParameterPath : apispecproto .ParameterType_PATH ,
62
+ apispecdoc .ParameterCookie : apispecproto .ParameterType_COOKIE ,
63
+ }
64
+
25
65
type ServiceImpl struct {
26
66
log logger.Logger
27
67
asdRepo AsdRepository
@@ -344,86 +384,34 @@ func entitySchemasToResponses(schemas []*apispecdoc.Schema) []*apispecproto.Sche
344
384
return resSchemas
345
385
}
346
386
347
- func paramTypeToResponse (tp apispecdoc.ParameterType ) apispecproto.ParameterType {
348
- switch tp {
349
- case apispecdoc .ParameterQuery :
350
- return apispecproto .ParameterType_QUERY
351
- case apispecdoc .ParameterHeader :
352
- return apispecproto .ParameterType_HEADER
353
- case apispecdoc .ParameterPath :
354
- return apispecproto .ParameterType_PATH
355
- case apispecdoc .ParameterCookie :
356
- return apispecproto .ParameterType_COOKIE
357
- }
358
- //TODO to map implementation to prevent extra actions
359
-
387
+ func paramTypeToResponse (pt apispecdoc.ParameterType ) apispecproto.ParameterType {
388
+ res , ok := parameterTypeMap [pt ]
389
+ if ok {
390
+ return res
391
+ }
360
392
return apispecproto .ParameterType_QUERY //TODO unknown type here for default case
361
393
}
362
394
363
395
func methodTypeToResponse (mt string ) apispecproto.MethodType {
364
- switch mt {
365
- case string (apispecdoc .MethodConnect ):
366
- return apispecproto .MethodType_CONNECT
367
- case string (apispecdoc .MethodGet ):
368
- return apispecproto .MethodType_GET
369
- case string (apispecdoc .MethodPut ):
370
- return apispecproto .MethodType_PUT
371
- case string (apispecdoc .MethodPost ):
372
- return apispecproto .MethodType_POST
373
- case string (apispecdoc .MethodDelete ):
374
- return apispecproto .MethodType_DELETE
375
- case string (apispecdoc .MethodOptions ):
376
- return apispecproto .MethodType_OPTIONS
377
- case string (apispecdoc .MethodHead ):
378
- return apispecproto .MethodType_HEAD
379
- case string (apispecdoc .MethodPatch ):
380
- return apispecproto .MethodType_PATCH
381
- case string (apispecdoc .MethodTrace ):
382
- return apispecproto .MethodType_TRACE
383
- }
384
- //TODO to map implementation to prevent extra actions
385
-
396
+ res , ok := methodTypeMap [mt ]
397
+ if ok {
398
+ return res
399
+ }
386
400
return apispecproto .MethodType_GET //TODO unknown type here for default case
387
401
}
388
402
389
403
func schemaTypeToResponse (st apispecdoc.SchemaType ) apispecproto.SchemaType {
390
- switch st {
391
- case apispecdoc .NotDefined :
392
- return apispecproto .SchemaType_NOT_DEFINED
393
- case apispecdoc .Integer :
394
- return apispecproto .SchemaType_INTEGER
395
- case apispecdoc .Boolean :
396
- return apispecproto .SchemaType_BOOLEAN
397
- case apispecdoc .Number :
398
- return apispecproto .SchemaType_NUMBER
399
- case apispecdoc .String :
400
- return apispecproto .SchemaType_STRING
401
- case apispecdoc .Date :
402
- return apispecproto .SchemaType_DATE
403
- case apispecdoc .Array :
404
- return apispecproto .SchemaType_ARRAY
405
- case apispecdoc .Map :
406
- return apispecproto .SchemaType_MAP
407
- case apispecdoc .OneOf :
408
- return apispecproto .SchemaType_ONE_OF
409
- case apispecdoc .AnyOf :
410
- return apispecproto .SchemaType_ANY_OF
411
- case apispecdoc .AllOf :
412
- return apispecproto .SchemaType_ALL_OF
413
- case apispecdoc .Not :
414
- return apispecproto .SchemaType_NOT
415
- case apispecdoc .Object :
416
- return apispecproto .SchemaType_OBJECT
417
- default :
418
- return apispecproto .SchemaType_UNKNOWN
419
- }
420
- //TODO to map implementation to prevent extra actions
404
+ res , ok := schemaTypeMap [st ]
405
+ if ok {
406
+ return res
407
+ }
408
+ return apispecproto .SchemaType_UNKNOWN
421
409
}
422
410
423
411
func apiTypeToResponse (asdT string ) apispecproto.Type {
424
- switch asdT {
425
- case string ( apispecdoc . TypeOpenApi ):
426
- return apispecproto . Type_OPEN_API
412
+ res , ok := asdTypeMap [ asdT ]
413
+ if ok {
414
+ return res
427
415
}
428
416
return apispecproto .Type_OPEN_API
429
417
}
0 commit comments