Skip to content

gen-php: anyOf/oneOf #39

@massadm

Description

@massadm

https://github.com/swaggest/json-cli/releases/tag/v1.11.0

While gen-markdown works as expected, gen-php does not.

Schema:

{
    "id": "/Test",
    "type": "object",
    "properties": {
        "label": {
            "anyOf": [
                {
                    "type": "integer"
                },
                {
                    "type": "number"
                },
                {
                    "type": "object",
                    "properties": {
                        "test1": {
                            "type": "string"
                        }
                    }
                },
                {
                    "type": "object",
                    "properties": {
                        "test2": {
                            "type": "string"
                        }
                    }
                }
            ]
        },
        "label2": {
            "oneOf": [
                {
                    "type": "integer"
                },
                {
                    "type": "number"
                },
                {
                    "type": "object",
                    "properties": {
                        "test1": {
                            "type": "string"
                        }
                    }
                },
                {
                    "type": "object",
                    "properties": {
                        "test2": {
                            "type": "string"
                        }
                    }
                }
            ]
        }
    }
}

ClassStructure:

    public static function setUpProperties($properties, Schema $ownerSchema)
    {
        $properties->label = new Schema();
        $properties->label->anyOf[0] = Schema::integer();
        $properties->label->anyOf[1] = Schema::number();
        $properties->label->anyOf[2] = Label::schema();
        $properties->label->anyOf[3] = Label::schema();
        $properties->label2 = new Schema();
        $properties->label2->oneOf[0] = Schema::integer();
        $properties->label2->oneOf[1] = Schema::number();
        $properties->label2->oneOf[2] = Label2::schema();
        $properties->label2->oneOf[3] = Label2::schema();
        $ownerSchema->type = Schema::OBJECT;
        $ownerSchema->id = "/Test";
    }

Note: $properties->label->anyOf[2] eq $properties->label->anyOf[3] and $properties->label2->oneOf[2] eq $properties->label2->oneOf[3]. No issues for $ownerSchema (tested), only $properties affected.

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