Skip to content

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

@ostridm

Description

@ostridm

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions