prism icon indicating copy to clipboard operation
prism copied to clipboard

Static response generation returns 'string' instead of null for a nullable field

Open jsokolowskii opened this issue 1 year ago • 2 comments

While running prism mock server with OpenApi 3.0 specification a nullable field is returned with the value "string" instead of null in the HTTP response body.

Context

The OpenApi spec https://raw.githubusercontent.com/twilio/twilio-oai/main/spec/json/twilio_api_v2010.json is as follows:

{
  "openapi": "3.0.1",
  "components": {
    "schemas": {
      "api.v2010.account.message": {
        ...
        "properties": {
          ...
          "price_unit": {
            "type": "string",
            "format": "currency",
            "nullable": true,
            "description": "The currency in which `price` is measured, in [ISO 4127](https://www.iso.org/iso/home/standards/currency_codes.htm) format (e.g. `usd`, `eur`, `jpy`)."
          },
          ...
        }
      }
    }
  },
  "paths": {
    "/2010-04-01/Accounts/{AccountSid}/Messages.json": {
      ...
      "post": {
        ...
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/api.v2010.account.message"
                }
              }
            },
            "description": "Created"
          }
        },
        ...
      },
      ...
    },
    ...
  },
  ...
}

Current Behavior

When running request curl -s -D "/dev/stderr" http://127.0.0.1:4010/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages.json -u aaa:aaa | json_pp I get the response:

{
   "account_sid" : "stringstringstringstringstringstri",
   "api_version" : "string",
   "body" : "string",
   "date_created" : "string",
   "date_sent" : "string",
   "date_updated" : "string",
   "direction" : "inbound",
   "error_code" : 0,
   "error_message" : "string",
   "from" : "string",
   "messaging_service_sid" : "stringstringstringstringstringstri",
   "num_media" : "string",
   "num_segments" : "string",
   "price" : "string",
   "price_unit" : "string",
   "sid" : "stringstringstringstringstringstri",
   "status" : "queued",
   "subresource_uris" : {},
   "to" : "string",
   "uri" : "string"
}

price_unit (and other nodes as well) value is "string".

Expected Behavior

The value for the nullable fields should be null if no default or example values are specified as per the documentation: https://github.com/stoplightio/prism/blob/master/docs/guides/01-mocking.md#static-response-generation

Possible Workaround/Solution

Workaround: adding a default value in the spec works.

Steps to Reproduce

  1. Run prism mock https://raw.githubusercontent.com/twilio/twilio-oai/main/spec/json/twilio_api_v2010.json
  2. Run curl -s -D "/dev/stderr" http://127.0.0.1:4010/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages.json -u aaa:aaa | json_pp
  3. Verify the response.

Environment

  • Version used: 4.12.0

jsokolowskii avatar Apr 26 '23 11:04 jsokolowskii

Having this same issue as well, with the same Twilio functionality. I'm on M2 Apple silicon.

williamdevitt7 avatar Jul 18 '23 15:07 williamdevitt7

Any answer on this?

lopenchi avatar Oct 02 '23 21:10 lopenchi