Skip to content
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

encoding/openapi: regression in handling of disjunctions #1058

Open
cueckoo opened this issue Jul 3, 2021 · 2 comments
Open

encoding/openapi: regression in handling of disjunctions #1058

cueckoo opened this issue Jul 3, 2021 · 2 comments
Labels

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @eadlam in cuelang/cue#1058

What version of CUE are you using (cue version)?

$ cue version
cue version v0.4.0 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

main.cue

#A: {}
#blocks: a: {a: #A}

#B: {}
#blocks: b: {b: #B}

#Block: or([for k, v in #blocks {v}])
$ cue def main.cue -o openapi:example.openapi.json

What did you expect to see?

Note: this works correctly in v0.4.0-rc.1
example.openapi.json

{
    "openapi": "3.0.0",
    "info": {
        "title": "Generated by cue.",
        "version": "no version"
    },
    "paths": {},
    "components": {
        "schemas": {
            "A": {
                "type": "object"
            },
            "B": {
                "type": "object"
            },
            "Block": {
                "type": "object",
                "oneOf": [
                    {
                        "required": [
                            "a"
                        ],
                        "properties": {
                            "a": {
                                "$ref": "#/components/schemas/A"
                            }
                        }
                    },
                    {
                        "required": [
                            "b"
                        ],
                        "properties": {
                            "b": {
                                "$ref": "#/components/schemas/B"
                            }
                        }
                    }
                ]
            },
            ...
        }
    }
}

What did you see instead?

example.openapi.json

{
    "openapi": "3.0.0",
    "info": {
        "title": "Generated by cue.",
        "version": "no version"
    },
    "paths": {},
    "components": {
        "schemas": {
            "A": {
                "type": "object"
            },
            "B": {
                "type": "object"
            },
            "Block": {
                "type": "object",
                "oneOf": [
                    {
                        "$ref": "#/components/schemas/_.v"
                    },
                    {
                        "$ref": "#/components/schemas/_.v"
                    }
                ]
            },
            ...
        }
    }
}

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @eadlam in cuelang/cue#1058 (comment)

This worked correctly on v0.4.0-rc.1 but fails on v0.4.0.

@myitcv
Copy link
Member

myitcv commented Jul 29, 2021

Thanks very much @eadlam for raising this. Apologies again for the migration-related delay (#1078) in getting round to looking at this.

I can confirm your analysis above:

exec cue export main.cue --out openapi -o openapi.json
cmp openapi.json openapi.json.golden

-- main.cue --
#A: {}

#blocks: a: {a: #A}

#B: {}

#blocks: b: {b: #B}

#Block: or([ for k, v in #blocks {v}])
-- openapi.json.golden --
{
    "openapi": "3.0.0",
    "info": {
        "title": "Generated by cue.",
        "version": "no version"
    },
    "paths": {},
    "components": {
        "schemas": {
            "A": {
                "type": "object"
            },
            "B": {
                "type": "object"
            },
            "Block": {
                "type": "object",
                "oneOf": [
                    {
                        "required": [
                            "a"
                        ],
                        "properties": {
                            "a": {
                                "$ref": "#/components/schemas/A"
                            }
                        }
                    },
                    {
                        "required": [
                            "b"
                        ],
                        "properties": {
                            "b": {
                                "$ref": "#/components/schemas/B"
                            }
                        }
                    }
                ]
            },
            "blocks": {
                "type": "object",
                "properties": {
                    "a": {
                        "type": "object",
                        "required": [
                            "a"
                        ],
                        "properties": {
                            "a": {
                                "$ref": "#/components/schemas/A"
                            }
                        }
                    },
                    "b": {
                        "type": "object",
                        "required": [
                            "b"
                        ],
                        "properties": {
                            "b": {
                                "$ref": "#/components/schemas/B"
                            }
                        }
                    }
                },
                "allOf": [
                    {
                        "required": [
                            "a"
                        ]
                    },
                    {
                        "required": [
                            "b"
                        ]
                    }
                ]
            }
        }
    }
}

Bisected this down to 37bf801.

@myitcv myitcv added M NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Jul 29, 2021
@myitcv myitcv changed the title [regression] cue def openapi fails to handle disjunctions encoding/openapi: regression in handling of disjunctions Jul 29, 2021
@myitcv myitcv removed the M label Oct 26, 2021
@myitcv myitcv added the zGarden label Jun 15, 2023
@mvdan mvdan removed the zGarden label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants