Example #1
0
func main() {
	flag.Parse()

	// parses the swagger spec file
	spec, err := spec.YAMLSpec(*input)
	if err != nil {
		log.Fatal(err)
	}
	swag := spec.Spec()

	// we wrap the swagger file in a map, otherwise it
	// won't work with our existing templates, which expect
	// a map as the root parameter.
	var swag_ = normalize(swag)
	for _, tag := range swag_.Tags {
		w, _ := os.Create(
			filepath.Join(*output, strings.ToLower(tag.Name)) + ".md",
		)
		defer w.Close()

		t := template.Must(template.ParseFiles(*templ))
		err = t.Execute(w, tag)
		if err != nil {
			log.Fatal(err)
		}
	}
}
Example #2
0
func main() {
	flag.Parse()

	// parses the swagger spec file
	spec, err := spec.YAMLSpec(*input)
	if err != nil {
		log.Fatal(err)
	}
	swag := spec.Spec()

	// create output source for file. defaults to
	// stdout but may be file.
	var w io.WriteCloser = os.Stdout
	if *output != "" {
		w, err = os.Create(*output)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			return
		}
		defer w.Close()
	}

	// we wrap the swagger file in a map, otherwise it
	// won't work with our existing templates, which expect
	// a map as the root parameter.
	var data = map[string]interface{}{
		"Swagger": normalize(swag),
	}

	t := amber.MustCompileFile(*templ, amber.DefaultOptions)
	err = t.Execute(w, data)
	if err != nil {
		log.Fatal(err)
	}
}
Example #3
0
func TestValidateReferenced(t *testing.T) {
	doc, err := spec.YAMLSpec(filepath.Join("..", "..", "fixtures", "validation", "valid-referenced.yml"))
	if assert.NoError(t, err) {
		validator := NewSpecValidator(spec.MustLoadSwagger20Schema(), strfmt.Default)
		validator.spec = doc
		res := validator.validateReferenced()
		assert.Empty(t, res.Errors)
	}

	doc, err = spec.YAMLSpec(filepath.Join("..", "..", "fixtures", "validation", "invalid-referenced.yml"))
	if assert.NoError(t, err) {
		validator := NewSpecValidator(spec.MustLoadSwagger20Schema(), strfmt.Default)
		validator.spec = doc
		res := validator.validateReferenced()
		assert.NotEmpty(t, res.Errors)
		assert.Len(t, res.Errors, 3)
	}
}
Example #4
0
func TestIssue123(t *testing.T) {
	fp := filepath.Join("..", "fixtures", "bugs", "123", "swagger.yml")

	// as swagger spec
	doc, err := spec.YAMLSpec(fp)
	if assert.NoError(t, err) {
		validator := intvalidate.NewSpecValidator(doc.Schema(), strfmt.Default)
		res, _ := validator.Validate(doc)
		for _, e := range res.Errors {
			fmt.Println(e)
		}
		assert.True(t, res.IsValid())
	}
}