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 TestRouterCanonicalBasePath(t *testing.T) {
	spec, api := petstore.NewAPI(t)
	spec.Spec().BasePath = "/api///"
	context := NewContext(spec, api, nil)
	mw := newRouter(context, http.HandlerFunc(terminator))

	recorder := httptest.NewRecorder()
	request, _ := http.NewRequest("GET", "/api/pets", nil)

	mw.ServeHTTP(recorder, request)
	assert.Equal(t, 200, recorder.Code)
}