Skip to content

[JsonSchema] v3.1.6 regression - modifying output to a DTO can cause infinite loop in schema types #5626

@jamesisaac

Description

@jamesisaac

API Platform version(s) affected: 3.1.6 up to latest

Description

v3.1.6 has introduced an issue in how references in the JsonSchema are calculated, which can lead to incorrect types in the OpenApi schema (and ultimately an infinite loop of types).

  • For one of the GET operations of my resource (GET /greetings/1), I want the output to be represented as a DTO which contains the resource itself, and some additional fields, so I set output: GreetingOverviewDto::class on the Operation.
  • Starting in v3.1.6, the type given for the $greeting field in the OpenApi docs is incorrect - the schema states that its type is GreetingOverviewDto when it should be Greeting
  • So as well as being incorrect type, it results in an infinite loop when trying to analyse the types, as it's referencing itself.

How to reproduce

I've created a minimal repro here: https://github.com/jamesisaac/apip-3.1.6-bug-jsonschema

Open up http://localhost:8000/docs.json and look at the following location in the json:

paths:
  /greetings/{id}:
    get:
      responses:
        200:
          content:
            application/ld+json
              schema:
                $ref: "#/components/schemas/Greeting.GreetingOverviewDto.jsonld-Advanced"

components:
  schemas:
    Greeting.GreetingOverviewDto.jsonld-Advanced:
      properties:
        greeting:
          $ref: "#/components/schemas/Greeting.GreetingOverviewDto.jsonld-Advanced"

The above is self-referencing back to the DTO.

Downgrade to 3.1.5 and it works correctly:

$ref: "#/components/schemas/Greeting.jsonld-Advanced"

Possible Solution

Specifically, this PR seems to have introduced the issue: #5469

By reverting the changes to SchemaFactory, it starts working again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions