Skip to content

fix(generate-schema-types): mark properties with defaults as always present in generated types#1048

Merged
vladfrangu merged 3 commits intoapify:masterfrom
JuanGalilea:generate-schema-types-input-optional-inversion
Mar 25, 2026
Merged

fix(generate-schema-types): mark properties with defaults as always present in generated types#1048
vladfrangu merged 3 commits intoapify:masterfrom
JuanGalilea:generate-schema-types-input-optional-inversion

Conversation

@JuanGalilea
Copy link
Contributor

@JuanGalilea JuanGalilea commented Mar 24, 2026

currently the optionalness of fields is based on the users perspective, not the actor's. This PR flips it and makes the output types match the structure that the actor receives when calling Actor.getInput()

As an example, an input schema containing:

{
  "properties": {
    "normal": { "type": "string" },
    "required": { "type": "string" },
    "defaulted": { "type": "string", "default": "hello" },
  },
  "required": ["required"]
}

The interface for the user should be:

type Input = {
  normal?: string;    // no strict requirement of it
  required: string;   // its required so we have to supply it to run the actor
  defaulted?: string; // since it has a default, its not necessary to fill it (even if made required?)
};

But the input interface as seen by the actor is:

type Input = {
  normal?: string;   // user won't necessarily supply it and its not defaulted
  required: string;  // user MUST supply it
  defaulted: string; // always there since the platform supplied a default value
};

The main use case is the last one, so as to be able to provide an interface matching the real input_schema during an actor's development cycle.

@JuanGalilea JuanGalilea marked this pull request as ready for review March 25, 2026 08:52
@JuanGalilea JuanGalilea requested a review from vladfrangu as a code owner March 25, 2026 08:52
Copy link
Contributor

@l2ysho l2ysho left a comment

Choose a reason for hiding this comment

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

just one thing found by claude, scenarios looks valid

@JuanGalilea JuanGalilea requested a review from l2ysho March 25, 2026 09:13
Copy link
Contributor

@l2ysho l2ysho left a comment

Choose a reason for hiding this comment

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

lgtm, thx @JuanGalilea

@vladfrangu pls also take a look

  • tests locally ✅
  • added some regression tests for scenarios found by claude

@vladfrangu vladfrangu changed the title fix(generate-schema-types): change optionals to inside actor perspective fix(generate-schema-types): mark properties with defaults as always present in generated types Mar 25, 2026
@vladfrangu vladfrangu merged commit 0af4974 into apify:master Mar 25, 2026
13 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants