Skip to content

Typing: API does not allow passing additional properties #182

Closed
@msw-kialo

Description

@msw-kialo

GitHub deployments API includes a payload field. That can be JSON payload (either as string or directly embedded).

It is currently documented as:

payload:
  oneOf:
    - type: object
      additionalProperties: true
    - type: string
      description: JSON payload with extra information about the deployment.
      default: ''

it is currently typed as

class ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type(TypedDict):
    """ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0"""

However, TypedDict do not allow additional fields at the moment (PEP 728 – TypedDict with Typed Extra Items):

from githubkit.versions.latest.types import ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type

empty : ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type = {}

some_field_bool : ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type = {"downtime": False}
some_field_str : ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type = {"downtime": "false"}

Results in typing issues with at least pyright and mypy

> pyright
payload_test.py
  payload_test.py:5:77 - error: Type "dict[str, bool]" is not assignable to declared type "ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type"
    "downtime" is an undefined item in type "ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type" (reportAssignmentType)
  payload_test.py:6:76 - error: Type "dict[str, str]" is not assignable to declared type "ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type"
    "downtime" is an undefined item in type "ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type" (reportAssignmentType)
2 errors, 0 warnings, 0 informations 
> mypy
payload_test.py:5: error: Extra key "downtime" for TypedDict "ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type"  [typeddict-unknown-key]
payload_test.py:6: error: Extra key "downtime" for TypedDict "ReposOwnerRepoDeploymentsPostBodyPropPayloadOneof0Type"  [typeddict-unknown-key]
I think for the time being additionalProperties: true must allow a plain dict?

Therefore, in a type-safe practice create_deployment and async_create_deployment can only be used with strings but not dicts (as the schema should allow).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions