-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Reuven
committed
Feb 4, 2024
1 parent
30a4a75
commit 5283b5c
Showing
3 changed files
with
50 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Package load loads OpenAPI specs from different sources like URL, Path, stdin | ||
// Package load loads OpenAPI specs from different sources like URLs, paths, globs and stdin | ||
// Optionally, specs can be preprocessed after loading | ||
package load |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package load | ||
|
||
import ( | ||
"github.com/tufin/oasdiff/flatten/allof" | ||
"github.com/tufin/oasdiff/flatten/commonparams" | ||
) | ||
|
||
// option functions can be used to preprocess specs after loading them | ||
type Option func(Loader, []*SpecInfo) ([]*SpecInfo, error) | ||
|
||
// WithIdentity returns the original SpecInfos | ||
func WithIdentity() Option { | ||
return func(loader Loader, specInfos []*SpecInfo) ([]*SpecInfo, error) { | ||
return specInfos, nil | ||
} | ||
} | ||
|
||
// GetOption returns the requested option or the identity option | ||
func GetOption(option Option, enable bool) Option { | ||
if !enable { | ||
return WithIdentity() | ||
} | ||
return option | ||
} | ||
|
||
// WithFlattenAllOf returns SpecInfos with flattened allOf | ||
func WithFlattenAllOf() Option { | ||
return func(loader Loader, specInfos []*SpecInfo) ([]*SpecInfo, error) { | ||
var err error | ||
for _, specInfo := range specInfos { | ||
if specInfo.Spec, err = allof.MergeSpec(specInfo.Spec); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return specInfos, nil | ||
} | ||
} | ||
|
||
// WithFlattenParams returns SpecInfos with Common Parameters combined into operation parameters | ||
// See here for Common Parameters definition: https://swagger.io/docs/specification/describing-parameters/ | ||
func WithFlattenParams() Option { | ||
return func(loader Loader, specInfos []*SpecInfo) ([]*SpecInfo, error) { | ||
for _, specInfo := range specInfos { | ||
commonparams.Move(specInfo.Spec) | ||
} | ||
return specInfos, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters