@@ -7,51 +7,75 @@ import (
7
7
"google.golang.org/protobuf/proto"
8
8
)
9
9
10
- func (g * generator ) extractFileOptions (target * descriptor.File ) (* openapi3.T , bool ) {
10
+ func (g * generator ) convertFileOptions (target * descriptor.File ) (* openapi3.T , bool ) {
11
11
if openAPIAno := proto .GetExtension (target .GetOptions (), options .E_Openapiv3Document ).(* options.OpenAPI ); openAPIAno != nil {
12
12
doc := & openapi3.T {
13
- OpenAPI : OpenAPIVersion ,
13
+ OpenAPI : OpenAPIVersion ,
14
+ Info : g .convertInfo (openAPIAno .GetInfo ()),
15
+ Security : * convertSecurityRequiremnt (openAPIAno .GetSecurity ()),
16
+ Servers : g .convertServers (openAPIAno .GetServers ()),
14
17
}
15
- doc .Info = g .extractInfo (openAPIAno .GetInfo ())
16
18
// TODO: implement other openapi file annotation fields
17
19
return doc , true
18
20
}
19
21
20
22
return nil , false
21
23
}
22
24
23
- func (g * generator ) extractInfo (openAPIInfo * options.Info ) * openapi3.Info {
25
+ func (g * generator ) convertServers (servers []* options.Server ) openapi3.Servers {
26
+ oAPIservers := make (openapi3.Servers , len (servers ))
27
+
28
+ for i , srv := range servers {
29
+ vars := map [string ]* openapi3.ServerVariable {}
30
+
31
+ for k , v := range srv .GetVariables () {
32
+ vars [k ] = & openapi3.ServerVariable {
33
+ Enum : v .GetEnum (),
34
+ Default : v .GetDefault (),
35
+ Description : v .GetDescription (),
36
+ }
37
+ }
38
+
39
+ oAPIservers [i ] = & openapi3.Server {
40
+ URL : srv .GetUrl (),
41
+ Description : srv .GetDescription (),
42
+ Variables : vars ,
43
+ }
44
+ }
45
+
46
+ return oAPIservers
47
+ }
48
+
49
+ func (g * generator ) convertInfo (openAPIInfo * options.Info ) * openapi3.Info {
24
50
return & openapi3.Info {
25
- Title : openAPIInfo .GetTitle (),
26
- Description : openAPIInfo .GetDescription (),
27
- Version : openAPIInfo .GetVersion (),
51
+ Title : openAPIInfo .GetTitle (),
52
+ Description : openAPIInfo .GetDescription (),
53
+ Version : openAPIInfo .GetVersion (),
28
54
TermsOfService : openAPIInfo .GetTermsOfService (),
29
- Contact : g . extractContact (openAPIInfo .GetContact ()),
30
- License : g . extractLicense (openAPIInfo .GetLicense ()),
55
+ Contact : g . convertContact (openAPIInfo .GetContact ()),
56
+ License : g . convertLicense (openAPIInfo .GetLicense ()),
31
57
}
32
58
}
33
59
34
- func (g * generator ) extractContact (contactOption * options.Contact ) * openapi3.Contact {
60
+ func (g * generator ) convertContact (contactOption * options.Contact ) * openapi3.Contact {
35
61
if contactOption == nil {
36
62
return nil
37
63
}
38
64
39
- contact := & openapi3.Contact {}
40
- contact .Name = contactOption .GetName ()
41
- contact .URL = contactOption .GetUrl ()
42
- contact .Email = contactOption .GetEmail ()
43
-
44
- return contact
65
+ return & openapi3.Contact {
66
+ Name : contactOption .GetName (),
67
+ URL : contactOption .GetUrl (),
68
+ Email : contactOption .GetEmail (),
69
+ }
45
70
}
46
71
47
- func (g * generator ) extractLicense (licenseOption * options.License ) * openapi3.License {
72
+ func (g * generator ) convertLicense (licenseOption * options.License ) * openapi3.License {
48
73
if licenseOption == nil {
49
74
return nil
50
75
}
51
76
52
- license := & openapi3.License {}
53
- license .Name = licenseOption .GetName ()
54
- license .URL = licenseOption .GetUrl ()
55
-
56
- return license
77
+ return & openapi3.License {
78
+ Name : licenseOption .GetName (),
79
+ URL : licenseOption .GetUrl (),
80
+ }
57
81
}
0 commit comments