Example #1
0
// validateSwagger validates that the given swagger object represents a valid Swagger spec.
func validateSwagger(swagger *genswagger.Swagger) {
	b, err := json.Marshal(swagger)
	Ω(err).ShouldNot(HaveOccurred())
	doc, err := spec.New(b, "")
	Ω(err).ShouldNot(HaveOccurred())
	err = validate.Spec(doc, strfmt.NewFormats())
	Ω(err).ShouldNot(HaveOccurred())
}
Example #2
0
// NewAPI creates the default untyped API
func NewAPI(spec *spec.Document) *API {
	return &API{
		spec:            spec,
		DefaultProduces: httpkit.JSONMime,
		DefaultConsumes: httpkit.JSONMime,
		consumers: map[string]httpkit.Consumer{
			httpkit.JSONMime: httpkit.JSONConsumer(),
		},
		producers: map[string]httpkit.Producer{
			httpkit.JSONMime: httpkit.JSONProducer(),
		},
		authenticators: make(map[string]httpkit.Authenticator),
		operations:     make(map[string]httpkit.OperationHandler),
		ServeError:     errors.ServeError,
		Models:         make(map[string]func() interface{}),
		formats:        strfmt.NewFormats(),
	}
}
Example #3
0
// RegisterFormat registers a custom format validator
func (d *API) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
	if d.formats == nil {
		d.formats = strfmt.NewFormats()
	}
	d.formats.Add(name, format, validator)
}
Example #4
0
// Formats returns the registered string formats
func (d *API) Formats() strfmt.Registry {
	if d.formats == nil {
		d.formats = strfmt.NewFormats()
	}
	return d.formats
}