-
-
Notifications
You must be signed in to change notification settings - Fork 899
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
fix(hydra): use correctly enable_docs #7062
base: 4.1
Are you sure you want to change the base?
Conversation
9a5eac4
to
b7033a4
Compare
@@ -111,7 +111,11 @@ public function load(array $configs, ContainerBuilder $container): void | |||
$formats = $this->getFormats($config['formats']); | |||
$patchFormats = $this->getFormats($config['patch_formats']); | |||
$errorFormats = $this->getFormats($config['error_formats']); | |||
$docsFormats = $this->getFormats($config['docs_formats']); | |||
// JSON-LD documentation format is mandatory, even if documentation is disabled. | |||
$docsFormats = ['jsonld' => ['application/ld+json']]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be the defaults only if jsonld is actually in the formats
(isset($formats['jsonld'])
)
@@ -65,8 +67,9 @@ public function normalize(mixed $object, ?string $format = null, array $context | |||
$classes = []; | |||
$entrypointProperties = []; | |||
$hydraPrefix = $this->getHydraPrefix($context + $this->defaultContext); | |||
$resourceClasses = $this->docsEnabled ? $object->getResourceNameCollection() : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this could be a single configuration like:
defaults:
hideHydraOperation: true
since 12c4209
$hydraPrefix.'returns' => 'Entrypoint', | ||
], | ||
]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's quite weird to have an API with hydra that's not discoverable but nothing in the spec says we can't. We should check whether the Link
is sent when entrypointEnabled
is set to false
(I think we do).
@@ -538,11 +542,6 @@ private function registerJsonLdHydraConfiguration(ContainerBuilder $container, a | |||
if (!$container->has('api_platform.json_schema.schema_factory')) { | |||
$container->removeDefinition('api_platform.hydra.json_schema.schema_factory'); | |||
} | |||
|
|||
if (!$config['enable_docs']) { | |||
$container->removeDefinition('api_platform.hydra.listener.response.add_link_header'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should check if the operation has hideHydraOperation
directly we can do this inside the listener to avoid playing with DI
This PR aims to fix definitively a recurring issue: JSON-LD documentation is mandatory but users don't want to expose their endpoints when the API is private: #1568
The
enable_docs
configuration parameter removes theapi_doc
route: the documentation is not exposed anymore, but the URL is needed in some parts of the API Platform code: JSON-LD context, Hydra links, etc.It regularly causes some bugs.
A relating PR was done in 2018:
#1731
This PR was removing the code adding the Hydra headers when the docs is disabled.
IMO @dunglas's comment was right:
In 2023 another PRs were done but never merged:
#5676
#5862
@dunglas's comments were having the same point:
#5676 (comment)
#5862 (comment)
My proposal:
enable_docs
is set tofalse
, only thejsonld
documentation format is registered.enable_docs
isfalse
,hydra:supportedClass
is not filled: the API resources are not included in the documentation but all the other keys stay (@context
,@vocab
...).enable_entrypoint
set tofalse
), the entrypoint is not added tohydra:entrypoint
andhydra:supportedClass
.