Skip to content

InnerShadowEffect required list is missing the type property #84

@DavidVanKampen-eaton

Description

@DavidVanKampen-eaton

The InnerShadowEffect does not have type listed as a required property, which can create a problem when you run this schema through the datamodel-code-generator tool. Documentation for that tool can be found here - https://datamodel-code-generator.koxudaxi.dev/.

generated code without type set as required:

class InnerShadowEffect(BaseShadowEffect):
    type: Literal["INNER_SHADOW"] | None = Field(
        None,
        description="A string literal representing the effect's type. Always check the type before reading other properties.",
    )

generated code with type set as required:

class InnerShadowEffect(BaseShadowEffect):
    type: Literal["INNER_SHADOW"] = Field(
        ...,
        description="A string literal representing the effect's type. Always check the type before reading other properties.",
    )

The key differences - no Union operator with None (| None), and the default is ... instead of None.

The code without the fix cannot be imported - it produces the following error:

pydantic.errors.PydanticUserError: Model 'InnerShadowEffect' needs field 'type' to be of type `Literal`

With the fix, the import works fine.

type should be required, because it is used as the discriminator here:

discriminator:
        propertyName: type
        mapping:
          DROP_SHADOW: "#/components/schemas/DropShadowEffect"
          INNER_SHADOW: "#/components/schemas/InnerShadowEffect"
          LAYER_BLUR: "#/components/schemas/BlurEffect"
          BACKGROUND_BLUR: "#/components/schemas/BlurEffect"
          TEXTURE: "#/components/schemas/TextureEffect"
          NOISE: "#/components/schemas/NoiseEffect"

It appears all other items in that mapping list DO have type set as required.

Reproducing the Error

Here is a pyproject.toml for running the generator:

[tool.datamodel-codegen]
url = "https://github.com/figma/rest-api-spec/raw/refs/tags/v0.35.0/openapi/openapi.yaml"
input-file-type = "openapi"
output = "models.py"
output-model-type = "pydantic_v2.BaseModel"
formatters = ["isort", "ruff-format"]
enum-field-as-literal = "all"

Note that the enum-field-as-literal flag set to all.

With the above, run datamodel-codegen, then just run import models in a python REPL to see if an error occurs or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions