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

fix: path parameters are not encoded #679 #895

Merged
merged 9 commits into from
Nov 30, 2023

Conversation

Maxim-Mazurok
Copy link
Contributor

@Maxim-Mazurok Maxim-Mazurok commented Jul 13, 2023

Status

READY

Description

Addresses #679 issue, based on my patch #679 (comment)

Also updates vue to the latest, so that we can use MaybeRef from it's indirect dependency @vue/reactivity. I need this because the old import was unresolved when using "moduleResolution": "bundler" which is the default now for vue in in node_modules/@vue/tsconfig/tsconfig.json

I think some people might have implemented encoding on their end, so this probably should be a major release, otherwise people will get double-encoding.

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased) - not sure what to do about this

@vercel
Copy link

vercel bot commented Jul 13, 2023

Someone is attempting to deploy a commit to a Personal Account owned by @anymaniax on Vercel.

@anymaniax first needs to authorize it.

@anymaniax
Copy link
Collaborator

@Maxim-Mazurok thanks for the help. It's encode every parameters? If wouldn't be better to add that as a config?

@Maxim-Mazurok
Copy link
Contributor Author

@Maxim-Mazurok thanks for the help. It's encode every parameters? If wouldn't be better to add that as a config?

I would argue that it should be encoded by default, for example /api?song=Me&you will unexpectedly be parsed as song=Me; you=

But I guess it'd be easier to make a non-default option, then no need for major release, I'll do that.

@melloware melloware linked an issue Nov 10, 2023 that may be closed by this pull request
@melloware
Copy link
Collaborator

I would think we want all parameters encoded by default no?

@Maxim-Mazurok
Copy link
Contributor Author

I would think we want all parameters encoded by default no?

I would want that as well, but as @anymaniax mentioned this will be a breaking change and might require a major release. I think that would be a good idea overall, what do you think?

@melloware
Copy link
Collaborator

I mean I guess I don't see the harm in encoding URLs it feels like the safe thing to do. I wonder what @anymaniax concern is?

@Maxim-Mazurok
Copy link
Contributor Author

Maxim-Mazurok commented Nov 29, 2023

I mean I guess I don't see the harm in encoding URLs it feels like the safe thing to do. I wonder what @anymaniax concern is?

Well, I'm pretty sure that we agree that it's a good thing, but changing default behaviour will be a breaking change.

For example, if someone had /api?song=Me&you in their project - their server would receive {song: "Me", you: undefined}. Even thought this is a bug, some people might be fine with this bug and actually want it to work this way. If we make the change and encode all by default - their server will now get {song: "Me&you"} which is technically correct, but imagine if they already have some logic like if (song === "Me") to handle this request - then it'll break, potentially introducing bugs.

So I think the best thing to do is to encode all params by default and make a major release (major version bump) so that people know to expect breaking changes.

The second best thing to do is to make encoding params a non-default option.

}

if (output?.urlEncodeParameters) {
route = makeRouteSafe(route);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the core change that addresses the original issue

@Maxim-Mazurok
Copy link
Contributor Author

Maxim-Mazurok commented Nov 30, 2023

This is ready for review now

Summary:

  • Added urlEncodeParameters option, false by default
  • Enable tsc --noEmit for packages/orval (ignored most of the pre-existing issues for now)
  • Added docs for urlEncodeParameters and allParamsOptional new output options
  • Added zod option for OutputClient
  • Passing output: NormalizedOutputOptions all the way into packages/query's builder (now I realise that it probably makes sense to have urlEncodeParameters for all clients and I could probably have done it somewhere else... perhaps we can refactor in the future, still I think it's useful to pass config options to the builder, and not too confident changing other clients)

Copy link
Collaborator

@anymaniax anymaniax left a comment

Choose a reason for hiding this comment

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

Seems really good to me! Thanks @Maxim-Mazurok

@Maxim-Mazurok Maxim-Mazurok merged commit ff2b7d3 into orval-labs:master Nov 30, 2023
2 checks passed
route: string,
prepend: string,
append: string,
): string => route.replaceAll(/\${(.+?)}/g, `\${${prepend}$1${append}}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

getRouteAsArray uses a slightly different regex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, interesting. I think mine is better because it seems to be more aligned with OpenAPI specs by allowing special characters and an empty string: OAI/OpenAPI-Specification#1969 (comment)

But yeah, it's probably better to refactor it to avoid duplication

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've created #1084 to address 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

Successfully merging this pull request may close these issues.

Path Parameters Are Not Encoded
4 participants