Skip to content

Commit

Permalink
openapi2conv: expose loader and location to ToV3 (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriehSchneier authored Oct 31, 2023
1 parent c446426 commit bfab8b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/docs/openapi2conv.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ func ToV3SchemaRef(schema *openapi3.SchemaRef) *openapi3.SchemaRef
func ToV3Schemas(defs map[string]*openapi3.SchemaRef) map[string]*openapi3.SchemaRef
func ToV3SecurityRequirements(requirements openapi2.SecurityRequirements) openapi3.SecurityRequirements
func ToV3SecurityScheme(securityScheme *openapi2.SecurityScheme) (*openapi3.SecuritySchemeRef, error)
func ToV3WithLoader(doc2 *openapi2.T, loader *openapi3.Loader, location *url.URL) (*openapi3.T, error)
13 changes: 8 additions & 5 deletions openapi2conv/openapi2_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (

// ToV3 converts an OpenAPIv2 spec to an OpenAPIv3 spec
func ToV3(doc2 *openapi2.T) (*openapi3.T, error) {
return ToV3WithLoader(doc2, openapi3.NewLoader(), nil)
}

func ToV3WithLoader(doc2 *openapi2.T, loader *openapi3.Loader, location *url.URL) (*openapi3.T, error) {
doc3 := &openapi3.T{
OpenAPI: "3.0.3",
Info: &doc2.Info,
Expand Down Expand Up @@ -106,12 +110,11 @@ func ToV3(doc2 *openapi2.T) (*openapi3.T, error) {
}

doc3.Security = ToV3SecurityRequirements(doc2.Security)
{
sl := openapi3.NewLoader()
if err := sl.ResolveRefsIn(doc3, nil); err != nil {
return nil, err
}

if err := loader.ResolveRefsIn(doc3, location); err != nil {
return nil, err
}

return doc3, nil
}

Expand Down

0 comments on commit bfab8b0

Please sign in to comment.