Skip to content

Commit 11d9eb3

Browse files
amaskara-ddclaude
andcommitted
Support pageStart in x-pagination extension
Add support for the pageStart field in the x-pagination OpenAPI extension to allow APIs that use 1-based page numbering (like Case Management) to work correctly with pagination helpers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 42f3f95 commit 11d9eb3

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

.generator/src/generator/templates/Api.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public class {{ name }} {
148148
String valueGetterPath = "";
149149
String valueSetterPath = "{%- if getters|length > 1 %}{{ ".".join(getters[:getters|length-1]) }}.{%- endif %}{{ setters[getters|length-1] }}";
150150
Boolean valueSetterParamOptional = {{ optional|lower }};
151-
parameters.{% if getters|length > 1 %}{{ ".".join(getters[:getters|length-1]) }}.{%- endif %}{{ setters[getters|length-1] }}({{ 0|format_value(schema=paramSchema['schema']) }});
151+
parameters.{% if getters|length > 1 %}{{ ".".join(getters[:getters|length-1]) }}.{%- endif %}{{ setters[getters|length-1] }}({{ (pagination.pageStart | default(0))|format_value(schema=paramSchema['schema']) }});
152152
{%- endif %}
153153

154154
{#- Limit param field #}
@@ -205,7 +205,7 @@ public class {{ name }} {
205205
args.put("optionalParams", parameters);
206206
{%- endif %}
207207

208-
PaginationIterable iterator = new PaginationIterable(this, "{{ operationId }}", resultsPath, valueGetterPath, valueSetterPath, valueSetterParamOptional, {% if pagination.pageParam %}false{% else %}true{% endif %}, limit, args);
208+
PaginationIterable iterator = new PaginationIterable(this, "{{ operationId }}", resultsPath, valueGetterPath, valueSetterPath, valueSetterParamOptional, {% if pagination.pageParam %}false{% else %}true{% endif %}, limit, args, {{ pagination.pageStart | default(0) }});
209209

210210
return iterator;
211211
{%- endmacro %}

.generator/src/generator/templates/PaginationIterable.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class PaginationIterable<T> implements Iterable<T> {
1414
Boolean offsetPageIncrement;
1515
Object limit;
1616
LinkedHashMap<String, Object> args;
17+
int pageStart;
1718

1819
public PaginationIterable(
1920
Object requestClass,
@@ -24,7 +25,8 @@ public class PaginationIterable<T> implements Iterable<T> {
2425
Boolean valueSetterParamOptional,
2526
Boolean offsetPageIncrement,
2627
Object limit,
27-
LinkedHashMap<String, Object> args) {
28+
LinkedHashMap<String, Object> args,
29+
int pageStart) {
2830

2931
this.requestClass = requestClass;
3032
this.requestName = requestName;
@@ -41,6 +43,7 @@ public class PaginationIterable<T> implements Iterable<T> {
4143
this.offsetPageIncrement = offsetPageIncrement;
4244
this.limit = limit;
4345
this.args = args;
46+
this.pageStart = pageStart;
4447
}
4548

4649
@Override

.generator/src/generator/templates/PaginationIterator.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ public class PaginationIterator<T> implements Iterator<T> {
8080
value = value.getClass().getMethod(path).invoke(value);
8181
}
8282
} else {
83-
// fallback to pageOffset = totalCount;
83+
// fallback to pageOffset = pageStart + totalCount;
8484
// We cast the type based on the setterMethod parameter type
8585
String pType = setterMethod.getParameterTypes()[0].getSimpleName();
8686
if ("Long".equals(pType)) {
87-
value = (long) this.totalCount;
87+
value = (long) (this.iterable.pageStart + this.totalCount);
8888
} else {
89-
value = this.totalCount;
89+
value = this.iterable.pageStart + this.totalCount;
9090
}
9191
}
9292

0 commit comments

Comments
 (0)