Skip to content

Commit

Permalink
(chore): Refactor Pagination IR to support offset (#3072)
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Feb 28, 2024
1 parent 83e7138 commit 04be316
Show file tree
Hide file tree
Showing 25 changed files with 401 additions and 121 deletions.
8 changes: 4 additions & 4 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
59 changes: 44 additions & 15 deletions fern.schema.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,23 +643,52 @@
"pagination": {
"anyOf": [
{
"type": "object",
"properties": {
"page": {
"type": "string",
"description": "The request property name that represents the page cursor or offset."
},
"next": {
"type": "string",
"description": "The response property name that represents the next page cursor or offset to retrieve."
"anyOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "cursor",
"description": "Configures cursor auto-pagination."
},
"page": {
"type": "string",
"description": "The request property name that represents the page cursor."
},
"next": {
"type": "string",
"description": "The response property name that represents the next page cursor to retrieve."
},
"results": {
"type": "string",
"description": "The response property name that represents the page elements."
}
},
"required": ["type", "page", "next", "results"],
"additionalProperties": false
},
"results": {
"type": "string",
"description": "The response property name that represents the page elements."
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "offset",
"description": "Configures offset auto-pagination."
},
"page": {
"type": "string",
"description": "The request property name that represents the page offset."
},
"results": {
"type": "string",
"description": "The response property name that represents the page elements."
}
},
"required": ["type", "page", "results"],
"additionalProperties": false
}
},
"required": ["page", "next", "results"],
"additionalProperties": false
]
},
{ "type": "boolean" }
]
Expand Down
86 changes: 78 additions & 8 deletions fern.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,28 @@
"headers": {
"type": "object",
"additionalProperties": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties"
"anyOf": [
{ "type": "string" },
{
"type": "object",
"properties": {
"type": { "type": "string" },
"docs": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs" },
"availability": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/availability"
},
"audiences": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/audiences"
},
"name": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/examples/items/properties/name"
},
"env": { "type": "string" }
},
"required": ["type"],
"additionalProperties": false
}
]
}
},
"endpoints": {
Expand Down Expand Up @@ -413,7 +434,7 @@
"headers": {
"type": "object",
"additionalProperties": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties"
"$ref": "#/properties/service/properties/headers/additionalProperties"
}
},
"body": {
Expand Down Expand Up @@ -618,6 +639,59 @@
},
"additionalProperties": false
}
},
"pagination": {
"anyOf": [
{
"anyOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "cursor",
"description": "Configures cursor auto-pagination."
},
"page": {
"type": "string",
"description": "The request property name that represents the page cursor."
},
"next": {
"type": "string",
"description": "The response property name that represents the next page cursor to retrieve."
},
"results": {
"type": "string",
"description": "The response property name that represents the page elements."
}
},
"required": ["type", "page", "next", "results"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "offset",
"description": "Configures offset auto-pagination."
},
"page": {
"type": "string",
"description": "The request property name that represents the page offset."
},
"results": {
"type": "string",
"description": "The response property name that represents the page elements."
}
},
"required": ["type", "page", "results"],
"additionalProperties": false
}
]
},
{ "type": "boolean" }
]
}
},
"required": ["path"],
Expand All @@ -642,9 +716,7 @@
"display-name": { "type": "string" },
"headers": {
"type": "object",
"additionalProperties": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties"
}
"additionalProperties": { "$ref": "#/properties/service/properties/headers/additionalProperties" }
},
"payload": {
"anyOf": [
Expand Down Expand Up @@ -716,9 +788,7 @@
"display-name": { "type": "string" },
"headers": {
"type": "object",
"additionalProperties": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties"
}
"additionalProperties": { "$ref": "#/properties/service/properties/headers/additionalProperties" }
},
"path-parameters": {
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/generation/ir-migrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@fern-fern/ir-v32-sdk": "0.0.1",
"@fern-fern/ir-v33-sdk": "0.0.15",
"@fern-fern/ir-v34-sdk": "0.0.8",
"@fern-fern/ir-v35-sdk": "0.0.15",
"@fern-fern/ir-v35-sdk": "0.0.17",
"@fern-fern/ir-v4-model": "0.0.4",
"@fern-fern/ir-v5-model": "0.0.3",
"@fern-fern/ir-v6-model": "0.0.33",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ service:
method: GET
path: /users
pagination:
type: cursor
page: $request.cursor
next: $response.nextPage
results: $response.users
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,28 @@ exports[`migrateFromV36ToV35 snapshot 1`] = `
"name": {
"name": {
"camelCase": {
"safeName": "cursor",
"unsafeName": "cursor",
"safeName": "pageNum",
"unsafeName": "pageNum",
},
"originalName": "cursor",
"originalName": "pageNum",
"pascalCase": {
"safeName": "Cursor",
"unsafeName": "Cursor",
"safeName": "PageNum",
"unsafeName": "PageNum",
},
"screamingSnakeCase": {
"safeName": "CURSOR",
"unsafeName": "CURSOR",
"safeName": "PAGE_NUM",
"unsafeName": "PAGE_NUM",
},
"snakeCase": {
"safeName": "cursor",
"unsafeName": "cursor",
"safeName": "page_num",
"unsafeName": "page_num",
},
},
"wireValue": "cursor",
"wireValue": "pageNum",
},
"valueType": {
"_visit": [Function],
"primitive": "STRING",
"primitive": "INTEGER",
"type": "primitive",
},
},
Expand Down Expand Up @@ -564,45 +564,6 @@ exports[`migrateFromV36ToV35 snapshot 1`] = `
"_visit": [Function],
"extends": [],
"properties": [
{
"availability": undefined,
"docs": undefined,
"name": {
"name": {
"camelCase": {
"safeName": "nextPage",
"unsafeName": "nextPage",
},
"originalName": "nextPage",
"pascalCase": {
"safeName": "NextPage",
"unsafeName": "NextPage",
},
"screamingSnakeCase": {
"safeName": "NEXT_PAGE",
"unsafeName": "NEXT_PAGE",
},
"snakeCase": {
"safeName": "next_page",
"unsafeName": "next_page",
},
},
"wireValue": "nextPage",
},
"valueType": {
"_visit": [Function],
"container": {
"_visit": [Function],
"optional": {
"_visit": [Function],
"primitive": "STRING",
"type": "primitive",
},
"type": "optional",
},
"type": "container",
},
},
{
"availability": undefined,
"docs": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ types:

ListUsersResponse:
properties:
nextPage: optional<string>
users: list<User>

service:
Expand All @@ -16,8 +15,8 @@ service:
method: GET
path: /users
pagination:
page: $request.cursor
next: $response.nextPage
type: offset
page: $request.pageNum
results: $response.users
request:
headers:
Expand All @@ -27,5 +26,5 @@ service:
env: MY_HEADER_ENV
name: ListUsersRequest
query-parameters:
cursor: string
response: ListUsersResponse
pageNum: integer
response: ListUsersResponse
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ export const FernOpenAPIExtension = {

/**
* Used to specify if an endpoint should be generated
* as a paginated endpoint.
* as a paginated endpoint. Both cursor and offset pagination
* examples are shown below.
*
* Example usage:
* paths:
* /path/to/my/endpoint:
* x-fern-pagination:
* type: "cursor"
* page: $request.page
* next: $response.next
* results: $response.results
Expand All @@ -80,8 +82,8 @@ export const FernOpenAPIExtension = {
*
* Example usage:
* x-fern-pagination:
* type: "offset"
* page: $request.page
* next: $response.next
* results: $response.results
*
* paths:
Expand Down
Loading

0 comments on commit 04be316

Please sign in to comment.