-
-
Notifications
You must be signed in to change notification settings - Fork 918
fix(jsonschema): generation of non-LD+JSON distinct schema formats #6236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
236a116
4b16ba7
e3f0e4f
096ead1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,7 +24,7 @@ | |||||||||||||||||||||||||||||||||
* @author Kévin Dunglas <[email protected]> | ||||||||||||||||||||||||||||||||||
* @author Jachim Coudenys <[email protected]> | ||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||
final class SchemaFactory implements SchemaFactoryInterface | ||||||||||||||||||||||||||||||||||
final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareInterface | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
private const HREF_PROP = [ | ||||||||||||||||||||||||||||||||||
'href' => [ | ||||||||||||||||||||||||||||||||||
|
@@ -46,7 +46,6 @@ final class SchemaFactory implements SchemaFactoryInterface | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public function __construct(private readonly SchemaFactoryInterface $schemaFactory) | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
$this->addDistinctFormat('jsonhal'); | ||||||||||||||||||||||||||||||||||
if ($this->schemaFactory instanceof SchemaFactoryAwareInterface) { | ||||||||||||||||||||||||||||||||||
$this->schemaFactory->setSchemaFactory($this); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
@@ -79,8 +78,18 @@ public function buildSchema(string $className, string $format = 'jsonhal', strin | |||||||||||||||||||||||||||||||||
$schema['type'] = 'object'; | ||||||||||||||||||||||||||||||||||
$schema['properties'] = [ | ||||||||||||||||||||||||||||||||||
'_embedded' => [ | ||||||||||||||||||||||||||||||||||
'type' => 'array', | ||||||||||||||||||||||||||||||||||
'items' => $items, | ||||||||||||||||||||||||||||||||||
'anyOf' => [ | ||||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||||
'type' => 'object', | ||||||||||||||||||||||||||||||||||
'properties' => [ | ||||||||||||||||||||||||||||||||||
'item' => [ | ||||||||||||||||||||||||||||||||||
'type' => 'array', | ||||||||||||||||||||||||||||||||||
'items' => $items, | ||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||
['type' => 'object'], | ||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something's bothering me here I need to check that, I don't understand why we put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduced in #4357, as was There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://datatracker.ietf.org/doc/html/draft-kelly-json-hal#section-4.1.2
can you revert this change? I think that our HAL representation always uses an array and we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't that make the behaviour in core/src/Hal/Serializer/CollectionNormalizer.php Lines 86 to 100 in 874e4d6
The changes in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From https://datatracker.ietf.org/doc/html/draft-kelly-json-hal#section-6 {
"_links": {
"self": { "href": "/orders" },
"next": { "href": "/orders?page=2" },
"find": { "href": "/orders{?id}", "templated": true }
},
"_embedded": {
"orders": [{
"_links": {
"self": { "href": "/orders/123" },
"basket": { "href": "/baskets/98712" },
"customer": { "href": "/customers/7809" }
},
"total": 30.00,
"currency": "USD",
"status": "shipped",
},{
"_links": {
"self": { "href": "/orders/124" },
"basket": { "href": "/baskets/97213" },
"customer": { "href": "/customers/12369" }
},
"total": 20.00,
"currency": "USD",
"status": "processing"
}]
},
"currentlyProcessing": 14,
"shippedToday": 20
} Which also comes back to a previous question as to the key(s) of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be correct the schema should be
item as I see it.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in how I did it originally in 97f7dff? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh, never mind, it clicked what you meant … now (I think) I get you 😇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking too hard at the same thing for too long and got my brain in a twist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now we may have (as this is what we use for our collections and):
Although the spec says that it can also be
I'm okay with adding it if you want |
||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||
'totalItems' => [ | ||||||||||||||||||||||||||||||||||
'type' => 'integer', | ||||||||||||||||||||||||||||||||||
|
@@ -127,10 +136,10 @@ public function buildSchema(string $className, string $format = 'jsonhal', strin | |||||||||||||||||||||||||||||||||
return $schema; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public function addDistinctFormat(string $format): void | ||||||||||||||||||||||||||||||||||
public function setSchemaFactory(SchemaFactoryInterface $schemaFactory): void | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
if (method_exists($this->schemaFactory, 'addDistinctFormat')) { | ||||||||||||||||||||||||||||||||||
$this->schemaFactory->addDistinctFormat($format); | ||||||||||||||||||||||||||||||||||
if ($this->schemaFactory instanceof SchemaFactoryAwareInterface) { | ||||||||||||||||||||||||||||||||||
$this->schemaFactory->setSchemaFactory($schemaFactory); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
|
||
use ApiPlatform\JsonLd\ContextBuilder; | ||
use ApiPlatform\JsonSchema\Schema; | ||
use ApiPlatform\JsonSchema\SchemaFactory as BaseSchemaFactory; | ||
use ApiPlatform\JsonSchema\SchemaFactoryAwareInterface; | ||
use ApiPlatform\JsonSchema\SchemaFactoryInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
|
@@ -25,7 +24,7 @@ | |
* | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
final class SchemaFactory implements SchemaFactoryInterface | ||
final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareInterface | ||
{ | ||
private const BASE_PROP = [ | ||
'readOnly' => true, | ||
|
@@ -60,7 +59,6 @@ final class SchemaFactory implements SchemaFactoryInterface | |
|
||
public function __construct(private readonly SchemaFactoryInterface $schemaFactory) | ||
{ | ||
$this->addDistinctFormat('jsonld'); | ||
if ($this->schemaFactory instanceof SchemaFactoryAwareInterface) { | ||
$this->schemaFactory->setSchemaFactory($this); | ||
} | ||
|
@@ -184,10 +182,10 @@ public function buildSchema(string $className, string $format = 'jsonld', string | |
return $schema; | ||
} | ||
|
||
public function addDistinctFormat(string $format): void | ||
public function setSchemaFactory(SchemaFactoryInterface $schemaFactory): void | ||
{ | ||
if ($this->schemaFactory instanceof BaseSchemaFactory) { | ||
$this->schemaFactory->addDistinctFormat($format); | ||
if ($this->schemaFactory instanceof SchemaFactoryAwareInterface) { | ||
$this->schemaFactory->setSchemaFactory($schemaFactory); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.