@@ -22,6 +22,46 @@ func NewService(log logger.Logger, repo AsdRepository) Service {
2222 return & ServiceImpl {log : log , asdRepo : repo }
2323}
2424
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+
2565type ServiceImpl struct {
2666 log logger.Logger
2767 asdRepo AsdRepository
@@ -344,86 +384,34 @@ func entitySchemasToResponses(schemas []*apispecdoc.Schema) []*apispecproto.Sche
344384 return resSchemas
345385}
346386
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+ }
360392 return apispecproto .ParameterType_QUERY //TODO unknown type here for default case
361393}
362394
363395func 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+ }
386400 return apispecproto .MethodType_GET //TODO unknown type here for default case
387401}
388402
389403func 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
421409}
422410
423411func 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
427415 }
428416 return apispecproto .Type_OPEN_API
429417}
0 commit comments