Skip to content

fix: Invalid slot type and templated parameters - #10

Open
Derugon wants to merge 3 commits into
wikimedia-gadgets:mainfrom
Derugon:templatedparameters
Open

fix: Invalid slot type and templated parameters#10
Derugon wants to merge 3 commits into
wikimedia-gadgets:mainfrom
Derugon:templatedparameters

Conversation

@Derugon

@Derugon Derugon commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Issue

A few modules use templated parameters to let users specify a variable number of structured arguments.
For example, the action=compare API uses 2 sets of templated parameters (from… and to…) to specify additional parameters for one or more sources and targets:

{
    ...
    "fromslots": ["foo", "bar"],
    "fromtext-foo": "Foo text",
    "fromsection-foo": "Foo section",
    "fromtext-bar": "Bar text",
    "fromsection-bar": "Bar section",
    ...
}

These are defined by:

  1. A slots parameter to specify a set of identifiers (e.g. fromslots: ["foo", "bar"],
  2. Templated parameters used once per previously defined identifier (e.g. "fromtext-foo": "Foo text", "fromtext-bar": "Bar text").

However, templated parameters are currently not included in interfaces, and slot types only allow an extremely limited set of values.
For example, the following parameters are generated for ApiComparePagesParams:

export interface ApiComparePagesParams extends ApiParams {
    ...
    fromslots?: OneOrMore<"main">;
    ...
    toslots?: OneOrMore<"main">;
    ...
}

Proposed changes

In this PR, as a first step, templated parameters are generated using template literal types, ensuring properly-prefixed parameters have the correct types.
For example, the following parameters are generated for ApiComparePagesParams:

export interface ApiComparePagesParams extends ApiParams {
    ...
    fromslots?: string | string[];
    [k: `fromtext-${string}`]: string;
    [k: `fromsection-${string}`]: string;
    ...
    toslots?: string | string[];
    [k: `totext-${string}`]: string;
    [k: `tosection-${string}`]: string;
    ...
}

This could be improved further, as this approach does not ensure parameter name suffixes are synchronized with each other.

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.

1 participant