func invalidProgram(name string) *loader.Program {
	var ldr loader.Config
	ldr.ParserMode = goparser.ParseComments
	ldr.Import("../fixtures/goparsing/" + name)
	prog, err := ldr.Load()
	if err != nil {
		log.Fatal(err)
	}
	return prog
}
Exemple #2
0
// allowErrors causes type errors to be silently ignored.
// (Not suitable if SSA construction follows.)
func allowErrors(lconf *loader.Config) {
	ctxt := *lconf.Build // copy
	ctxt.CgoEnabled = false
	lconf.Build = &ctxt
	lconf.AllowErrors = true
	// AllErrors makes the parser always return an AST instead of
	// bailing out after 10 errors and returning an empty ast.File.
	lconf.ParserMode = parser.AllErrors
	lconf.TypeChecker.Error = func(err error) {}
}
func classifierProgram() *loader.Program {
	var ldr loader.Config
	ldr.ParserMode = goparser.ParseComments
	ldr.Import("../fixtures/goparsing/classification")
	ldr.Import("../fixtures/goparsing/classification/models")
	ldr.Import("../fixtures/goparsing/classification/operations")
	prog, err := ldr.Load()
	if err != nil {
		log.Fatal(err)
	}
	return prog
}
func petstoreProgram() *loader.Program {
	var ldr loader.Config
	ldr.ParserMode = goparser.ParseComments
	ldr.Build = &gobuild.Default
	ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/petstore")
	ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/models")
	ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/rest/handlers")
	prog, err := ldr.Load()
	if err != nil {
		log.Fatal(err)
	}
	return prog
}
func classifierProgram() *loader.Program {
	var ldr loader.Config
	ldr.ParserMode = goparser.ParseComments
	ldr.Build = &gobuild.Default
	ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/classification")
	ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/classification/models")
	ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/classification/operations")
	prog, err := ldr.Load()
	if err != nil {
		log.Fatal(err)
	}
	return prog
}
// ParsePathsFromArgs parses arguments from command line and looks at import
// paths to rename objects.
func ParsePathsFromArgs() {
	flag.Parse()
	for _, dir := range flag.Args() {
		var conf loader.Config
		conf.ParserMode = parser.ParseComments
		conf.ImportWithTests(dir)
		prog, err := conf.Load()
		if err != nil {
			panic(err)
		}

		r := renamer{prog, map[*token.File]bool{}}
		r.parse()
		if !*dryRun {
			r.write()
		}
	}
}
Exemple #7
0
// newAppScanner creates a new api parser
func newAppScanner(opts *Opts, includes, excludes packageFilters) (*appScanner, error) {
	var ldr loader.Config
	ldr.ParserMode = goparser.ParseComments
	ldr.ImportWithTests(opts.BasePath)
	prog, err := ldr.Load()
	if err != nil {
		return nil, err
	}

	input := opts.Input
	if input == nil {
		input = new(spec.Swagger)
		input.Swagger = "2.0"
	}

	if input.Paths == nil {
		input.Paths = new(spec.Paths)
	}
	if input.Definitions == nil {
		input.Definitions = make(map[string]spec.Schema)
	}
	if input.Responses == nil {
		input.Responses = make(map[string]spec.Response)
	}

	return &appScanner{
		MainPackage: opts.BasePath,
		prog:        prog,
		input:       input,
		loader:      &ldr,
		operations:  collectOperationsFromInput(input),
		definitions: input.Definitions,
		responses:   input.Responses,
		scanModels:  opts.ScanModels,
		classifier: &programClassifier{
			Includes: includes,
			Excludes: excludes,
		},
	}, nil
}