Johannes Batzill 5337c46a4f Add Query and Sorting Capability to ListBranches API (#42)
This change adds the following to the list branches api:
- 'query' parameter for querying branches using arbitrary substrings
- 'sort' parameter for sorting the branches (name and date supported)
- 'direction' parameter for specifing the direction of the sorted output
2022-10-21 20:45:26 -07:00

106 lines
3.0 KiB
Go

// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
package openapi
import (
"github.com/gotidy/ptr"
"github.com/harness/gitness/internal/api/request"
"github.com/harness/gitness/types/enum"
"github.com/swaggest/openapi-go/openapi3"
)
func ptrSchemaType(t openapi3.SchemaType) *openapi3.SchemaType {
return &t
}
func ptrptr(i interface{}) *interface{} {
return &i
}
var queryParameterPage = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamPage,
In: openapi3.ParameterInQuery,
Description: ptr.String("The page to return."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
Default: ptrptr(1),
Minimum: ptr.Float64(1),
},
},
},
}
var queryParameterPerPage = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamPerPage,
In: openapi3.ParameterInQuery,
Description: ptr.String("The number of entries returned per page."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
Default: ptrptr(request.PerPageDefault),
Minimum: ptr.Float64(1.0),
Maximum: ptr.Float64(request.PerPageMax),
},
},
},
}
var queryParameterDirection = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamDirection,
In: openapi3.ParameterInQuery,
Description: ptr.String("The order of the output."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.OrderAsc.String()),
Enum: []interface{}{
ptr.String(enum.OrderAsc.String()),
ptr.String(enum.OrderDesc.String()),
},
},
},
},
}
var queryParameterSortBranch = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the branches are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.BranchSortOptionName.String()),
Enum: []interface{}{
ptr.String(enum.BranchSortOptionName.String()),
ptr.String(enum.BranchSortOptionDate.String()),
},
},
},
},
}
var queryParameterQueryBranch = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring by which the branches are filtered."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}