Skip to content

Commit

Permalink
Add getEntitlementById to public API & fix pagination bugs OM-857 (#1287
Browse files Browse the repository at this point in the history
)

* fix: fix 500 error when page is 0

* feat: add getEntitlementById operation

* feat: implement getEntitlementById endpoint and set pagination default values
  • Loading branch information
GAlexIHU authored Aug 2, 2024
1 parent 4ded17e commit 1654411
Show file tree
Hide file tree
Showing 19 changed files with 786 additions and 211 deletions.
238 changes: 141 additions & 97 deletions api/api.gen.go

Large diffs are not rendered by default.

337 changes: 240 additions & 97 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions api/client/node/clients/entitlement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,17 @@ export class EntitlementClient extends BaseClient {
options,
})
}

/**
* List all entitlements regardless of subject.
* @example
* const entitlement = await openmeter.entitlements.list()
*/
public async get(id: string, options?: RequestOptions): Promise<Entitlement> {
return await this.request({
path: `/api/v1/entitlements/${id}`,
method: 'GET',
options,
})
}
}
38 changes: 38 additions & 0 deletions api/client/node/schemas/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ export interface paths {
*/
get: operations['listEntitlements']
}
'/api/v1/entitlements/{entitlementId}': {
/**
* Get an entitlement
* @description Get entitlement by id.
*/
get: operations['getEntitlementById']
}
'/api/v1/features': {
/**
* List features
Expand Down Expand Up @@ -2259,6 +2266,37 @@ export interface operations {
default: components['responses']['UnexpectedProblemResponse']
}
}
/**
* Get an entitlement
* @description Get entitlement by id.
*/
getEntitlementById: {
parameters: {
path: {
entitlementId: components['parameters']['entitlementId']
}
}
responses: {
/** @description Entitlement found. */
200: {
content: {
'application/json': {
type: 'json'
} & Omit<components['schemas']['Entitlement'], 'type'> & {
/**
* Format: date-time
* @description The last time usage was reset.
* @example 2023-01-01T00:00:00Z
*/
lastReset?: string
}
}
}
401: components['responses']['UnauthorizedProblemResponse']
404: components['responses']['NotFoundProblemResponse']
default: components['responses']['UnexpectedProblemResponse']
}
}
/**
* List features
* @description List all features. If page is provided that takes precedence and the paginated response is returned.
Expand Down
83 changes: 83 additions & 0 deletions api/client/python/src/openmeter/_operations/_operations.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions api/client/python/src/openmeter/aio/_operations/_operations.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions api/client/web/src/client/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ export interface paths {
*/
get: operations['listEntitlements']
}
'/api/v1/entitlements/{entitlementId}': {
/**
* Get an entitlement
* @description Get entitlement by id.
*/
get: operations['getEntitlementById']
}
'/api/v1/features': {
/**
* List features
Expand Down Expand Up @@ -2259,6 +2266,37 @@ export interface operations {
default: components['responses']['UnexpectedProblemResponse']
}
}
/**
* Get an entitlement
* @description Get entitlement by id.
*/
getEntitlementById: {
parameters: {
path: {
entitlementId: components['parameters']['entitlementId']
}
}
responses: {
/** @description Entitlement found. */
200: {
content: {
'application/json': {
type: 'json'
} & Omit<components['schemas']['Entitlement'], 'type'> & {
/**
* Format: date-time
* @description The last time usage was reset.
* @example 2023-01-01T00:00:00Z
*/
lastReset?: string
}
}
}
401: components['responses']['UnauthorizedProblemResponse']
404: components['responses']['NotFoundProblemResponse']
default: components['responses']['UnexpectedProblemResponse']
}
}
/**
* List features
* @description List all features. If page is provided that takes precedence and the paginated response is returned.
Expand Down
32 changes: 32 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,38 @@ paths:
$ref: "#/components/responses/UnauthorizedProblemResponse"
default:
$ref: "#/components/responses/UnexpectedProblemResponse"
/api/v1/entitlements/{entitlementId}:
get:
operationId: getEntitlementById
summary: Get an entitlement
description: |
Get entitlement by id.
tags:
- Entitlements (Experimental)
parameters:
- $ref: "#/components/parameters/entitlementId"
responses:
"200":
description: Entitlement found.
content:
application/json:
schema:
allOf:
- $ref: "#/components/schemas/Entitlement"
- type: object
properties:
lastReset:
description: The last time usage was reset.
readOnly: true
type: string
format: date-time
example: "2023-01-01T00:00:00Z"
"401":
$ref: "#/components/responses/UnauthorizedProblemResponse"
"404":
$ref: "#/components/responses/NotFoundProblemResponse"
default:
$ref: "#/components/responses/UnexpectedProblemResponse"
# Feature
/api/v1/features:
get:
Expand Down
5 changes: 5 additions & 0 deletions internal/credit/grant_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ func (m *grantConnector) VoidGrant(ctx context.Context, grantID models.Namespace
}

func (m *grantConnector) ListGrants(ctx context.Context, params ListGrantsParams) (pagination.PagedResponse[Grant], error) {
if !params.Page.IsZero() {
if err := params.Page.Validate(); err != nil {
return pagination.PagedResponse[Grant]{}, err
}
}
return m.grantRepo.ListGrants(ctx, params)
}

Expand Down
Loading

0 comments on commit 1654411

Please sign in to comment.