Skip to content

Commit

Permalink
added openapi spec gen
Browse files Browse the repository at this point in the history
  • Loading branch information
koljagralla committed Jan 26, 2024
1 parent 09dc88c commit 5455dc8
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/stacks/my-stack/index.ts
Expand Up @@ -10,6 +10,7 @@ export class MyStack extends cdk.Stack {
const itemsTable = createItemsDynamoDB(this);

const myApiTurbogate = new MyApiTurbogate(this, {
openapi: {},
environment: {
ITEMS_TABLE_NAME: itemsTable.tableName,
VALID_API_KEYS: 'my-api-key,another-api-key',
Expand Down
8 changes: 7 additions & 1 deletion lib/stacks/my-stack/my-api-turbogate/docs.ts
Expand Up @@ -9,7 +9,13 @@ import { ApiDocs } from 'turbogate';

export const docs: ApiDocs = {
info: {
title: 'MY API',
title: 'Turbogate Example API',
version: '0.0.0',
},
servers: [
{
url: 'https://urapiid.execute-api.eu-central-1.amazonaws.com/prod', // <-- Change this to your API gateway base to use the API spec to make requests against your API.
description: 'Development server',
},
],
};
132 changes: 132 additions & 0 deletions lib/stacks/my-stack/my-api-turbogate/openapi.yaml
@@ -0,0 +1,132 @@
info:
title: Turbogate Example API
version: 0.0.0
servers:
- url: https://urapiid.execute-api.eu-central-1.amazonaws.com/prod
description: Development server
openapi: 3.1.0
components:
securitySchemes:
apiKey:
type: apiKey
in: header
name: Authorization
schemas:
Item:
type: object
properties:
id:
type: string
format: uuid
description: The ID of the item. Generated by the backend upon creation.
name:
type: string
minLength: 5
maxLength: 20
description: >-
The name of the item. Does not have to be unique and can be changed
at any given time.
example: Excellent Item
description:
type: string
description: The description of the item. Can be changed at any given time.
example: This item is of exceptional excellence.
required:
- id
- name
additionalProperties: false
description: An item.
ZodValidationError:
type: object
properties:
validationErrors:
type: array
items:
type: object
properties:
code:
type: string
enum:
- invalid_type
- invalid_literal
- custom
- invalid_union
- invalid_union_discriminator
- invalid_enum_value
- unrecognized_keys
- invalid_arguments
- invalid_return_type
- invalid_date
- invalid_string
- too_small
- too_big
- invalid_intersection_types
- not_multiple_of
- not_finite
message:
type: string
path:
type: array
items:
type: string
required:
- code
- message
- path
description: A list of Zod validation errors.
required:
- validationErrors
parameters: {}
paths:
/items:
post:
summary: Creates a new item
description: >-
Creates a new item in the database. The ID of the item is generated by
the backend. Upon success the whole item including the ID is returned.
security:
- apiKey: []
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
minLength: 5
maxLength: 20
description: >-
The name of the item. Does not have to be unique and can be
changed at any given time.
example: Excellent Item
description:
type: string
description: >-
The description of the item. Can be changed at any given
time.
example: This item is of exceptional excellence.
required:
- name
additionalProperties: false
responses:
'201':
description: >-
The item was created successfully. The whole created item is
returned.
content:
application/json:
schema:
$ref: '#/components/schemas/Item'
'400':
description: The validation of the request failed.
content:
application/json:
schema:
$ref: '#/components/schemas/ZodValidationError'
'500':
description: Internal server error.
content:
application/json:
schema: {}
webhooks: {}

0 comments on commit 5455dc8

Please sign in to comment.