@@ -7,51 +7,75 @@ import (
77 "google.golang.org/protobuf/proto"
88)
99
10- func (g * generator ) extractFileOptions (target * descriptor.File ) (* openapi3.T , bool ) {
10+ func (g * generator ) convertFileOptions (target * descriptor.File ) (* openapi3.T , bool ) {
1111 if openAPIAno := proto .GetExtension (target .GetOptions (), options .E_Openapiv3Document ).(* options.OpenAPI ); openAPIAno != nil {
1212 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 ()),
1417 }
15- doc .Info = g .extractInfo (openAPIAno .GetInfo ())
1618 // TODO: implement other openapi file annotation fields
1719 return doc , true
1820 }
1921
2022 return nil , false
2123}
2224
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 {
2450 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 (),
2854 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 ()),
3157 }
3258}
3359
34- func (g * generator ) extractContact (contactOption * options.Contact ) * openapi3.Contact {
60+ func (g * generator ) convertContact (contactOption * options.Contact ) * openapi3.Contact {
3561 if contactOption == nil {
3662 return nil
3763 }
3864
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+ }
4570}
4671
47- func (g * generator ) extractLicense (licenseOption * options.License ) * openapi3.License {
72+ func (g * generator ) convertLicense (licenseOption * options.License ) * openapi3.License {
4873 if licenseOption == nil {
4974 return nil
5075 }
5176
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+ }
5781}
0 commit comments