API Platform version(s) affected: 2.5.6 and master
Description
This is an easier problem to work around than the one I reported in #3666 , but thought I'd still make a note of it anyway.
If a certain serializer group only appears in a collection operation, then @id and @type fields are missing from the generated OpenAPI schema. E.g. this:
* @ApiResource(
* normalizationContext={"groups"={"Book:Default"}},
* collectionOperations={
* "get"={
* "normalization_context"={
* "groups"={
* "Book:Collection"
* },
* },
* }
* }
* )
...will lead to a consumer of the OpenAPI schema thinking there are no @id and @type fields for each item in the collection, when in fact there are.
This problem can be solved if Book:Collection were to be added to an itemOperation, because the schema is then shared. However this does introduce another slight bug... it then suggests that the collection includes @context, which it doesn't.
How to reproduce
I've created a reproduction here:
https://github.com/jamesisaac/openapi-bugs
Once running, OpenAPI docs are visible at http://localhost:8000 or http://localhost:8000/docs.json
The /books endpoint according to OpenAPI schemas has no @id or @type attribute, but in reality it does.
Possible Solution
A partial solution would be including @id and @type when the schema comes from a collection.
Although technically, that still doesn't seem perfect, as then you'd have the inconsistency that @context is different between collections and items. I suppose to get this perfect you'd need a different schema for items and collections... not sure that's exactly desirable though as it will lead to even more generated schemas and longer names.
Additional Context
API Platform version(s) affected: 2.5.6 and master
Description
This is an easier problem to work around than the one I reported in #3666 , but thought I'd still make a note of it anyway.
If a certain serializer group only appears in a collection operation, then
@idand@typefields are missing from the generated OpenAPI schema. E.g. this:...will lead to a consumer of the OpenAPI schema thinking there are no
@idand@typefields for each item in the collection, when in fact there are.This problem can be solved if
Book:Collectionwere to be added to an itemOperation, because the schema is then shared. However this does introduce another slight bug... it then suggests that the collection includes@context, which it doesn't.How to reproduce
I've created a reproduction here:
https://github.com/jamesisaac/openapi-bugs
Once running, OpenAPI docs are visible at http://localhost:8000 or http://localhost:8000/docs.json
The
/booksendpoint according to OpenAPI schemas has no@idor@typeattribute, but in reality it does.Possible Solution
A partial solution would be including
@idand@typewhen the schema comes from a collection.Although technically, that still doesn't seem perfect, as then you'd have the inconsistency that
@contextis different between collections and items. I suppose to get this perfect you'd need a different schema for items and collections... not sure that's exactly desirable though as it will lead to even more generated schemas and longer names.Additional Context