func loadSpec(input string) (*spec.Swagger, error) { if fi, err := os.Stat(input); err == nil { if fi.IsDir() { return nil, fmt.Errorf("expected %q to be a file not a directory", input) } sp, err := spec.Load(input) if err != nil { return nil, err } return sp.Spec(), nil } return nil, nil }
func loadSpec(specFile string) (string, *spec.Document, error) { // find swagger spec document, verify it exists specPath, err := findSwaggerSpec(specFile) if err != nil { return "", nil, err } // load swagger spec specDoc, err := spec.Load(specPath) if err != nil { return "", nil, err } return specPath, specDoc, nil }
// Execute validates the spec func (c *ValidateSpec) Execute(args []string) error { if len(args) == 0 { return errors.New("The validate command requires the swagger document url to be specified") } swaggerDoc := args[0] specDoc, err := spec.Load(swaggerDoc) if err != nil { return nil } result := validate.Spec(specDoc, strfmt.Default) if result == nil { fmt.Printf("The swagger spec at %q is valid against swagger specification %s\n", swaggerDoc, specDoc.Version()) } else { str := fmt.Sprintf("The swagger spec at %q is invalid against swagger specification %s. see errors :\n", swaggerDoc, specDoc.Version()) for _, desc := range result.(*swaggererrors.CompositeError).Errors { str += fmt.Sprintf("- %s\n", desc) } return errors.New(str) } return nil }