Skip to content

Conversation

mfori
Copy link
Member

@mfori mfori commented Jul 22, 2025

Solves https://github.com/apify/apify-core/issues/20247

The default property should allow default: null if field has nullable: true

"test": {
    "title": "test",
    "description": "test",
    "type": "integer",
    "nullable": true, 
    "default": null
}

Thanks to unevaluatedProperties from draft 2019 it's quite easy now

@mfori mfori requested review from fnesveda, valekjo and Copilot July 22, 2025 13:17
@mfori mfori self-assigned this Jul 22, 2025
@mfori mfori added the t-console Issues with this label are in the ownership of the console team. label Jul 22, 2025
@github-actions github-actions bot added this to the 119th sprint - Console team milestone Jul 22, 2025
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Jul 22, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR allows null values as defaults in input schema fields when the field has nullable: true. The implementation uses JSON Schema's unevaluatedProperties from draft 2019 to conditionally validate the default property type based on the nullable flag.

  • Adds conditional validation that allows default: null when nullable: true
  • Updates all property type definitions to use unevaluatedProperties instead of additionalProperties
  • Adds comprehensive test coverage for nullable default behavior across all supported field types

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
test/input_schema.test.ts Adds comprehensive test cases covering nullable default validation for all field types
packages/input_schema/src/schema.json Updates JSON schema definitions to conditionally allow null defaults based on nullable property

Copy link
Member

@valekjo valekjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised about the same thing as Copilot :D - that the if condition works even if the field is missing. I see the tests cover it and work though :)

@mfori
Copy link
Member Author

mfori commented Jul 23, 2025

I'm surprised about the same thing as Copilot :D - that the if condition works even if the field is missing. I see the tests cover it and work though :)

It's quite confusing but it must be like this, because the value fulfill the condition (schema)

"if": { "properties": { "nullable": { "const": false } } }

even if the nullable field is missing, because the field is not required. So the schema "properties": { "nullable": { "const": false } } say that the nullable field must be false if present, but doesn't have to be present.

On the other hand, if we would use the other one:

"if": { "properties": { "nullable": { "const": true } } }

This says that the nullable field is true or not present.

Working approach would be this:

  "if": {
    "properties": { "nullable": { "const": true } },
    "required": ["nullable"]
  },

but it works the same as current solution.

@mfori mfori merged commit f0fc860 into master Jul 23, 2025
9 checks passed
@mfori mfori deleted the feat/nullable-default-null branch July 23, 2025 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-console Issues with this label are in the ownership of the console team. tested Temporary label used only programatically for some analytics.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants