// NewAPI creates the default untyped API func NewAPI(spec *loads.Document) *API { var an *analysis.Spec if spec != nil && spec.Spec() != nil { an = analysis.New(spec.Spec()) } api := &API{ spec: spec, analyzer: an, consumers: make(map[string]runtime.Consumer, 10), producers: make(map[string]runtime.Producer, 10), authenticators: make(map[string]runtime.Authenticator), operations: make(map[string]map[string]runtime.OperationHandler), ServeError: errors.ServeError, Models: make(map[string]func() interface{}), formats: strfmt.NewFormats(), } return api.WithJSONDefaults() }
// NewAPI creates the default untyped API func NewAPI(spec *loads.Document) *API { var an *analysis.Spec if spec != nil && spec.Spec() != nil { an = analysis.New(spec.Spec()) } return &API{ spec: spec, analyzer: an, DefaultProduces: runtime.JSONMime, DefaultConsumes: runtime.JSONMime, consumers: map[string]runtime.Consumer{ runtime.JSONMime: runtime.JSONConsumer(), }, producers: map[string]runtime.Producer{ runtime.JSONMime: runtime.JSONProducer(), }, authenticators: make(map[string]runtime.Authenticator), operations: make(map[string]map[string]runtime.OperationHandler), ServeError: errors.ServeError, Models: make(map[string]func() interface{}), formats: strfmt.NewFormats(), } }
// 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) }
// Formats returns the registered string formats func (d *API) Formats() strfmt.Registry { if d.formats == nil { d.formats = strfmt.NewFormats() } return d.formats }