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

[JsonSchema] Property nullable or reference an object #352

Closed
Jibbarth opened this issue Jul 8, 2020 · 2 comments · Fixed by #595
Closed

[JsonSchema] Property nullable or reference an object #352

Jibbarth opened this issue Jul 8, 2020 · 2 comments · Fixed by #595
Labels

Comments

@Jibbarth
Copy link

Jibbarth commented Jul 8, 2020

Jane version(s) affected: 6.0.2

Description
For a given json-schema, I have a property that can be null or reference an other object.

The code generated add MyObject|null in phpdoc, but not in typehint for function : ->getProp(): MyObject (instead of ->getProp(): ?MyObject

How to reproduce

Reproduced with this json-schema

{
    "id": "Test",
    "type": "object",
    "properties": {
        "id": {
            "oneOf": [
                {"type": "null"},
                {"$ref": "#/definitions/id"}
            ]
        }
    },
    "definitions": {
        "id": {
            "properties": {
                "uuid": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    }
}

Additional context

Note, I also tested with following JSON

{
    "id": "Test",
    "type": "object",
    "properties": {
        "id": {
            "type": ["object", "null"],
            "allOf": [
                {"$ref": "#/definitions/id"}
            ]
        }
    },
    "definitions": {
        "id": {
            "properties": {
                "uuid": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    }
}

For getter and setter in my Test model, it works :

    /**
     * @return TestId|null
     */
    public function getId() : ?TestId
    {
        return $this->id;
    }
    /**
     * @param TestId|null $id
     *
     * @return self
     */
    public function setId(?TestId $id) : self
    {
        $this->id = $id;
        return $this;
    }

But I have two model generated for Id, a TestId and a Id.
I would expect that only generate the Id one.

Thank in advance 🙂

@Jibbarth Jibbarth added the bug label Jul 8, 2020
@oleg-andreyev
Copy link
Contributor

Ref.: OAI/OpenAPI-Specification#1368

@Gounlaf
Copy link
Contributor

Gounlaf commented Feb 2, 2022

Still present in v7. I will try to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants