mirror of
https://github.com/harness/drone.git
synced 2025-05-21 03:20:15 +08:00
openapi update for the sapce membership list API
This commit is contained in:
parent
592a9aeb63
commit
416bd1ba36
@ -115,6 +115,36 @@ var queryParameterQuerySpace = openapi3.ParameterOrRef{
|
||||
},
|
||||
}
|
||||
|
||||
var queryParameterSpaceMembers = openapi3.ParameterOrRef{
|
||||
Parameter: &openapi3.Parameter{
|
||||
Name: request.QueryParamQuery,
|
||||
In: openapi3.ParameterInQuery,
|
||||
Description: ptr.String("The substring by which the space members are filtered."),
|
||||
Required: ptr.Bool(false),
|
||||
Schema: &openapi3.SchemaOrRef{
|
||||
Schema: &openapi3.Schema{
|
||||
Type: ptrSchemaType(openapi3.SchemaTypeString),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var queryParameterSortSpaceMembers = openapi3.ParameterOrRef{
|
||||
Parameter: &openapi3.Parameter{
|
||||
Name: request.QueryParamSort,
|
||||
In: openapi3.ParameterInQuery,
|
||||
Description: ptr.String("The field by which the space members are sorted."),
|
||||
Required: ptr.Bool(false),
|
||||
Schema: &openapi3.SchemaOrRef{
|
||||
Schema: &openapi3.Schema{
|
||||
Type: ptrSchemaType(openapi3.SchemaTypeString),
|
||||
Default: ptrptr(enum.MembershipSortName),
|
||||
Enum: enum.MembershipSort("").Enum(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
//nolint:funlen // api spec generation no need for checking func complexity
|
||||
func spaceOperations(reflector *openapi3.Reflector) {
|
||||
opCreate := openapi3.Operation{}
|
||||
@ -252,7 +282,7 @@ func spaceOperations(reflector *openapi3.Reflector) {
|
||||
spaceRequest
|
||||
space.MembershipAddInput
|
||||
}{}, http.MethodPost)
|
||||
_ = reflector.SetJSONResponse(&opMembershipAdd, &types.Membership{}, http.StatusCreated)
|
||||
_ = reflector.SetJSONResponse(&opMembershipAdd, &types.MembershipUser{}, http.StatusCreated)
|
||||
_ = reflector.SetJSONResponse(&opMembershipAdd, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&opMembershipAdd, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&opMembershipAdd, new(usererror.Error), http.StatusForbidden)
|
||||
@ -281,7 +311,7 @@ func spaceOperations(reflector *openapi3.Reflector) {
|
||||
UserUID string `path:"user_uid"`
|
||||
space.MembershipUpdateInput
|
||||
}{}, http.MethodPatch)
|
||||
_ = reflector.SetJSONResponse(&opMembershipUpdate, &types.Membership{}, http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opMembershipUpdate, &types.MembershipUser{}, http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opMembershipUpdate, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&opMembershipUpdate, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&opMembershipUpdate, new(usererror.Error), http.StatusForbidden)
|
||||
@ -291,10 +321,14 @@ func spaceOperations(reflector *openapi3.Reflector) {
|
||||
opMembershipList := openapi3.Operation{}
|
||||
opMembershipList.WithTags("space")
|
||||
opMembershipList.WithMapOfAnything(map[string]interface{}{"operationId": "membershipList"})
|
||||
opMembershipList.WithParameters(
|
||||
queryParameterSpaceMembers,
|
||||
queryParameterOrder, queryParameterSortSpaceMembers,
|
||||
queryParameterPage, queryParameterLimit)
|
||||
_ = reflector.SetRequest(&opMembershipList, &struct {
|
||||
spaceRequest
|
||||
}{}, http.MethodGet)
|
||||
_ = reflector.SetJSONResponse(&opMembershipList, []types.Membership{}, http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opMembershipList, []types.MembershipUser{}, http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opMembershipList, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&opMembershipList, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&opMembershipList, new(usererror.Error), http.StatusForbidden)
|
||||
|
@ -235,7 +235,6 @@ func (s *MembershipStore) ListUsers(ctx context.Context,
|
||||
stmt = stmt.OrderBy("principal_display_name " + order.String())
|
||||
case enum.MembershipSortCreated:
|
||||
stmt = stmt.OrderBy("membership_created " + order.String())
|
||||
case enum.MembershipSortNone:
|
||||
}
|
||||
|
||||
sql, args, err := stmt.ToSql()
|
||||
|
@ -9,15 +9,25 @@ import (
|
||||
)
|
||||
|
||||
// MembershipSort represents membership sort order.
|
||||
type MembershipSort int
|
||||
type MembershipSort string
|
||||
|
||||
// Order enumeration.
|
||||
const (
|
||||
MembershipSortNone MembershipSort = iota
|
||||
MembershipSortName
|
||||
MembershipSortCreated
|
||||
MembershipSortName = name
|
||||
MembershipSortCreated = created
|
||||
)
|
||||
|
||||
var membershipSorts = sortEnum([]MembershipSort{
|
||||
MembershipSortName,
|
||||
MembershipSortCreated,
|
||||
})
|
||||
|
||||
func (MembershipSort) Enum() []interface{} { return toInterfaceSlice(membershipSorts) }
|
||||
func (s MembershipSort) Sanitize() (MembershipSort, bool) { return Sanitize(s, GetAllMembershipSorts) }
|
||||
func GetAllMembershipSorts() ([]MembershipSort, MembershipSort) {
|
||||
return membershipSorts, MembershipSortName
|
||||
}
|
||||
|
||||
// ParseMembershipSort parses the membership sort attribute string
|
||||
// and returns the equivalent enumeration.
|
||||
func ParseMembershipSort(s string) MembershipSort {
|
||||
@ -27,19 +37,17 @@ func ParseMembershipSort(s string) MembershipSort {
|
||||
case created, createdAt:
|
||||
return MembershipSortCreated
|
||||
default:
|
||||
return MembershipSortNone
|
||||
return MembershipSortName
|
||||
}
|
||||
}
|
||||
|
||||
// String returns the string representation of the attribute.
|
||||
func (a MembershipSort) String() string {
|
||||
switch a {
|
||||
func (s MembershipSort) String() string {
|
||||
switch s {
|
||||
case MembershipSortName:
|
||||
return name
|
||||
case MembershipSortCreated:
|
||||
return created
|
||||
case MembershipSortNone:
|
||||
return ""
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user