prism
prism copied to clipboard
Static response generation returns 'string' instead of null for a nullable field
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
- Run
prism mock https://raw.githubusercontent.com/twilio/twilio-oai/main/spec/json/twilio_api_v2010.json
- Run
curl -s -D "/dev/stderr" http://127.0.0.1:4010/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages.json -u aaa:aaa | json_pp
- Verify the response.
Environment
- Version used: 4.12.0
Having this same issue as well, with the same Twilio functionality. I'm on M2 Apple silicon.
Any answer on this?