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

Support both "example" and "examples" in the request body #196

Closed
derevnjuk opened this issue Feb 23, 2023 · 0 comments · Fixed by #197
Closed

Support both "example" and "examples" in the request body #196

derevnjuk opened this issue Feb 23, 2023 · 0 comments · Fixed by #197
Assignees
Labels
Priority: high Type: bug Something isn't working.

Comments

@derevnjuk
Copy link
Member

derevnjuk commented Feb 23, 2023

Description

We are currently unable to extract the request body from "examples". When attempting to fill in the value, the error message The property `application~1x-www-form-urlencoded` must have either `example` or `examples`, but not both, as they are mutually exclusive is displayed due to the "example" parameter being added when the request already has "examples".

Steps to reproduce

To reproduce the issue, follow these steps:

  1. Parse the my-oas.json file (see below) using the following code:
import { OasV3Editor } from '@har-sdk/editor';
import { readFile } from 'node:fs/promises';

const  openApiParser = new OasV3Editor();

await openApiParser.setup(
  await readFile(
    './my-oas.json',
    'utf-8'
  )
);

const result = openApiParser.parse();
  1. Ensure that the parameters of the /paths/~1api~1users/post tree node contain the appropriate values:
{
  "bodyType": "application/x-www-form-urlencoded",
  "paramType": "requestBody",
  "value": {
    "email": "bob@example.com",
    "password": "Qwerty1"
  },
  "valueJsonPointer": "/paths/~1api~1users/post/requestBody/content/application~1x-www-form-urlencoded/~1examples~1example-1~1value"
}
my-oas.json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Support both `example` and `examples` in the request bodies",
    "description": "Ensure accurate extraction of the request body example.",
    "version": "1.0",
    "contact": {}
  },
  "tags": [],
  "servers": [
    {
      "url": "https://brokencrystals.com"
    }
  ],
  "components": {
    "schemas": {
      "User": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          },
          "password": {
            "type": "string",
            "format": "password"
          }
        },
        "required": ["email", "password"]
      }
    }
  },
  "paths": {
    "/api/users": {
      "post": {
        "description": "Should use value from `content[mime].examples`",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/User"
              },
              "examples": {
                "example-1": {
                  "value": {
                    "email": "bob@example.com",
                    "password": "Qwerty1"
                  }
                }
              }
            }
          },
          "description": ""
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {}
          }
        }
      }
    }
  }
}

Actual result

The parsing is completed without errors, however, the resulting node is missing the expected value and contains an unexpected valueJsonPointer.

Expected result

The request body value should first be filled from the "examples", followed by "example". If both of them are absent, the "example" from the "schema" can be used as a last resort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: high Type: bug Something isn't working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant