OpenAPIs using remote functions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
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: https://github.com/sveltejs/kit/issues/14612
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing how remote functions compile to endpoints and the fallback method handler described in the issue. Compare the proposal with the guard discussion in issue 14612. Done would require a decided approach for exposing remote functions as REST endpoints and generating and serving an openapi.json specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100