You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the property has a default value, then it will return the specified value.
This is highest on the list, so if default is found, it's used no matter what. This is problematic with nullable fields, which may or may not exist in a response:
Because the field is optional, it's not defined in "required". But then, it's common to explicitly show the field in a response, so it's declared as nullable, too ("type": ["string", "null"]). No problem so far.
The problem comes when the schema also contains "default": null value, which should be valid although maybe not absolutely required? (Should be interpret as null if it doesn't exist, at least when not talking about PATCH methods...)
At least Pydantic, a popular Python library (and probably some other tools as well?), output schema like this when the default value is None:
classFoobar(BaseModel):
foo: str|None=None
Because it really defines a default value, it totally makes sense that the outputted JSON schema has that "default": null.
Current Behavior
Prism chooses null value in mocking, because it's declared as default.
Expected Behavior
There are much more interesting options available than null (although technically valid). It would be much nicer to use "example-1". Null just gives basically nothing, it's obscure and everything.
Have Prism use the first example (if one exists), instead of the null default.
Possible Solution(s)
Prioritize example over default, when it's null.
The text was updated successfully, but these errors were encountered:
Context
The docs at https://docs.stoplight.io/docs/prism/83dbbd75532cf-http-mocking have this as the highest priority in value mocking:
This is highest on the list, so if
default
is found, it's used no matter what. This is problematic with nullable fields, which may or may not exist in a response:Because the field is optional, it's not defined in
"required"
. But then, it's common to explicitly show the field in a response, so it's declared as nullable, too ("type": ["string", "null"]
). No problem so far.The problem comes when the schema also contains
"default": null
value, which should be valid although maybe not absolutely required? (Should be interpret as null if it doesn't exist, at least when not talking aboutPATCH
methods...)At least Pydantic, a popular Python library (and probably some other tools as well?), output schema like this when the default value is
None
:Because it really defines a default value, it totally makes sense that the outputted JSON schema has that
"default": null
.Current Behavior
Prism chooses
null
value in mocking, because it's declared asdefault
.Expected Behavior
There are much more interesting options available than
null
(although technically valid). It would be much nicer to use"example-1"
. Null just gives basically nothing, it's obscure and everything.Have Prism use the first example (if one exists), instead of the
null
default.Possible Solution(s)
Prioritize example over default, when it's
null
.The text was updated successfully, but these errors were encountered: