8000 Fix cluster app JSON schema preprocessing by gusevda · Pull Request #4613 · giantswarm/happa · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix cluster app JSON schema preprocessing #4613

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 28, 2024

Conversation

gusevda
Copy link
Contributor
@gusevda gusevda commented May 27, 2024

What does this PR do?

On CAPA installation when you go to cluster creation form you see validation errors that are incorrect.
Image

The reason for this is the error in preprocessing of the default values in JSON schema. In current implementation we convert "type": "object" schemas with additionalProperties or patternProperties into "type": "array" schemas so they are better supported by the form building library. When converting a subschema we also convert the default value of that subschema if it is present. For example, correct preprocessing:

{
    "type": "object",
    "additionalProperties": {
        "type": "string",
    },
    "default": {
        "service-priority": "highest"
    }
}

becomes:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "key": {
                "type": "string"
            },
            "value": {
                "type": "string"
            }
        }
    },
    "default": [
        {
            "key": "service-priority",
            "value": "highest"
        }
    ]
}

In this example default value is specified directly in the schema with additionalProperties and preprocessed correctly. But in some cases default value for a property can come from default value of parent schema. And such cases are not handled correctly in current implementation, for example:

{
    "type": "object",
    "properties": {
        "childProperty": {
            "type": "object",
            "additionalProperties": {
                "type": "string",
            }
        }
    },
    "default": {
        "childProperty": {
            "service-priority": "highest"
        }
    }
}

is incorrectly converted into (childProperty subschema is converted but default value is not):

{
    "type": "object",
    "properties": {
        "childProperty": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "key": {
                        "type": "string"
                    },
                    "value": {
                        "type": "string"
                    }
                }
            }
        }
    }
    "default": {
        "childProperty": {
            "service-priority": "highest"
        }
    }
}

In this PR schema preprocessing was changed and default values are being correctly converted no matter of where they are defined in the schema.

Any background context you can provide?

Fixes giantswarm/roadmap#3452

@gusevda gusevda changed the title Cluster app schema preprocessing fixes Fix cluster app JSON schema preprocessing May 27, 2024
@gusevda gusevda marked this pull request as ready for review May 28, 2024 06:44
@gusevda gusevda requested a review from a team as a code owner May 28, 2024 06:44
@gusevda gusevda requested a review from marians May 28, 2024 06:44
@gusevda gusevda merged commit 92fbee2 into main May 28, 2024
@gusevda gusevda deleted the cluster-app-schema-preprocessing-fixes branch May 28, 2024 07:51
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.

Incorrect validation errors in cluster creation form in Happa
2 participants
0