mswjs / source

Generate MSW request handlers from various sources (HAR files, OpenAPI documents, etc).
https://source.mswjs.io
134 stars 5 forks source link

In the OpenAPI spec, `enum` keys are not respected #60

Open kevbook opened 3 weeks ago

kevbook commented 3 weeks ago

Description

In the OpenAPI spec, when an enum key exists, it's not respected in mock responses. See example:

"responses": {
  "200": {
    "description": "Default Response",
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "status": {
              "type": "number",
              "enum": [200]
            }
          },
          "required": ["status"],
          "additionalProperties": false
        }
      }
    }
  }
}

Just using standard library

import { fromOpenApi } from '@mswjs/source/open-api'
import api from './api.spec.json'

const handlers = await fromOpenApi(api)

// Result when using client
Result: { status: 16.76 }

Reproduction steps

Expected behavior

Initial assessment

Screenshots