github.com/TykTechnologies/tyk/cli/importer
No package summary is available.
Package
Files: 1. Third party imports: 2. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Constants
const (
cmdName = "import"
cmdDesc = "Imports a BluePrint/Swagger/WSDL file"
)
Vars
var (
imp *Importer = &Importer{}
errUnknownMode = errors.New("unknown mode")
)
Types
Importer
Importer wraps the import functionality.
| Field name | Field type | Comment |
|---|---|---|
| input |
|
No comment on field. |
| swaggerMode |
|
No comment on field. |
| bluePrintMode |
|
No comment on field. |
| wsdlMode |
|
No comment on field. |
| portNames |
|
No comment on field. |
| createAPI |
|
No comment on field. |
| orgID |
|
No comment on field. |
| upstreamTarget |
|
No comment on field. |
| asMock |
|
No comment on field. |
| forAPI |
|
No comment on field. |
| asVersion |
|
No comment on field. |
type Importer struct {
input *string
swaggerMode *bool
bluePrintMode *bool
wsdlMode *bool
portNames *string
createAPI *bool
orgID *string
upstreamTarget *string
asMock *bool
forAPI *string
asVersion *string
}
Functions
func AddTo
AddTo initializes an importer object.
func AddTo(app *kingpin.Application) {
cmd := app.Command(cmdName, cmdDesc)
imp.input = cmd.Arg("input file", "e.g. blueprint.json, swagger.json, service.wsdl etc.").String()
imp.swaggerMode = cmd.Flag("swagger", "Use Swagger mode").Bool()
imp.bluePrintMode = cmd.Flag("blueprint", "Use BluePrint mode").Bool()
imp.wsdlMode = cmd.Flag("wsdl", "Use WSDL mode").Bool()
imp.portNames = cmd.Flag("port-names", "Specify port name of each service in the WSDL file. Input format is comma separated list of serviceName:portName").String()
imp.createAPI = cmd.Flag("create-api", "Creates a new API definition from the blueprint").Bool()
imp.orgID = cmd.Flag("org-id", "assign the API Definition to this org_id (required with create-api").String()
imp.upstreamTarget = cmd.Flag("upstream-target", "set the upstream target for the definition").PlaceHolder("URL").String()
imp.asMock = cmd.Flag("as-mock", "creates the API as a mock based on example fields").Bool()
imp.forAPI = cmd.Flag("for-api", "adds blueprint to existing API Definition as version").PlaceHolder("PATH").String()
imp.asVersion = cmd.Flag("as-version", "the version number to use when inserting").PlaceHolder("VERSION").String()
cmd.Action(imp.Import)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*Importer) Import
Import performs the import process.
func (i *Importer) Import(_ *kingpin.ParseContext) (err error) {
if *i.swaggerMode {
err = i.handleSwaggerMode()
if err != nil {
log.Fatal(err)
}
} else if *i.bluePrintMode {
err = i.handleBluePrintMode()
if err != nil {
log.Fatal(err)
}
} else if *i.wsdlMode {
err = i.handleWSDLMode()
if err != nil {
log.Fatal(err)
}
} else {
log.Fatal(errUnknownMode)
}
os.Exit(0)
return nil
}
Cognitive complexity: 14, Cyclomatic complexity: 7
Private functions
func apiDefLoadFile
apiDefLoadFile (path string) (*apidef.APIDefinition, error)
References: apidef.APIDefinition, json.NewDecoder, os.Open.
func bluePrintLoadFile
bluePrintLoadFile (path string) (*importer.BluePrintAST, error)
References: importer.ApiaryBluePrint, importer.BluePrintAST, importer.GetImporterForSource, os.Open.
func handleBluePrintMode
handleBluePrintMode () error
References: fmt.Errorf.
func handleSwaggerMode
handleSwaggerMode () error
References: fmt.Errorf.
func handleWSDLMode
handleWSDLMode () error
References: apidef.APIDefinition, fmt.Errorf.
func printDef
printDef (def *apidef.APIDefinition)
References: fmt.Println, json.MarshalIndent, log.Error, strings.Replace.
func processPortNames
processPortNames () map[string]string
References: strings.Split.
func swaggerLoadFile
swaggerLoadFile (path string) (*importer.SwaggerAST, error)
References: importer.GetImporterForSource, importer.SwaggerAST, importer.SwaggerSource, os.Open.
func validateInput
validateInput () error
References: fmt.Errorf.
func wsdlLoadFile
wsdlLoadFile (path string) (*importer.WSDLDef, error)
References: importer.GetImporterForSource, importer.WSDLDef, importer.WSDLSource, os.Open.