Skip to content

Commit

Permalink
Merge pull request #237 from cmars/fix/singletons-arent-paginated
Browse files Browse the repository at this point in the history
fix: singletons are not paginated
  • Loading branch information
cmars authored Apr 8, 2022
2 parents 5d744c8 + 1058cd0 commit 865dc4f
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 3 deletions.

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

4 changes: 3 additions & 1 deletion end-end-tests/api-standards/test-bulk.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cat >$tempdir/passes <<EOF
}, {
"from": "$HERE/resources/thing/2021-11-10/000-batch-post.yaml", "to": "$HERE/resources/thing/2021-11-10/000-batch-post.yaml", "context": {"changeDate": "2021-11-11", "changeResource": "thing", "changeVersion": {"date": "2021-11-10", "stability": "experimental"}}
}, {
"from": "$HERE/resources/thing/2021-11-10/001-singleton.yaml", "to": "$HERE/resources/thing/2021-11-10/001-singleton.yaml", "context": {"changeDate": "2021-11-11", "changeResource": "thing", "changeVersion": {"date": "2021-11-10", "stability": "experimental"}}
"to": "$HERE/resources/thing/2021-11-10/001-singleton.yaml", "context": {"changeDate": "2021-11-11", "changeResource": "thing", "changeVersion": {"date": "2021-11-10", "stability": "experimental"}}
}, {
"from": "$HERE/resources/thing/2021-11-10/000-baseline-in-reform.yaml", "to": "$HERE/resources/thing/2021-11-10/002-fail-tenancy.yaml", "context": {"changeDate": "2021-11-11", "changeResource": "thing", "changeVersion": {"date": "2021-11-10", "stability": "experimental"}}
}]
Expand Down Expand Up @@ -78,6 +78,8 @@ cat >$tempdir/failures <<EOF
"from": "$HERE/resources/thing/2021-11-10/002-fail-batch-post.yaml", "to": "$HERE/resources/thing/2021-11-10/002-fail-batch-post.yaml", "context": {"changeDate": "2021-11-11", "changeResource": "thing", "changeVersion": {"date": "2021-11-10", "stability": "experimental"}}
}, {
"from": "$HERE/resources/thing/2021-11-10/000-baseline.yaml", "to": "$HERE/resources/thing/2021-11-10/003-jsonapi.yaml", "context": {"changeDate": "2021-11-11", "changeResource": "thing", "changeVersion": {"date": "2021-11-10", "stability": "experimental"}}
}, {
"to": "$HERE/resources/thing/2021-11-10/002-fail-singleton-no-pagination.yaml", "context": {"changeDate": "2021-11-11", "changeResource": "thing", "changeVersion": {"date": "2021-11-10", "stability": "experimental"}}
}]
}
EOF
Expand Down
7 changes: 5 additions & 2 deletions src/rulesets/jsonapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ export const rules = {
"correctly support pagination parameters",
(operation, context, docs, specItem) => {
docs.includeDocsLink(links.jsonApi.pagination);
if (context.isSingletonPath) {
return;
}
if (isOpenApiPath(context.path)) return;
if (isItemOperation(operation)) return;
if (operation.method !== "get") return;
Expand Down Expand Up @@ -289,7 +292,7 @@ export const rules = {
docs.includeDocsLink(links.jsonApi.pagination);
if (isOpenApiPath(context.path)) return;
if (isItemOperation(operation)) return;
if (operation.method === "get") return;
if (operation.method === "get" && !context.isSingletonPath) return;
const operationName = getOperationName(operation);
const parameterNames = getParameterNames(specItem.parameters);
const unsupportedPaginationParameters: string[] = [];
Expand All @@ -315,7 +318,7 @@ export const rules = {
docs.includeDocsLink(links.jsonApi.pagination);
if (isOpenApiPath(context.path)) return;
if (isItemOperation(operation)) return;
if (operation.method !== "get") return;
if (operation.method !== "get" || context.isSingletonPath) return;
const operationName = getOperationName(operation);
const response = specItem.responses["200"];
if (!("$ref" in response)) {
Expand Down

0 comments on commit 865dc4f

Please sign in to comment.