Skip to content

Using hashmaps produces invalid openapi schema #6800

@ostrolucky

Description

@ostrolucky

API Platform version(s) affected: 4.0.9

Description

How to reproduce

#[ApiResource]
class Test {
    /** @var array<string, Foo> */
    public array $foos;
}

class Foo {
    public string $bar;
}

above produces schema like so

"Test": {
  "type": "object",
  "description": "",
  "deprecated": false,
  "properties": {
    "foos": {
      "type": "object",
      "additionalProperties": {
        "type": "unknown_type"
      }
    }
  }
},

since "unknown_type" isn't actually recognized by OpenAPI, openapi schema validators will reject this kind of schema.

Instead, I would expect it generates schema like so

"Test": {
  "type": "object",
  "description": "",
  "deprecated": false,
  "properties": {
    "foos": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {"bar": {"type": "string"}}
      }
    }
  }
},

Possible Solution

Additional Context

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