3 // Copyright 2013 Ernest Micklei. All rights reserved.
4 // Use of this source code is governed by a license
5 // that can be found in the LICENSE file.
8 // PathParameterKind = indicator of Request parameter type "path"
9 PathParameterKind = iota
11 // QueryParameterKind = indicator of Request parameter type "query"
14 // BodyParameterKind = indicator of Request parameter type "body"
17 // HeaderParameterKind = indicator of Request parameter type "header"
20 // FormParameterKind = indicator of Request parameter type "form"
23 // CollectionFormatCSV comma separated values `foo,bar`
24 CollectionFormatCSV = CollectionFormat("csv")
26 // CollectionFormatSSV space separated values `foo bar`
27 CollectionFormatSSV = CollectionFormat("ssv")
29 // CollectionFormatTSV tab separated values `foo\tbar`
30 CollectionFormatTSV = CollectionFormat("tsv")
32 // CollectionFormatPipes pipe separated values `foo|bar`
33 CollectionFormatPipes = CollectionFormat("pipes")
35 // CollectionFormatMulti corresponds to multiple parameter instances instead of multiple values for a single
36 // instance `foo=bar&foo=baz`. This is valid only for QueryParameters and FormParameters
37 CollectionFormatMulti = CollectionFormat("multi")
40 type CollectionFormat string
42 func (cf CollectionFormat) String() string {
46 // Parameter is for documententing the parameter used in a Http Request
47 // ParameterData kinds are Path,Query and Body
48 type Parameter struct {
52 // ParameterData represents the state of a Parameter.
53 // It is made public to make it accessible to e.g. the Swagger package.
54 type ParameterData struct {
55 Name, Description, DataType, DataFormat string
58 AllowableValues map[string]string
61 CollectionFormat string
64 // Data returns the state of the Parameter
65 func (p *Parameter) Data() ParameterData {
69 // Kind returns the parameter type indicator (see const for valid values)
70 func (p *Parameter) Kind() int {
74 func (p *Parameter) bePath() *Parameter {
75 p.data.Kind = PathParameterKind
78 func (p *Parameter) beQuery() *Parameter {
79 p.data.Kind = QueryParameterKind
82 func (p *Parameter) beBody() *Parameter {
83 p.data.Kind = BodyParameterKind
87 func (p *Parameter) beHeader() *Parameter {
88 p.data.Kind = HeaderParameterKind
92 func (p *Parameter) beForm() *Parameter {
93 p.data.Kind = FormParameterKind
97 // Required sets the required field and returns the receiver
98 func (p *Parameter) Required(required bool) *Parameter {
99 p.data.Required = required
103 // AllowMultiple sets the allowMultiple field and returns the receiver
104 func (p *Parameter) AllowMultiple(multiple bool) *Parameter {
105 p.data.AllowMultiple = multiple
109 // AllowableValues sets the allowableValues field and returns the receiver
110 func (p *Parameter) AllowableValues(values map[string]string) *Parameter {
111 p.data.AllowableValues = values
115 // DataType sets the dataType field and returns the receiver
116 func (p *Parameter) DataType(typeName string) *Parameter {
117 p.data.DataType = typeName
121 // DataFormat sets the dataFormat field for Swagger UI
122 func (p *Parameter) DataFormat(formatName string) *Parameter {
123 p.data.DataFormat = formatName
127 // DefaultValue sets the default value field and returns the receiver
128 func (p *Parameter) DefaultValue(stringRepresentation string) *Parameter {
129 p.data.DefaultValue = stringRepresentation
133 // Description sets the description value field and returns the receiver
134 func (p *Parameter) Description(doc string) *Parameter {
135 p.data.Description = doc
139 // CollectionFormat sets the collection format for an array type
140 func (p *Parameter) CollectionFormat(format CollectionFormat) *Parameter {
141 p.data.CollectionFormat = format.String()