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

(feat): refactor how pagination properties are checked in fern check #4250

Merged
merged 17 commits into from
Aug 10, 2024

Conversation

dsinghvi
Copy link
Member

@dsinghvi dsinghvi commented Aug 10, 2024

Introduces a better primitive for property paths are checked.

  1. Easy to write a message like $response.hasNextPage points to a string but should point to a boolean instead
  2. request + response validation build on the same schemas
  3. validatePropertyInType invokers control the error message
return validatePropertyInType({
        typeResolver,
        file,
        path: getPathFromSelector(offsetPagination["has-next-page"]),
        resolvedType: resolvedResponseType,
        validate: ({ resolvedType }) => {
            const primitiveType = maybePrimitiveType(resolvedType);
            if (primitiveType !== "BOOLEAN") {
                return [
                    {
                        message: `"has-next-page" selector, ${offsetPagination["has-next-page"]}, does not point to a boolean property`,
                        severity: "error"
                    }
                ];
            }
            return [];
        }
    });
}

@dsinghvi dsinghvi marked this pull request as ready for review August 10, 2024 01:55
@dsinghvi dsinghvi merged commit 96e52e2 into main Aug 10, 2024
13 of 14 checks passed
@dsinghvi dsinghvi deleted the dsinghvi/fix-ci branch August 10, 2024 02:07
Copy link
Contributor

@amckinney amckinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor looks great overall, nicely done!

We might be able to do something similar in the IR generator since we have to support a similar analogue abstraction there (i.e. the PropertyResolver).

That refactor isn't as necessary as this one, so we could also defer that until we actually unify fern check and fern ir since it otherwise might be a little wasteful.

propertyValidator: {
propertyID: "has-next-page",
validate: isValidHasNextPageType
path: getPathFromSelector(offsetPagination["has-next-page"]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this would support any selector prefix - it doesn't actually validate that the user specified $response.

@@ -151,23 +152,22 @@ function validateHasNextPageProperty({
if (offsetPagination["has-next-page"] == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: A variable would be nice for this since we use offsetPagination["has-next-page"] in a few places here.

We previously referred to them as propertyComponents, but we could probably just do path so it's consistent with the new validatePropertyInType signature.

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

Successfully merging this pull request may close these issues.

2 participants