Skip to content

Conversation

@koul1sh
Copy link
Contributor

@koul1sh koul1sh commented Mar 22, 2025

example.zzb

requests:
  simple-get:
    method: GET
    url: https://jsonplaceholder.typicode.com/:user/posts/:id
    pathParams:
      user: 1
      id: 3

final url would look like this : https://jsonplaceholder.typicode.com/1/posts/3

Copy link
Collaborator

@vasan-agrostar vasan-agrostar left a comment

Choose a reason for hiding this comment

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

Great job! I was expecting you to miss out the schema change. You have done that too. Wonderful. But there are some things we need to address. I have left comments.

"description": "path parameters",
"anyOf": [
{
"type": "array",
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does an array apply to pathParams? I don't think we should allow this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"pathParamObject": {
      "type": "object",
      "description": "A set of path parameters described as key/value pairs",
      "properties": {
        "": { "$ref": "#/$defs/scalar" }
      }
    }

tried with this type but user can still pass array of values.

allData.httpRequest.baseUrl,
allData.httpRequest.url,
getParamsForUrl(allData.httpRequest.params, allData.options.rawParams),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would rather pass the pathParams here and get the getURL() function to incorporate it.

getParamsForUrl(allData.httpRequest.params, allData.options.rawParams),
);

if(allData.httpRequest.pathParams){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally, we should check if the path has /:\w+/ and call substitute. What if the user has forgotten to add pathParams, but has /:userid/ in the path? We got to tell the user that a value is expected, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, the condition is useless, this will run every time. Updated to check this with regex.

if (param) {
return encodeURIComponent(param.value);
}
throw new Error(`Missing value for parameter: ${key}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if a throw translate to a user-friendly readable message in the output window. Have you tested this path?

Copy link
Contributor Author

@koul1sh koul1sh Mar 22, 2025

Choose a reason for hiding this comment

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

Yes it shows an error message about the missing parameter.
Screenshot from 2025-03-23 01-53-53

return baseUrl + path.replace(/:(\w+)/g, (_, key) => {
const param = params.find(p => p.name === key);
if (param) {
return encodeURIComponent(param.value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if we should encodeURI component. Things like "/" in the path parameter are very problematic, even if you encode them. Path parameters are not intended to have complex strings, just IDs, typically numbers. And sometimes slugs, which too, don't have non-word non-number characters.

@koul1sh
Copy link
Contributor Author

koul1sh commented Mar 22, 2025

Hey @vasan-agrostar, I've made changes addressing your comments. Let me know if this looks good.

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.

2 participants