Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Duplicates in required field of ObjectType JSON schema #338

Closed
MeltyBot opened this issue Mar 2, 2022 · 3 comments
Closed

Duplicates in required field of ObjectType JSON schema #338

MeltyBot opened this issue Mar 2, 2022 · 3 comments

Comments

@MeltyBot
Copy link
Contributor

MeltyBot commented Mar 2, 2022

Migrated from GitLab: https://gitlab.com/meltano/sdk/-/issues/340

Originally created by @ReubenFrankel on 2022-03-02 12:06:24


Summary

https://gitlab.com/meltano/sdk/-/merge_requests/250#note_859372536

If any Property objects have a non-unique name (i.e. duplicates) and are also required, in the resulting schema dictionary:

  • properties are correctly merged by name
  • required will contain a name for each duplicate property

Steps to reproduce

properties = [
    Property("id", StringType),
    Property("email", StringType, True),
    Property("email", StringType, True), # duplicate required property
    Property("username", StringType, True),
    Property("phone_number", StringType),
]

ObjectType(*properties).type_dict
{
    "type": "object",
    "properties": {
        "id": {
            "type": [
                "string",
                "null",
            ],
        },
        "email": {
            "type": ["string"],
        },
        "username": {
            "type": ["string"],
        },
        "phone_number": {
            "type": [
                "string",
                "null",
            ],
        }
    },
    "required": [
        "email",
        "email",
        "username",
    ],
}

What is the current bug behavior?

Required properties with the same name are merged in properties, but the names remain duplicated in required.

What is the expected correct behavior?

properties = [
    Property("id", StringType),
    Property("email", StringType, True),
    Property("email", StringType, True), # duplicate required property
    Property("username", StringType, True),
    Property("phone_number", StringType),
]

ObjectType(*properties).type_dict
{
    "type": "object",
    "properties": {
        "id": {
            "type": [
                "string",
                "null",
            ],
        },
        "email": {
            "type": ["string"],
        },
        "username": {
            "type": ["string"],
        },
        "phone_number": {
            "type": [
                "string",
                "null",
            ],
        }
    },
    "required": [
        "email",
        "username",
    ],
}

Possible fixes

https://gitlab.com/meltano/sdk/-/blob/main/singer_sdk/typing.py#L281

# see https://stackoverflow.com/a/7961390
result["required"] = list(dict.fromkeys(required)) # filter duplicates from list
@MeltyBot
Copy link
Contributor Author

@stale
Copy link

stale bot commented Jul 18, 2023

This has been marked as stale because it is unassigned, and has not had recent activity. It will be closed after 21 days if no further activity occurs. If this should never go stale, please add the evergreen label, or request that it be added.

@stale stale bot added the stale label Jul 18, 2023
@edgarrmondragon
Copy link
Collaborator

Closed by #1214

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants