44 "fmt"
55 "github.com/okhuz/openapi2krakend/pkg/extensions"
66 "github.com/okhuz/openapi2krakend/pkg/models"
7+ "github.com/okhuz/openapi2krakend/pkg/utility"
78 "io/fs"
89 "io/ioutil"
910)
@@ -23,6 +24,7 @@ func Convert(swaggerDirectory string, encoding string, globalTimeout string) mod
2324
2425 host := openApiDefinition .Servers [0 ].URL
2526 path := sanitizeTitle (openApiDefinition .Info .Title )
27+ pathPrefix := utility .GetEnv ("PATH_PREFIX" , "" )
2628 apiTimeout := globalTimeout
2729
2830 if extensionValue := getExtension (openApiDefinition .Extensions , extensions .TimeOut ); extensionValue != "" {
@@ -32,17 +34,20 @@ func Convert(swaggerDirectory string, encoding string, globalTimeout string) mod
3234 for pathUrl , pathItem := range openApiDefinition .Paths {
3335 for methodName , methodObject := range pathItem .Operations () {
3436
35- endpoint := fmt .Sprintf ("%s" , pathUrl )
37+ krakendEndpointUrl := fmt .Sprintf ("%s" , pathUrl )
3638 if numberOfFiles > 1 {
37- endpoint = fmt .Sprintf ("/%s%s" , path , pathUrl )
39+ krakendEndpointUrl = fmt .Sprintf ("/%s%s" , path , pathUrl )
40+ }
41+ if pathPrefix != "" {
42+ krakendEndpointUrl = fmt .Sprintf ("/%s%s" , pathPrefix , pathUrl )
3843 }
3944
4045 methodTimeout := apiTimeout
4146 if extensionValue := getExtension (methodObject .Extensions , extensions .TimeOut ); extensionValue != "" {
4247 methodTimeout = extensionValue
4348 }
4449
45- krakendEndpoint := models .NewEndpoint (host , endpoint , pathUrl , methodName , encoding , methodTimeout )
50+ krakendEndpoint := models .NewEndpoint (host , krakendEndpointUrl , pathUrl , methodName , encoding , methodTimeout )
4651 if methodObject .Security != nil {
4752 lengthOfSecurity := len (* methodObject .Security )
4853 if lengthOfSecurity > 0 {
0 commit comments