Skip to content

Commit

Permalink
1.1.0: support fastify 4.x
Browse files Browse the repository at this point in the history
- upgrade dependencies to fastify 4.x / @fastify modules
- make register() async as fastify 4.x requires
  • Loading branch information
elierotenberg committed Aug 1, 2022
1 parent 81eb01c commit 19698f0
Show file tree
Hide file tree
Showing 14 changed files with 2,837 additions and 3,280 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ declare module "fastify" {

// Local augmentation
// See below for register()
const f = register(fastify(), { jsonSchemas });
const f = await register(fastify(), { jsonSchemas });
```

- Register `fastify-zod` with optional config for `fastify-swagger`
Expand All @@ -89,7 +89,7 @@ import { buildJsonSchemas, register } from "fastify-zod";

const f = fastify();

register(f, {
await register(f, {
jsonSchemas: buildJsonSchemas(models),
// optional, see below
swagger: {
Expand Down Expand Up @@ -222,7 +222,7 @@ Any options will be passed directly to `fastify-swagger` so you may refer to [th
In addition to `fastify-swagger` options, you can pass an additional property, `transformSpec`, to expose a transformed version of the original spec (see below).

```ts
register(f, {
await register(f, {
jsonSchemas: buildJsonSchemas(models),
swaggerOptions: {
routePrefix: `/swagger`,
Expand Down Expand Up @@ -586,7 +586,7 @@ For this you need to first generate the spec file, then run `openapitools-genera
```ts
const jsonSchemas = buildJsonSchemas(models);

register(f, {
await register(f, {
jsonSchemas,
swaggerOptions: {
openapi: {
Expand Down
18 changes: 6 additions & 12 deletions openapi.original.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid"
"$ref": "#/components/schemas/Schema/properties/TodoItemId/properties/id"
},
"label": {
"type": "string"
Expand All @@ -46,12 +45,7 @@
"minimum": 0
},
"state": {
"type": "string",
"enum": [
"todo",
"in progress",
"done"
]
"$ref": "#/components/schemas/Schema/properties/TodoState"
}
},
"required": [
Expand Down Expand Up @@ -216,13 +210,13 @@
},
"parameters": [
{
"in": "path",
"name": "id",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
},
"in": "path",
"name": "id",
"required": true
}
],
"responses": {
Expand Down
30 changes: 15 additions & 15 deletions openapi.transformed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
},
"components": {
"schemas": {
"Schema_TodoState": {
"type": "string",
"enum": [
"todo",
"in progress",
"done"
]
},
"Schema_TodoItem": {
"type": "object",
"properties": {
"id": {
"$ref": "#/components/schemas/Schema_TodoItem_id"
"$ref": "#/components/schemas/Schema_TodoItemId_id"
},
"label": {
"$ref": "#/components/schemas/Schema_TodoItem_label"
Expand All @@ -20,7 +28,7 @@
"$ref": "#/components/schemas/Schema_TodoItem_dueDateMs"
},
"state": {
"$ref": "#/components/schemas/Schema_TodoItem_state"
"$ref": "#/components/schemas/Schema_TodoState"
}
},
"required": [
Expand Down Expand Up @@ -68,7 +76,7 @@
42
]
},
"Schema_TodoItem_id": {
"Schema_TodoItemId_id": {
"type": "string",
"format": "uuid"
},
Expand All @@ -79,14 +87,6 @@
"type": "integer",
"minimum": 0
},
"Schema_TodoItem_state": {
"type": "string",
"enum": [
"todo",
"in progress",
"done"
]
},
"Schema_TodoItems_todoItems": {
"type": "array",
"items": {
Expand Down Expand Up @@ -205,13 +205,13 @@
},
"parameters": [
{
"in": "path",
"name": "id",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
},
"in": "path",
"name": "id",
"required": true
}
],
"responses": {
Expand Down
26 changes: 13 additions & 13 deletions openapi.transformed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ info:
version: 0.0.0
components:
schemas:
Schema_TodoState:
type: string
enum:
- todo
- in progress
- done
Schema_TodoItem:
type: object
properties:
id:
$ref: '#/components/schemas/Schema_TodoItem_id'
$ref: '#/components/schemas/Schema_TodoItemId_id'
label:
$ref: '#/components/schemas/Schema_TodoItem_label'
dueDateMs:
$ref: '#/components/schemas/Schema_TodoItem_dueDateMs'
state:
$ref: '#/components/schemas/Schema_TodoItem_state'
$ref: '#/components/schemas/Schema_TodoState'
required:
- id
- label
Expand Down Expand Up @@ -47,20 +53,14 @@ components:
type: number
enum:
- 42
Schema_TodoItem_id:
Schema_TodoItemId_id:
type: string
format: uuid
Schema_TodoItem_label:
type: string
Schema_TodoItem_dueDateMs:
type: integer
minimum: 0
Schema_TodoItem_state:
type: string
enum:
- todo
- in progress
- done
Schema_TodoItems_todoItems:
type: array
items:
Expand Down Expand Up @@ -132,12 +132,12 @@ paths:
schema:
$ref: '#/components/schemas/Schema_TodoItem'
parameters:
- in: path
name: id
required: true
schema:
- schema:
type: string
format: uuid
in: path
name: id
required: true
responses:
'200':
description: Default Response
Expand Down
Loading

0 comments on commit 19698f0

Please sign in to comment.