-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
Describe the problem
Remote functions are a blast to work with in SvelteKit. But of course, there is a whole world out there beyond SvelteKit. So often one would want to expose a REST API. OpenAPI is a well established standard, not only providing automated documentation solutions, but also automated SDK generation in many languages.
Describe the proposed solution
Since remote functions already compile to endpoints, I wondered if it may be feasible to support generating REST APIs like this:
// src/openapi.server.ts
import {
createFooCommand,
readFooQuery,
updateFooCommand,
deleteFooCommand
} from '$lib/remotes/foo.remote.ts';
import {
createBarCommand,
readBarQuery,
updateBarCommand,
deleteBarCommand
} from '$lib/remotes/bar.remote.ts';
export const spec = {
foo: {
POST: createFooCommand
.endpoint({
// additional options passed here
}),
GET: readFooCommand,
PUT: updateFooCommand
DELETE: deleteFooCommand
},
bar: {
// etc
}
}Alternatives considered
Currently, as far as I know, one can either:
- Manually write endpoint wrappers for remote functions and somehow generate and serve an
openapi.jsonfile - Use a fallback method handler to dynamically generate the full API and serve the
openapi.json
Importance
would make my life easier
Additional Information
I'm not exactly sure how this sort of proposal plays with guards such as proposed here: #14612
david-plugge, dennisregalado and lishaduck
Metadata
Metadata
Assignees
Labels
No labels