-
-
Notifications
You must be signed in to change notification settings - Fork 933
Open
Labels
Description
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 setoutput: 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 isGreetingOverviewDto
when it should beGreeting
- 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.
sergiuionescu