File size: 3,372 Bytes
1477a90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi";
import "@typespec/openapi3";
import "../common/error.tsp";
import "../shared/index.tsp";
import "../meters/query.tsp";
import "./cost.tsp";
import "./feature.tsp";

using TypeSpec.Http;
using TypeSpec.OpenAPI;

namespace Features;

/**
 * Filter options for listing features.
 */
@friendlyName("ListFeatureParamsFilter")
model ListFeaturesParamsFilter {
  #suppress "@openmeter/api-spec-aip/doc-decorator" "shared model"
  meter_id?: Common.ULIDFieldFilter;
  #suppress "@openmeter/api-spec-aip/doc-decorator" "shared model"
  key?: Common.StringFieldFilter;
  #suppress "@openmeter/api-spec-aip/doc-decorator" "shared model"
  name?: Common.StringFieldFilter;
}

interface FeatureOperations {
  /**
   * List all features.
   */
  @get
  @operationId("list-features")
  @summary("List features")
  @extension(Shared.UnstableExtension, true)
  list(
    ...Common.PagePaginationQuery,

    /**
     * Sort features returned in the response. Supported sort attributes are:
     *
     * - `key`
     * - `name`
     * - `created_at` (default)
     * - `updated_at`
     *
     * The `asc` suffix is optional as the default sort order is ascending. The `desc`
     * suffix is used to specify a descending order.
     */
    @query(#{ name: "sort" })
    sort?: Common.SortQuery,

    /**
     * Filter features returned in the response.
     *
     * To filter features by meter_id add the following query param:
     * filter[meter_id][oeq]=<id>
     */
    @query(#{ style: "deepObject", explode: true })
    filter?: ListFeaturesParamsFilter,
  ): Shared.PagePaginatedResponse<Feature> | Common.ErrorResponses;

  /**
   * Create a feature.
   */
  @post
  @operationId("create-feature")
  @summary("Create feature")
  @extension(Shared.UnstableExtension, true)
  create(
    @body
    feature: Shared.CreateRequest<Feature>,
  ): Shared.CreateResponse<Feature> | Common.ErrorResponses;

  /**
   * Get a feature by id.
   */
  @get
  @route("/{featureId}")
  @operationId("get-feature")
  @summary("Get feature")
  @extension(Shared.UnstableExtension, true)
  get(@path featureId: Shared.ULID):
    | Shared.GetResponse<Feature>
    | Common.ErrorResponses
    | Common.Gone
    | Common.NotFound;

  /**
   * Update a feature by id. Currently only the unit_cost field can be updated.
   */
  @patch
  @route("/{featureId}")
  @operationId("update-feature")
  @summary("Update feature")
  @extension(Shared.UnstableExtension, true)
  update(@path featureId: Shared.ULID, @body feature: FeatureUpdateRequest):
    | Shared.UpdateResponse<Feature>
    | Common.ErrorResponses
    | Common.NotFound;

  /**
   * Delete a feature by id.
   */
  @delete
  @route("/{featureId}")
  @operationId("delete-feature")
  @summary("Delete feature")
  @extension(Shared.UnstableExtension, true)
  delete(@path featureId: Shared.ULID):
    | Shared.DeleteResponse
    | Common.ErrorResponses
    | Common.NotFound;
}

interface FeatureCostOperations {
  /**
   * Query the cost of a feature.
   */
  @extension(Shared.UnstableExtension, true)
  @post
  @route("/query")
  @operationId("query-feature-cost")
  @summary("Query feature cost")
  queryCost(
    @path featureId: Shared.ULID,
    @body request?: Meters.MeterQueryRequest,
  ): FeatureCostQueryResult | Common.NotFound | Common.ErrorResponses;
}