diff --git a/docs/api_docs/bundle.yaml b/docs/api_docs/bundle.yaml index 7a41f455..4b337a33 100644 --- a/docs/api_docs/bundle.yaml +++ b/docs/api_docs/bundle.yaml @@ -4,7 +4,7 @@ info: Flagr is a feature flagging, A/B testing and dynamic configuration microservice title: Flagr - version: 1.0.0 + version: 1.0.7 tags: - name: flag description: Everything about the flag @@ -60,6 +60,13 @@ paths: name: description_like type: string description: return flags partially matching given description + - in: query + name: offset + type: integer + format: int64 + description: >- + return flags given the offset, it should usually set together with + limit responses: '200': description: list all the flags diff --git a/pkg/handler/crud.go b/pkg/handler/crud.go index 475cd2a2..b2662237 100644 --- a/pkg/handler/crud.go +++ b/pkg/handler/crud.go @@ -81,6 +81,9 @@ func (c *crud) FindFlags(params flag.FindFlagsParams) middleware.Responder { if params.Limit != nil { q = q.Limit(int(*params.Limit)) } + if params.Offset != nil { + q = q.Offset(int(*params.Offset)) + } err := q.All(&fs) if err != nil { diff --git a/swagger/flags.yaml b/swagger/flags.yaml index 55292abe..06a1ffd0 100644 --- a/swagger/flags.yaml +++ b/swagger/flags.yaml @@ -20,6 +20,11 @@ get: name: description_like type: string description: return flags partially matching given description + - in: query + name: offset + type: integer + format: int64 + description: return flags given the offset, it should usually set together with limit responses: 200: description: list all the flags diff --git a/swagger/index.yaml b/swagger/index.yaml index 68a56520..cd53c7e1 100644 --- a/swagger/index.yaml +++ b/swagger/index.yaml @@ -3,7 +3,7 @@ swagger: "2.0" info: description: Flagr is a feature flagging, A/B testing and dynamic configuration microservice title: Flagr - version: 1.0.0 + version: 1.0.7 tags: - name: flag description: Everything about the flag diff --git a/swagger_gen/restapi/doc.go b/swagger_gen/restapi/doc.go index b43f0867..a747c412 100644 --- a/swagger_gen/restapi/doc.go +++ b/swagger_gen/restapi/doc.go @@ -9,7 +9,7 @@ Flagr is a feature flagging, A/B testing and dynamic configuration microservice http Host: localhost BasePath: /api/v1 - Version: 1.0.0 + Version: 1.0.7 Consumes: - application/json diff --git a/swagger_gen/restapi/embedded_spec.go b/swagger_gen/restapi/embedded_spec.go index 7159220c..78ec4e6c 100644 --- a/swagger_gen/restapi/embedded_spec.go +++ b/swagger_gen/restapi/embedded_spec.go @@ -31,7 +31,7 @@ func init() { "info": { "description": "Flagr is a feature flagging, A/B testing and dynamic configuration microservice", "title": "Flagr", - "version": "1.0.0" + "version": "1.0.7" }, "basePath": "/api/v1", "paths": { @@ -132,6 +132,13 @@ func init() { "description": "return flags partially matching given description", "name": "description_like", "in": "query" + }, + { + "type": "integer", + "format": "int64", + "description": "return flags given the offset, it should usually set together with limit", + "name": "offset", + "in": "query" } ], "responses": { @@ -1634,7 +1641,7 @@ func init() { "info": { "description": "Flagr is a feature flagging, A/B testing and dynamic configuration microservice", "title": "Flagr", - "version": "1.0.0" + "version": "1.0.7" }, "basePath": "/api/v1", "paths": { @@ -1735,6 +1742,13 @@ func init() { "description": "return flags partially matching given description", "name": "description_like", "in": "query" + }, + { + "type": "integer", + "format": "int64", + "description": "return flags given the offset, it should usually set together with limit", + "name": "offset", + "in": "query" } ], "responses": { diff --git a/swagger_gen/restapi/operations/flag/find_flags_parameters.go b/swagger_gen/restapi/operations/flag/find_flags_parameters.go index c764fa37..164413d8 100644 --- a/swagger_gen/restapi/operations/flag/find_flags_parameters.go +++ b/swagger_gen/restapi/operations/flag/find_flags_parameters.go @@ -48,6 +48,10 @@ type FindFlagsParams struct { In: query */ Limit *int64 + /*return flags given the offset, it should usually set together with limit + In: query + */ + Offset *int64 } // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface @@ -81,6 +85,11 @@ func (o *FindFlagsParams) BindRequest(r *http.Request, route *middleware.Matched res = append(res, err) } + qOffset, qhkOffset, _ := qs.GetOK("offset") + if err := o.bindOffset(qOffset, qhkOffset, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -166,3 +175,25 @@ func (o *FindFlagsParams) bindLimit(rawData []string, hasKey bool, formats strfm return nil } + +// bindOffset binds and validates parameter Offset from query. +func (o *FindFlagsParams) bindOffset(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + return nil + } + + value, err := swag.ConvertInt64(raw) + if err != nil { + return errors.InvalidType("offset", "query", "int64", raw) + } + o.Offset = &value + + return nil +} diff --git a/swagger_gen/restapi/operations/flag/find_flags_urlbuilder.go b/swagger_gen/restapi/operations/flag/find_flags_urlbuilder.go index 2ac2216a..292428e6 100644 --- a/swagger_gen/restapi/operations/flag/find_flags_urlbuilder.go +++ b/swagger_gen/restapi/operations/flag/find_flags_urlbuilder.go @@ -19,6 +19,7 @@ type FindFlagsURL struct { DescriptionLike *string Enabled *bool Limit *int64 + Offset *int64 _basePath string // avoid unkeyed usage @@ -86,6 +87,14 @@ func (o *FindFlagsURL) Build() (*url.URL, error) { qs.Set("limit", limit) } + var offset string + if o.Offset != nil { + offset = swag.FormatInt64(*o.Offset) + } + if offset != "" { + qs.Set("offset", offset) + } + result.RawQuery = qs.Encode() return &result, nil