Add a config option for a default Accept header #117

Merged
merged 3 commits into from Mar 16, 2013

Conversation

Projects
None yet
4 participants
Contributor

gregholland commented Dec 12, 2012

I'm not sure if this is ideal for everyone, but I thought I'd submit the PR anyway.

If an API looks at the HTTP Accept header when deciding what format to return we need to manually enter a header into the sandbox's header field, i.e. application/json, application/xml, etc, this can get a little cumbersome/boring when playing around with multiple services in the sandbox. This PR adds the option to set a default in the config as follows:

# app/config.yml
nelmio_api_doc:
    name: My API
    sandbox:
        accept_type: application/json

You will then by default have that header value already populated in the sandbox field.

PR

Collaborator

willdurand commented Dec 12, 2012

👍

@gordalina gordalina commented on an outdated diff Jan 7, 2013

Resources/views/method.html.twig
@@ -202,6 +202,14 @@
<fieldset class="headers">
<legend>Headers</legend>
+ {% if acceptType %}
+ <p class="tuple">
@gordalina

gordalina Jan 7, 2013

Contributor

Indentation is 4 spaces instead of 2

@gordalina gordalina commented on an outdated diff Jan 7, 2013

Formatter/HtmlFormatter.php
@@ -144,6 +169,7 @@ private function getGlobalVars()
'endpoint' => $this->endpoint,
'enableSandbox' => $this->enableSandbox,
'requestFormatMethod' => $this->requestFormatMethod,
+ 'acceptType' => $this->acceptType,
@gordalina

gordalina Jan 7, 2013

Contributor

Respect alignment please

@gordalina gordalina commented on an outdated diff Jan 7, 2013

Formatter/HtmlFormatter.php
@@ -134,6 +147,18 @@ protected function render(array $collection)
}
/**
+ * {@inheritdoc}
+ */
+ protected function selfRender(array $collection)
+ {
+
@gordalina

gordalina Jan 7, 2013

Contributor

Please align code and have a space between array() and $this->getGlobalVars()
Even though having an extra comma at the end of an array is not an error nothing is gained by having it there.

Contributor

gordalina commented Jan 7, 2013

The README should include this parameter.

@stof stof commented on an outdated diff Jan 7, 2013

Formatter/HtmlFormatter.php
@@ -134,6 +147,18 @@ protected function render(array $collection)
}
/**
+ * {@inheritdoc}
+ */
+ protected function selfRender(array $collection)
+ {
+
+ $merged_data = array_merge(array('resources' => $collection,),$this->getGlobalVars());
+
+ return $merged_data;
@stof

stof Jan 7, 2013

Contributor

Please use camelCased names for variables, and spaces for the indentation

Contributor

gregholland commented Jan 8, 2013

Commit aa44e75 was not meant to be part of this PR, my bad for accidentally committing to my fork while this PR was open. It is useful for me as it allows me to render the docs inside a div on another page. Do you think it would be a useful feature for anyone else?

Contributor

stof commented Jan 8, 2013

@gregholland it is a separate topic anyway. So please remove it from this branch and submit it separately to discuss it.

Contributor

gregholland commented Jan 9, 2013

I've removed the unrelated/accidental commits from this PR. If there is anything else, please let me know.

@willdurand willdurand added a commit that referenced this pull request Mar 16, 2013

@willdurand willdurand Merge pull request #117 from gregholland/master
Add a config option for a default Accept header
026fcc4

@willdurand willdurand merged commit 826fd35 into nelmio:master Mar 16, 2013

Collaborator

willdurand commented Mar 16, 2013

Merged. Thank you @gregholland

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment