Replies: 2 comments
-
|
@spladug can you share your spec? When there are small changes like this, the answer I'm looking for is "how can I allow you to do them without writing your own plugin?" Can you show your |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Here's the extract function implementation: import { parseLinkHeader } from "@web3-storage/parse-link-header"
export type PaginationMetadata = {
next: string | null
prev: string | null
}
const extractPageParam = (url: string | undefined) => {
if (!url) return null
const urlObj = new URL(url)
return urlObj.searchParams.get("page")
}
export const extractPaginationMetadata = (response: { response: Response }): PaginationMetadata => {
const linkHeader = response.response.headers.get("link")
const links = parseLinkHeader(linkHeader)
return {
next: extractPageParam(links?.next?.url),
prev: extractPageParam(links?.prev?.url),
}
}The spec is here: https://api.wattcarbon.com/#tag/Devices/operation/Devices-list_devices / https://api.wattcarbon.com/openapi.json |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I love openapi-ts, thank you for the great tool.
I'm trying out using the pinia-colada plugin with my app but wanted to raise an edge case I've run into. Our app uses
Linkheaders for pagination, much like the GitHub API does. Since the pagination metadata isn't in the JSON response payload, there needs to be a little extra processing before returning from the query function. I had something like this in my code:That is, it's nearly a copy-paste of the generated query definition but with a transform for mapping the response object to the query result. (Plus the
placeholderDatathing recommended by pinia colada for pagination, but that's less important).I see a few paths forward:
x-paginatedfield for the relevant endpoints so this is something that can be automatedI was wondering what you'd recommend doing here?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions