Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Paged Collection request fails on "You try to get wrong resource type: expected PagedResourceCollection type" #83

Closed
ed4becky opened this issue Oct 18, 2022 · 2 comments

Comments

@ed4becky
Copy link

I am making a request for a PagedResouurce (networks). When the results are empty, I get the error in the title, because the results are returned without an _embedded field

{
    "_links": {
        "self": {
            "href": "https://gateway.sandbox.netfoundry.io/core/v2/networks?page=0&size=30"
        }
    },
    "page": {
        "size": 0,
        "totalElements": 0,
        "totalPages": 1,
        "number": 0
    }
}

Since the results are empty and _embedde3d is OPTIONAl, is this the correct behavior?

function isPagedResourceCollection(object) {
const baseCondition = isObject(object) &&
('_links' in object) &&
('page' in object);
if (!baseCondition) {
return false;
}
if (LibConfig.getConfig().halFormat.collections.embeddedOptional) {
return baseCondition && (Object.keys(object).length === 2 ||
'_embedded' in object && Object.keys(object).length === 3);
}
else {
return baseCondition && '_embedded' in object && Object.keys(object).length === 3;
}
}

@lagoshny
Copy link
Owner

@ed4becky look at the same issue.

You can configure lib to ignore an empty _embedded props.

@ed4becky
Copy link
Author

Thanks, sorry I missed that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants