Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ How the specification maps onto Go:
not JSON is returned as `[]byte`. The server copies a returned reader into
the response, and the JavaScript client returns such a body as a `Blob`, or
text as a string.
- **Paging** — an operation whose list is paged through by cursor also gets
`XPages`, which yields each page, and `XAll`, which yields every item, each
fetching the next page as the one before is used up, and stopping when the
loop breaks and at the first error, which it yields. Such a list is found
by its members: a list of items (`results`, `data`, `items`), the cursor of
the next page (`next_cursor`, `next_page_token`, ...) and, if there is one,
whether there is a next page (`has_more`), where there is none once the
cursor is zero; and by a cursor of the same type the operation takes, as a
query parameter or a member of the body (`start_cursor`, `cursor`,
`page_token`, ...). An operation's `x-pagination` names those an API calls
otherwise, by their JSON names (`cursor`, `next`, `more`, `items`), and fails
the run where they do not fit; `"x-pagination": false` leaves an operation
without iterators. The caller's parameters and body are copied, not changed.
- **Error responses** — an error body's type is returned wrapped in
`api.Error`, so it needs an `Error() string` method. The generator does not
write one, since a good message depends on the API: add it by hand beside the
Expand Down
13 changes: 13 additions & 0 deletions README/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ How the specification maps onto Go:
not JSON is returned as `[]byte`. The server copies a returned reader into
the response, and the JavaScript client returns such a body as a `Blob`, or
text as a string.
- **Paging** — an operation whose list is paged through by cursor also gets
`XPages`, which yields each page, and `XAll`, which yields every item, each
fetching the next page as the one before is used up, and stopping when the
loop breaks and at the first error, which it yields. Such a list is found
by its members: a list of items (`results`, `data`, `items`), the cursor of
the next page (`next_cursor`, `next_page_token`, ...) and, if there is one,
whether there is a next page (`has_more`), where there is none once the
cursor is zero; and by a cursor of the same type the operation takes, as a
query parameter or a member of the body (`start_cursor`, `cursor`,
`page_token`, ...). An operation's `x-pagination` names those an API calls
otherwise, by their JSON names (`cursor`, `next`, `more`, `items`), and fails
the run where they do not fit; `"x-pagination": false` leaves an operation
without iterators. The caller's parameters and body are copied, not changed.
- **Error responses** — an error body's type is returned wrapped in
`api.Error`, so it needs an `Error() string` method. The generator does not
write one, since a good message depends on the API: add it by hand beside the
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/MarkRosemaker/openapi-flatten v0.0.0-20261114135009-b46b792b06be
github.com/MarkRosemaker/ordmap v0.0.0-20261114134829-166766214acc
github.com/ettle/strcase v0.2.0
github.com/go-api-libs/api v0.0.0-20261113130130-277524695333
github.com/go-api-libs/api v0.0.0-20261115030148-02c29b673d3a
github.com/spf13/afero v1.15.0
mvdan.cc/gofumpt v0.12.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ github.com/MarkRosemaker/yaml2json v0.0.0-20261114134758-35f07119f480 h1:+NUgW7j
github.com/MarkRosemaker/yaml2json v0.0.0-20261114134758-35f07119f480/go.mod h1:DxNA9SDFrzw+RHsnxjIxjUzHy0I4+3hZg7R13u3SBvE=
github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q=
github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A=
github.com/go-api-libs/api v0.0.0-20261113130130-277524695333 h1:jHic3tOf6/vtJHZKB5niLbzXcXwl1kcIq1424Wc9xJc=
github.com/go-api-libs/api v0.0.0-20261113130130-277524695333/go.mod h1:nJuMPHY4qEhbWBvTdDFOPK+LC3Uo8RM9kPhIQfzXv4s=
github.com/go-api-libs/api v0.0.0-20261115030148-02c29b673d3a h1:Thu2LNeFzxiWHfVKhRmIu16/N7Rf6vUo5jghCroFc+k=
github.com/go-api-libs/api v0.0.0-20261115030148-02c29b673d3a/go.mod h1:rzjWUX+9lLTr+YF9mMw1rvNNDcnYpEHPGl7OA9qj9ZQ=
github.com/go-api-libs/types v0.0.0-20261114134757-0dc6e4300b30 h1:p1IOp1ya/fErQ3tUwXdprKG8vPRzmHVgiJsmRVRmbt0=
github.com/go-api-libs/types v0.0.0-20261114134757-0dc6e4300b30/go.mod h1:z0z6qkZc45AvoRnluq7PkVSlSSF25sT0diJ+vrubYfA=
github.com/go-quicktest/qt v1.102.0 h1:HSQxCeh5YZH3EL3W39ixjtyaEhcWSXQHtHnMBzSs474=
Expand Down
1 change: 1 addition & 0 deletions golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
_ "github.com/MarkRosemaker/cassette"
_ "github.com/go-api-libs/api"
_ "github.com/go-api-libs/api/apitest"
_ "github.com/go-api-libs/api/paging"
_ "github.com/go-api-libs/api/server"
_ "github.com/go-api-libs/api/union"
)
Expand Down
4 changes: 4 additions & 0 deletions ir/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func FromDocument(doc *openapi.Document, packageName, userAgent string, producti
return nil, fmt.Errorf("paths: %w", err)
}

if err := paginate(operations, schemas); err != nil {
return nil, fmt.Errorf("paths: %w", err)
}

hasURL, hasDuration, hasDate, hasDateTimeOrInt := needsSpecialImports(schemas, operations)

encodings, err := markEncodings(schemas)
Expand Down
5 changes: 5 additions & 0 deletions ir/ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ type Operation struct {
// StreamSuccess is true when the operation's success response is not text (see Response.IsStream), so
// SuccessReturn is io.ReadCloser and the method leaves the response body open for the caller.
StreamSuccess bool `json:"streamSuccess,omitzero"`
// Pagination is how the operation's list is paged through by cursor, if it is: the client then has an iterator
// of its pages and one of their items.
Pagination *Pagination `json:"pagination,omitempty"`

pagination paginationExt // what the operation's x-pagination says
}

func (op Operation) ParamsInStruct() Params {
Expand Down
6 changes: 6 additions & 0 deletions ir/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func FromOperation(
return nil, fmt.Errorf("responses: %w", err)
}

pagination, err := readPaginationExt(op.Extensions)
if err != nil {
return nil, err
}

return &Operation{
Name: name,
Description: op.Description,
Expand All @@ -125,6 +130,7 @@ func FromOperation(
RawBytesSuccess: rawBytesSuccess,
StreamSuccess: streamSuccess,
EmptySuccess: emptySuccess,
pagination: pagination,
}, nil
}

Expand Down
Loading
Loading