Fix the issue of converting swagger V2 to V3
@@ -32,8 +32,7 @@ var logger = log.Log.WithName("swagger")
func GetSwaggerV3(swaggerStr *string) (*openapi3.Swagger, error) {
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData([]byte(*swaggerStr))
if err != nil {
- logger.Error(err, "Error loading swagger")
- return nil, err
+ return GetSwaggerV2(swaggerStr)
}
swaggerV3Version := swagger.OpenAPI
@@ -43,12 +42,17 @@ func GetSwaggerV3(swaggerStr *string) (*openapi3.Swagger, error) {
return swagger, err
} else {
logger.Info("OpenAPI v3 not found. Hence converting Swagger v2 to Swagger v3")
+ return GetSwaggerV2(swaggerStr)
+ }
+}
+
+// GetSwaggerV2 returns the openapi2.Swagger of given swagger string
+func GetSwaggerV2(swaggerStr *string) (*openapi3.Swagger, error) {
var swagger2 openapi2.Swagger
err2 := yaml.Unmarshal([]byte(*swaggerStr), &swagger2)
swaggerV3, err2 := openapi2conv.ToV3Swagger(&swagger2)
return swaggerV3, err2
}
-}
func PrettyString(swagger *openapi3.Swagger) string {
var prettyJSON bytes.Buffer
