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

Add application/x-www-form-urlencoded OAS style serialization support #226

Open
ostridm opened this issue Feb 26, 2024 · 0 comments · May be fixed by #227
Open

Add application/x-www-form-urlencoded OAS style serialization support #226

ostridm opened this issue Feb 26, 2024 · 0 comments · May be fixed by #227
Assignees
Labels
Type: enhancement New feature or request.

Comments

@ostridm
Copy link
Contributor

ostridm commented Feb 26, 2024

Description

According to OpenAPI 3.x specification, it's possible to specify the style for parts of application/x-www-form-urlencoded body via EncodingObject.style

Steps to reproduce

Pass the my-schema.yaml (see below) to the oas2har as follows:

import { oas2har } from '@har-sdk/oas';
import { readFile } from 'fs';
import { promisify } from 'util';
import { load } from 'js-yaml';

const content = await promisify(readFile)(
  './my-schema.yaml',
  'utf8'
);

const result = oas2har(load(content) as OpenAPIV3.Document);
my-schema.yaml
openapi: 3.0.0
info:
  version: 1.0.0
  title: API
servers:
  - url: https://example.com/api/v1
paths:
  /nested-array-default:
    post:
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/NestedPrimitivesArray'
      responses:
        '200':
          description: ''
  /nested-array-default-explode:
    post:
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/NestedPrimitivesArray'
            encoding:
              bookIds:
                explode: true
      responses:
        '200':
          description: ''
components:
  schemas:
    PrimitivesArray:
      type: array
      items:
        type: number
    NestedPrimitivesArray:
      type: object
      properties:
        bookIds:
          schema:
            $ref: '#/components/schemas/PrimitivesArray'
      example:
        bookIds:
          - 1
          - 2

Actual result

application/x-www-form-urlencoded form data in HAR entry postData is produced as follows:

  postData:
    mimeType: application/x-www-form-urlencoded
    text: bookIds[0]=1&bookIds[1]=2
  postData:
    mimeType: application/x-www-form-urlencoded
    text: bookIds=[1,2]

Expected result

  postData:
    mimeType: application/x-www-form-urlencoded
    text: bookIds=1,2
  postData:
    mimeType: application/x-www-form-urlencoded
    text: bookIds=1&bookIds=2
@ostridm ostridm added the Type: enhancement New feature or request. label Feb 26, 2024
@ostridm ostridm self-assigned this Feb 26, 2024
ostridm added a commit that referenced this issue Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant