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

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

Open
jsokolowskii opened this issue Apr 26, 2023 · 2 comments

Comments

@jsokolowskii
Copy link

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
@williamdevitt7
Copy link

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

@lopenchi
Copy link

lopenchi commented Oct 2, 2023

Any answer on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants