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

Bug: curl syntax for JSON -d should escape single quote #1068

Open
yungyuchen521 opened this issue Jan 6, 2025 · 1 comment
Open

Bug: curl syntax for JSON -d should escape single quote #1068

yungyuchen521 opened this issue Jan 6, 2025 · 1 comment

Comments

@yungyuchen521
Copy link

yungyuchen521 commented Jan 6, 2025

Description

The generated curl sample code doesn't escape single quote for JSON body.

Reproduction

This can be reproduced with the OpenAPI spec below:

{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "post": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string"
                  }
                }
              },
              "examples": {
                "Message": {
                  "value": {
                    "text": "The user's message"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

The corresponding curl syntax doesn't escape ' for -d:

curl -X POST "http://localhost:3000/" \
 -H "content-type: application/json" \
 -d '{"text":"The user's message"}'

The correct syntax is:

curl -X POST "http://localhost:3000/" \
 -H "content-type: application/json" \
 -d '{"text":"The user'\''s message"}'

Suggestion

Change this line to:

curlData = ` -d '${JSON.stringify(JSON.parse(exampleTextAreaEl.value.replace(/'/g, "'\\''")))}' \\\n`;
@mrin9
Copy link
Collaborator

mrin9 commented Jan 8, 2025

thanks, will take a look soon

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

No branches or pull requests

2 participants