When hosting a REST API in your Linx Solution, for certain operations you may want to return NULL
values as the fields for the consuming system. There are a few things you must be aware of when trying to achieve this.
For example if you are returning the below object:
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
email:
type: string
token:
type: string
username:
type: string
bio:
type: string
image:
type: string
-
If no value is specified in the field (no value or no explicit
NULL
value) then Linx will automatically return a value of the default type i.e. “” for a String field.{ "email":"me@example.com", "token":"", "username":"myuser", "bio":"", "image":"" }
-
If you explicitly set the value as
$.System.Null
then Linx will not return that field.{ "email":"me@example.com", "username":"myuser", }
-
If you want to return a
NULL
value in the field (in this case the fieldtoken
), you must ensure that your Open API definition fields have thenullable
property on the field set astrue
as well as specifying that the field isrequired
, like below:responses: '200': description: OK content: application/json: schema: type: object required: - token properties: email: type: string token: type: string nullable: true username: type: string bio: type: string image: type: string
Then if the response object is set like below:
The response object will contain the below values:
{ "email": "me@example.com", "token": null, "username": "myuser" }
More information about the difference between Open API 2 and Open API 3 with nullable
fields can be found on this stackoverflow thread →