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: add type error if path doesn't start with / #882

Merged
merged 1 commit into from
Aug 23, 2024
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
4 changes: 3 additions & 1 deletion packages/io-ts-http/src/httpRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const Method = t.keyof({

export type Method = t.TypeOf<typeof Method>;

export type PathString = `/${string}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm torn between whether this counts as a breaking change, or something more akin to "this was always intended and the previous behavior is a bug". I'm curious to hear what others think about this.

Copy link
Contributor Author

@ad-world ad-world Aug 23, 2024

Choose a reason for hiding this comment

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

Would an endpoint even work if the path didn't didn't start with a /?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can test with superagent and express, but right now am assuming it is sort of undefined behavior and a leading / may be implicitly added

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose viewing that as undefined behavior is an argument against it being a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also not opposed to marking this as a breaking change! I can add that to the commit msg if needed.


export type HttpRoute<M extends Method = Method> = {
readonly path: string;
readonly path: PathString;
readonly method: Uppercase<M>;
readonly request: HttpRequestCodec<any>;
readonly response: HttpResponse;
Expand Down
2 changes: 1 addition & 1 deletion packages/superagent-wrapper/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const requestForRoute =
let path = route.path;
for (const key in reqProps.params) {
if (reqProps.params.hasOwnProperty(key)) {
path = path.replace(`{${key}}`, reqProps.params[key]);
path = path.replace(`{${key}}`, reqProps.params[key]) as h.PathString;
}
}

Expand Down