Skip to content
Last updated

spec-no-invalid-encoding-combinations

Ensures that MediaType objects and nested Encoding objects have valid combinations of encoding fields according to the OpenAPI 3.2.0 specification.

OASCompatibility
2.0❌
3.0❌
3.1❌
3.2✅

Root

Paths

PathItem

Operation

Parameter

MediaType

RequestBody

Responses

Encoding

Root

Paths

PathItem

Operation

Parameter

MediaType

RequestBody

Responses

Encoding

API design principles

According to the OpenAPI 3.2.0 specification, MediaType objects have strict rules about which encoding fields can be used together. This rule ensures that only valid encoding field combinations are used in MediaType objects. An Encoding object can nest encoding, prefixEncoding, and itemEncoding for a multipart part, so the same rules apply to it.

Configuration

OptionTypeDescription
severitystringPossible values: off, warn, error. Default error (in recommended configuration).

An example configuration:

rules:
  spec-no-invalid-encoding-combinations: error

Examples

Given this configuration:

rules:
  spec-no-invalid-encoding-combinations: error

Example of incorrect MediaType objects:

requestBody:
  content:
    'multipart/form-data':
      schema:
        type: object
        properties:
          id:
            type: integer
      encoding:
        id:
          style: form
      prefixEncoding:
        - style: form
    'application/x-www-form-urlencoded':
      schema:
        type: object
        properties:
          name:
            type: string
      encoding:
        name:
          style: form
      itemEncoding:
        style: form
    'multipart/mixed':
      schema:
        type: object
        properties:
          addresses:
            type: array
      encoding:
        addresses:
          contentType: multipart/mixed
          encoding:
            street:
              style: form
          itemEncoding:
            style: form

Example of correct MediaType objects:

requestBody:
  content:
    'multipart/form-data':
      schema:
        type: object
        properties:
          id:
            type: integer
      encoding:
        id:
          style: form
    'multipart/form-data-positional':
      schema:
        type: object
        properties:
          items:
            type: array
      prefixEncoding:
        - style: form
      itemEncoding:
        style: form

Resources