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

Fixed url conversion when exporting to Postman #2885

Closed
wants to merge 1 commit into from

Conversation

jbgomond
Copy link

@jbgomond jbgomond commented Aug 22, 2024

Description

The Postman export function is broken at the moment.
Fixes #2496.

This PR fixes the following issues :

  • Protocol is not exported
  • Text path segments are not exported
  • Auth url parameters are not exported
  • Path variables are no longer being re-ordered
  • Supports the case where not hostname is provided
  • Supports the case where the authentication is provided in the URL

I added a lot of unit tests to cover that part :)

With Bruno :

image

After import in Postman, before this PR :

image

After import in Postman, after this PR :

image

@@ -203,15 +232,17 @@ export const exportCollection = (collection) => {
header: generateHeaders(itemRequest.headers),
url: {
raw: itemRequest.url,
auth: generateAuthFromUrl(itemRequest.url),
Copy link
Member

@sanjai0py sanjai0py Aug 26, 2024

Choose a reason for hiding this comment

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

Are you sure Postman supports this schema?

Postman Schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "If object, contains the complete broken-down URL for this request. If string, contains the literal request URL.",
  "$id": "#/definitions/url",
  "title": "Url",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "raw": {
          "type": "string",
          "description": "The string representation of the request URL, including the protocol, host, path, hash, query parameter(s) and path variable(s)."
        },
        "protocol": {
          "type": "string",
          "description": "The protocol associated with the request, E.g: 'http'"
        },
        "host": {
          "title": "Host",
          "description": "The host for the URL, E.g: api.yourdomain.com. Can be stored as a string or as an array of strings.",
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "type": "string"
              },
              "description": "The host, split into subdomain strings."
            }
          ]
        },
        "path": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "description": "The complete path of the current url, broken down into segments. A segment could be a string, or a path variable.",
              "items": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string"
                      },
                      "value": {
                        "type": "string"
                      }
                    }
                  }
                ]
              }
            }
          ]
        },
        "port": {
          "type": "string",
          "description": "The port number present in this URL. An empty value implies 80/443 depending on whether the protocol field contains http/https."
        },
        "query": {
          "type": "array",
          "description": "An array of QueryParams, which is basically the query string part of the URL, parsed into separate variables",
          "items": {
            "type": "object",
            "title": "QueryParam",
            "properties": {
              "key": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "value": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "disabled": {
                "type": "boolean",
                "default": false,
                "description": "If set to true, the current query parameter will not be sent with the request."
              },
              "description": {
                "$ref": "#/definitions/description"
              }
            }
          }
        },
        "hash": {
          "description": "Contains the URL fragment (if any). Usually this is not transmitted over the network, but it could be useful to store this in some cases.",
          "type": "string"
        },
        "variable": {
          "type": "array",
          "description": "Postman supports path variables with the syntax `/path/:variableName/to/somewhere`. These variables are stored in this field.",
          "items": {
            "$ref": "#/definitions/variable"
          }
        }
      }
    },
    {
      "type": "string"
    }
  ]
}

https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html

@ravarage
Copy link

bumping this

@helloanoop
Copy link
Contributor

Hey @jbgomond !

Thanks for taking time to work on this PR.
I am closing this PR as this has already been addressed in #3025

@helloanoop helloanoop closed this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export Collection as Postman Collection
4 participants