Skip to content

genId false trigger an error on openapi #7162

Open
@monitaurus

Description

@monitaurus

API Platform version(s) affected: 3.4.* (looking at the code, could be also 4.* but not tested)

Description

Having a resource which has a sub resource with a ApiProperty's genId at false generates an error while using command api:openapi:export:

In SchemaFactory.php line 240:

  Notice: Indirect modification of overloaded element of ArrayObject has no effect

How to reproduce

That's the issue, I don't know how I ended up with this.
I tried to replicate this in a fresh APIP 4.1 distrib, but didn't manage to.
I didn't find a 3.4 distrib to test on a clean environment, so I tried to replicate on some professional project.

Investigating via step debug, it seems related to both sub resources and the presence of normalizationContext.
It's like the SchemaFactory generates a sub schema (v3.4 l231) of the sub resource that doesn't contains @id (due to serialization groups?) and then tries to delete it (v3.4 l240) but the @id is not existing then triggering the error.

Possible Solution

In the JsonSchema/SchemaFactory (v3.4 l240, v.4.0 l230, v4.1 l229), add in the condition before removing the @id part, a test of the key to delete:

if (
    isset($subSchema->getDefinitions()[$subDefinitionName])
    && isset($subSchema->getDefinitions()[$subDefinitionName]['properties']['@id'])
) {
    unset($subSchema->getDefinitions()[$subDefinitionName]['properties']['@id']);
}

I can do a PR to fix it, but as I wasn't enable to reproduce it outside of 3.4 I wanted to have some external feedback (cc @soyuka)

Additional Context

Full error:

Error thrown while running command "api:openapi:export --output='docs/swagger_docs.json'". Message: "Notice: Indirect modification of overloaded element of ArrayObject has no effect" ["exception" => ErrorException { …},"command" => "api:openapi:export --output='docs/swagger_docs.json'","message" => "Notice: Indirect modification of overloaded element of ArrayObject has no effect"]

In SchemaFactory.php line 240:

  Notice: Indirect modification of overloaded element of ArrayObject has no effect       

api:openapi:export [-y|--yaml] [-o|--output [OUTPUT]] [--spec-version [SPEC-VERSION]] [--api-gateway]

The quoted code was introduced by 99262dc, which focus on command api:json-schema:generate, but make api:openapi:export fail in the above situation.

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