Skip to content

Nullable properties not accepting null as acceptable #212

@JohnRoux

Description

@JohnRoux

Hey,

I'm finding that when validating the response, I'm often getting issues which don't quite make sense to me.

Here's the error:

allOf <== The data should match all schemas
    object++ <== The properties must match schema: data
        data: array
            object++ <== The properties must match schema: custom_expiry_content
                id*: integer
                model_name*: string
                company_id*: integer
                type*: string [Ongoing, Batch]
                name*: string
                status*: string
                status_code: string
                voucher_expiry_fast: boolean
                voucher_expiry_days*: integer?
                voucher_expiry_minutes: integer?
                has_custom_expiry_content: boolean
                custom_expiry_content: string? <== The data (null) must match the type: string
                sent_at: string?

But you can see that that field is string? which should 100% allow for a null value?

I've gotten the same with integer values too.

If it helps, I'm usiing zircote OA schema to generate my openAPI docs.
The schema for that object looks like this:

    /**
     * @OA\Schema(
     *     schema="v2Campaign",
     *     required={"id", "model_name", "company_id", "name", "status", "voucher_expiry_days", "type", "created_at", "updated_at"},
     *     type="object",
     *     title="Campaign",
     *
     *     @OA\Property(property="id", type="integer"),
     *     @OA\Property(property="model_name", type="string"),
     *     @OA\Property(property="company_id", type="integer"),
     *     @OA\Property(property="type", type="string", enum={"Ongoing", "Batch"}),
     *     @OA\Property(property="name", type="string"),
     *     @OA\Property(property="status", type="string"),
     *     @OA\Property(property="status_code", type="string"),
     *     @OA\Property(property="voucher_expiry_fast", type="boolean"),
     *     @OA\Property(property="voucher_expiry_days", type="integer", nullable=true),
     *     @OA\Property(property="voucher_expiry_minutes", type="integer", nullable=true),
     *     @OA\Property(property="has_custom_expiry_content", type="boolean"),
     *     @OA\Property(property="custom_expiry_content", type="string", nullable=true),

And in the actual json api it's also reflected as being nullable.

"v2Campaign": {
                "title": "Campaign",
                "required": [
                    "id",
                    "model_name",
                    "company_id",
                    "name",
                    "status",
                    "voucher_expiry_days",
                    "type",
                    "created_at",
                    "updated_at"
                ],
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "model_name": {
                        "type": "string"
                    },
                    "company_id": {
                        "type": "integer"
                    },
                    "type": {
                        "type": "string",
                        "enum": [
                            "Ongoing",
                            "Batch"
                        ]
                    },
                    "name": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string"
                    },
                    "status_code": {
                        "type": "string"
                    },
                    "voucher_expiry_fast": {
                        "type": "boolean"
                    },
                    "voucher_expiry_days": {
                        "type": "integer",
                        "nullable": true
                    },
                    "voucher_expiry_minutes": {
                        "type": "integer",
                        "nullable": true
                    },
                    "has_custom_expiry_content": {
                        "type": "boolean"
                    },
                    "custom_expiry_content": {
                        "type": "string",
                        "nullable": true
                    },
                    "sent_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "channel_config": {
                        "description": "This is only added when doing getting a channel and including the campaign",
                        "properties": {
                            "message_content": {
                                "type": "string"
                            },
                            "export_email_address": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    },
                    "channels": {
                        "$ref": "#/components/schemas/v2ChannelCollection"
                    },
                    "created_at": {
                        "type": "string"
                    },
                    "updated_at": {
                        "type": "string"
                    }
                },
                "type": "object"
            },

Would love some insights/help as to how to fix this, as the error message seems to contradict the typing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions