|
| 1 | +openapi: 3.0.3 |
| 2 | +info: |
| 3 | + title: Sample CAMARA Service API |
| 4 | + description: | |
| 5 | + Template for a request-response CAMARA API. |
| 6 | +
|
| 7 | + Copy this file to your API repository's `code/API_definitions/` directory |
| 8 | + and adapt it to your API's resources and operations. |
| 9 | +
|
| 10 | + This template demonstrates: |
| 11 | + - `$ref` to `../common/CAMARA_common.yaml` for shared schemas, error responses, |
| 12 | + parameters, headers, and security schemes |
| 13 | + - Two options for error responses: |
| 14 | + - Option A: Pure `$ref` for responses using only generic error codes |
| 15 | + - Option B: Local response definition extending generic errors with API-specific codes |
| 16 | + license: |
| 17 | + name: Apache 2.0 |
| 18 | + url: https://www.apache.org/licenses/LICENSE-2.0.html |
| 19 | + version: wip |
| 20 | + x-camara-commonalities: 0.7.0 |
| 21 | +servers: |
| 22 | + - url: "{apiRoot}/sample-service/vwip" |
| 23 | + variables: |
| 24 | + apiRoot: |
| 25 | + default: http://localhost:9091 |
| 26 | + description: API root, Apache 2.0 licensed |
| 27 | +tags: |
| 28 | + - name: Resources |
| 29 | + description: Operations on sample resources |
| 30 | +security: |
| 31 | + - openId: |
| 32 | + - sample-service:resource:read |
| 33 | + - sample-service:resource:write |
| 34 | +paths: |
| 35 | + /resources: |
| 36 | + post: |
| 37 | + tags: |
| 38 | + - Resources |
| 39 | + summary: Create a resource |
| 40 | + description: Creates a new resource with the provided properties. |
| 41 | + operationId: createResource |
| 42 | + parameters: |
| 43 | + - $ref: "../common/CAMARA_common.yaml#/components/parameters/x-correlator" |
| 44 | + requestBody: |
| 45 | + required: true |
| 46 | + content: |
| 47 | + application/json: |
| 48 | + schema: |
| 49 | + $ref: "#/components/schemas/CreateResource" |
| 50 | + responses: |
| 51 | + "201": |
| 52 | + description: Resource created |
| 53 | + headers: |
| 54 | + x-correlator: |
| 55 | + $ref: "../common/CAMARA_common.yaml#/components/headers/x-correlator" |
| 56 | + content: |
| 57 | + application/json: |
| 58 | + schema: |
| 59 | + $ref: "#/components/schemas/Resource" |
| 60 | + "400": |
| 61 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic400" |
| 62 | + "401": |
| 63 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic401" |
| 64 | + "403": |
| 65 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic403" |
| 66 | + "409": |
| 67 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic409" |
| 68 | + "422": |
| 69 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic422" |
| 70 | + "429": |
| 71 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic429" |
| 72 | + "500": |
| 73 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic500" |
| 74 | + get: |
| 75 | + tags: |
| 76 | + - Resources |
| 77 | + summary: List resources |
| 78 | + description: Returns a list of all resources accessible to the API consumer. |
| 79 | + operationId: listResources |
| 80 | + parameters: |
| 81 | + - $ref: "../common/CAMARA_common.yaml#/components/parameters/x-correlator" |
| 82 | + responses: |
| 83 | + "200": |
| 84 | + description: List of resources |
| 85 | + headers: |
| 86 | + x-correlator: |
| 87 | + $ref: "../common/CAMARA_common.yaml#/components/headers/x-correlator" |
| 88 | + content: |
| 89 | + application/json: |
| 90 | + schema: |
| 91 | + type: array |
| 92 | + items: |
| 93 | + $ref: "#/components/schemas/Resource" |
| 94 | + "401": |
| 95 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic401" |
| 96 | + "403": |
| 97 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic403" |
| 98 | + "500": |
| 99 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic500" |
| 100 | + /resources/{resourceId}: |
| 101 | + get: |
| 102 | + tags: |
| 103 | + - Resources |
| 104 | + summary: Get a resource by ID |
| 105 | + description: Returns the details of a specific resource identified by its ID. |
| 106 | + operationId: getResource |
| 107 | + parameters: |
| 108 | + - $ref: "#/components/parameters/ResourceId" |
| 109 | + - $ref: "../common/CAMARA_common.yaml#/components/parameters/x-correlator" |
| 110 | + responses: |
| 111 | + "200": |
| 112 | + description: Resource details |
| 113 | + headers: |
| 114 | + x-correlator: |
| 115 | + $ref: "../common/CAMARA_common.yaml#/components/headers/x-correlator" |
| 116 | + content: |
| 117 | + application/json: |
| 118 | + schema: |
| 119 | + $ref: "#/components/schemas/Resource" |
| 120 | + "401": |
| 121 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic401" |
| 122 | + "403": |
| 123 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic403" |
| 124 | + # Option A — pure $ref for responses using only generic error codes |
| 125 | + "404": |
| 126 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic404" |
| 127 | + "500": |
| 128 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic500" |
| 129 | + delete: |
| 130 | + tags: |
| 131 | + - Resources |
| 132 | + summary: Delete a resource |
| 133 | + description: Deletes a specific resource identified by its ID. |
| 134 | + operationId: deleteResource |
| 135 | + parameters: |
| 136 | + - $ref: "#/components/parameters/ResourceId" |
| 137 | + - $ref: "../common/CAMARA_common.yaml#/components/parameters/x-correlator" |
| 138 | + responses: |
| 139 | + "204": |
| 140 | + description: Resource deleted |
| 141 | + headers: |
| 142 | + x-correlator: |
| 143 | + $ref: "../common/CAMARA_common.yaml#/components/headers/x-correlator" |
| 144 | + "401": |
| 145 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic401" |
| 146 | + "403": |
| 147 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic403" |
| 148 | + # Option B — local response extending generic errors with API-specific codes |
| 149 | + "404": |
| 150 | + $ref: "#/components/responses/ResourceNotFound404" |
| 151 | + "500": |
| 152 | + $ref: "../common/CAMARA_common.yaml#/components/responses/Generic500" |
| 153 | +components: |
| 154 | + securitySchemes: |
| 155 | + openId: |
| 156 | + $ref: "../common/CAMARA_common.yaml#/components/securitySchemes/openId" |
| 157 | + responses: |
| 158 | + # Option B example: API-specific error response extending generic error codes. |
| 159 | + # Use this pattern when an operation needs API-specific error codes in addition |
| 160 | + # to the generic ones defined in CAMARA_common.yaml. |
| 161 | + ResourceNotFound404: |
| 162 | + description: Resource not found |
| 163 | + headers: |
| 164 | + x-correlator: |
| 165 | + $ref: "../common/CAMARA_common.yaml#/components/headers/x-correlator" |
| 166 | + content: |
| 167 | + application/json: |
| 168 | + schema: |
| 169 | + allOf: |
| 170 | + - $ref: "../common/CAMARA_common.yaml#/components/schemas/ErrorInfo" |
| 171 | + - type: object |
| 172 | + properties: |
| 173 | + status: |
| 174 | + enum: |
| 175 | + - 404 |
| 176 | + code: |
| 177 | + enum: |
| 178 | + - NOT_FOUND |
| 179 | + - IDENTIFIER_NOT_FOUND |
| 180 | + examples: |
| 181 | + GENERIC_404_NOT_FOUND: |
| 182 | + description: The specified resource was not found |
| 183 | + value: |
| 184 | + status: 404 |
| 185 | + code: NOT_FOUND |
| 186 | + message: The specified resource is not found. |
| 187 | + RESOURCE_404_IDENTIFIER_NOT_FOUND: |
| 188 | + description: API-specific — some identifier cannot be matched to a resource |
| 189 | + value: |
| 190 | + status: 404 |
| 191 | + code: IDENTIFIER_NOT_FOUND |
| 192 | + message: Some of the provided identifiers are not found. |
| 193 | + parameters: |
| 194 | + ResourceId: |
| 195 | + name: resourceId |
| 196 | + in: path |
| 197 | + required: true |
| 198 | + description: Identifier of the resource to operate on |
| 199 | + schema: |
| 200 | + $ref: "#/components/schemas/ResourceId" |
| 201 | + schemas: |
| 202 | + ResourceId: |
| 203 | + type: string |
| 204 | + format: uuid |
| 205 | + description: Unique identifier for the resource |
| 206 | + CreateResource: |
| 207 | + description: Properties for creating a new resource |
| 208 | + type: object |
| 209 | + required: |
| 210 | + - name |
| 211 | + properties: |
| 212 | + name: |
| 213 | + type: string |
| 214 | + maxLength: 128 |
| 215 | + description: Human-readable name for the resource |
| 216 | + device: |
| 217 | + $ref: "../common/CAMARA_common.yaml#/components/schemas/Device" |
| 218 | + Resource: |
| 219 | + description: A resource managed by the API |
| 220 | + type: object |
| 221 | + required: |
| 222 | + - resourceId |
| 223 | + - name |
| 224 | + properties: |
| 225 | + resourceId: |
| 226 | + $ref: "#/components/schemas/ResourceId" |
| 227 | + name: |
| 228 | + type: string |
| 229 | + maxLength: 128 |
| 230 | + description: Human-readable name for the resource |
| 231 | + device: |
| 232 | + $ref: "../common/CAMARA_common.yaml#/components/schemas/Device" |
0 commit comments