-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change breaks the API by changing the previous logic used for both input/output validation and the OpenAPI generation so that only a simple default specification is generated from the newly introfuced `input` and `output` logic, whereas the user can override these with the `openApiSpec` object that can now be used on three levels, similarly to the middlewares and error handlers. This change also contains miscellaneous refactorings for the project structure due to the increasing amount of utility functions etc.
- Loading branch information
Showing
49 changed files
with
3,151 additions
and
5,245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
node_modules | ||
coverage | ||
dist | ||
tsconfig.tsbuildinfo | ||
.next | ||
next-env.d.ts | ||
build | ||
.docusaurus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,108 @@ | ||
import sampleData from 'sample-data.json'; | ||
import * as z from 'zod'; | ||
import * as yup from 'yup'; | ||
import { defineEndpoints } from 'next-rest-framework/client'; | ||
import { z } from 'zod'; | ||
import * as yup from 'yup'; | ||
|
||
export default defineEndpoints({ | ||
middleware: ({ params: { foo, bar, baz } }) => ({ | ||
foo: bar, | ||
bar: baz, | ||
baz: foo, | ||
asd: 'asd' | ||
baz: foo | ||
}), | ||
GET: { | ||
middleware: () => ({ | ||
qux: 'qux' | ||
}), | ||
responses: [ | ||
output: [ | ||
{ | ||
status: 200, | ||
contentType: 'text/html', | ||
schema: z.object({ | ||
data: z.array( | ||
z.object({ | ||
userId: z.number(), | ||
id: z.number(), | ||
title: z.string(), | ||
completed: z.boolean() | ||
}) | ||
) | ||
foo: z.string(), | ||
bar: z.string(), | ||
baz: z.string(), | ||
qux: z.string() | ||
}) | ||
} | ||
], | ||
handler: async ({ res, params: { foo, bar, baz, qux } }) => { | ||
console.log({ foo, bar, baz, qux }); | ||
res.setHeader('content-type', 'text/html'); | ||
res.status(200).json({ data: sampleData }); | ||
res.status(200).json({ foo, bar, baz, qux }); | ||
} | ||
}, | ||
POST: { | ||
tags: ['Todo'], | ||
description: 'Create a new todo', | ||
externalDocs: { | ||
description: 'Find out more about Swagger', | ||
url: 'http://swagger.io' | ||
input: { | ||
contentType: 'application/json', | ||
schema: z.object({ | ||
foo: z.string(), | ||
bar: z.number() | ||
}) | ||
}, | ||
operationId: 'createTodo', | ||
parameters: [ | ||
output: [ | ||
{ | ||
name: 'todo', | ||
in: 'body', | ||
description: 'The todo to create', | ||
required: true, | ||
deprecated: false, | ||
allowEmptyValue: false | ||
} | ||
], | ||
deprecated: false, | ||
security: [ | ||
{ | ||
foo: ['bar'] | ||
} | ||
], | ||
servers: [ | ||
{ | ||
url: 'http://localhost:3000', | ||
description: 'Development server', | ||
variables: {} | ||
status: 201, | ||
contentType: 'application/json', | ||
schema: z.object({ | ||
foo: z.string(), | ||
bar: z.number(), | ||
qux: z.array( | ||
z.object({ | ||
qux: z.string() | ||
}) | ||
) | ||
}) | ||
} | ||
], | ||
requestBody: { | ||
description: 'The todo to create', | ||
middleware: () => ({ | ||
qux: 'qux' | ||
}), | ||
handler: async ({ | ||
req: { | ||
body: { foo, bar } | ||
}, | ||
res, | ||
params: { qux } | ||
}) => { | ||
res.status(201).json({ foo, bar, qux: [{ qux }] }); | ||
} | ||
}, | ||
PUT: { | ||
input: { | ||
contentType: 'application/json', | ||
schema: yup.object({ | ||
foo: yup.string(), | ||
bar: yup.number() | ||
}), | ||
example: { | ||
foo: 'Buy milk', | ||
bar: 1 | ||
}, | ||
examples: {}, | ||
encoding: {}, | ||
required: true | ||
foo: yup.array( | ||
yup.object({ | ||
bar: yup.string() | ||
}) | ||
), | ||
baz: yup.number() | ||
}) | ||
}, | ||
responses: [ | ||
output: [ | ||
{ | ||
status: 201, | ||
contentType: 'application/json', | ||
schema: z.object({ | ||
data: z.array( | ||
z.object({ | ||
userId: z.number(), | ||
id: z.number(), | ||
title: z.string(), | ||
completed: z.boolean() | ||
schema: yup.object({ | ||
foo: yup.array( | ||
yup.object({ | ||
bar: yup.string() | ||
}) | ||
) | ||
), | ||
bar: yup.number(), | ||
qux: yup.string() | ||
}) | ||
} | ||
], | ||
middleware: () => ({ | ||
qux: 'qux' | ||
}), | ||
handler: async ({ res }) => { | ||
res.status(201).json({ data: sampleData }); | ||
handler: async ({ | ||
req: { | ||
body: { foo } | ||
}, | ||
res, | ||
params: { qux } | ||
}) => { | ||
res.status(201).json({ foo, bar: 0, qux }); | ||
} | ||
} | ||
}); |
Oops, something went wrong.
ca08104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-rest-framework – ./
next-rest-framework-git-main-blomqma.vercel.app
next-rest-framework-blomqma.vercel.app
next-rest-framework.vercel.app