Missing 'Accept' => 'application/json'
Scribe version
4.36
Your question
I have this in my config file:
But "Accept" header is missing in result output:
Did i do something wrong ? i need to add default header to all my requests.
Docs
- [x] I've checked the docs, the troubleshooting guide, and existing issues, but I didn't find a solution
Hmmm, that's not right. Do you also have the config key 'routes' => 'apply'?
I am running into this issue as well. I have set routes.apply but I still have the issue.
You actually shouldn't set routes.apply.
Still running into the issue, the headers overrides aren't applied
Weird. I added a test, but I can't reproduce this. Both ways work. https://github.com/knuckleswtf/scribe/commit/a1cb38e76f1e67b198348293768ba872d633e298
@Forsakenrox you use the elements theme right?
If we use the default theme, the override works.
If we use the scalar theme (or like you, the elements theme), the override does not work.
Same Scribe Version 4.36.0
Update If I'm not wrong. The other themes are based on the "true" OpenAPISpec which does not allow to set this headers. See: https://swagger.io/docs/specification/v3_0/describing-parameters/#header-parameters
See: https://github.com/knuckleswtf/scribe/blob/master/src/Writing/OpenAPISpecWriter.php#L178
Ah, if you're using one of the external themes, the behaviour is out of our hands, as those read directly from the OpenAPI spec. The only thing Scribe can do is try to generate compliant specs.
@shalvah I debugged this a bit myself, but from my looks of it, the headers are not actually put into openapi.yaml? I can re-open with a new issue, but looks to be the exact same issue.
What's written inside openapi.yaml
/api/user:
get:
summary: ''
operationId: getApiUser
description: ''
parameters: []
responses:
401:
description: ''
content:
application/json:
schema:
type: object
example:
error_code: unauthorized
message: Unauthorized
success: false
properties:
error_code:
type: string
example: unauthorized
message:
type: string
example: Unauthorized
success:
type: boolean
example: false
tags:
- Endpoints
What's written to collection.json
{
"name": "Endpoints",
"description": "",
"item": [
{
"name": "GET api\/user",
"request": {
"url": {
"host": "{{baseUrl}}",
"path": "api\/user",
"query": [],
"raw": "{{baseUrl}}\/api\/user"
},
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application\/json"
},
{
"key": "Content-Type",
"value": "application\/json"
}
],
"body": null,
"description": ""
},
"response": [
{
"header": [
{
"key": "cache-control",
"value": "no-cache, private"
},
{
"key": "content-type",
"value": "application\/json"
},
{
"key": "access-control-allow-origin",
"value": "*"
}
],
"code": 401,
"body": "{\"error_code\":\"unauthorized\",\"message\":\"Unauthorized\",\"success\":false}",
"name": ""
}
]
},
What's written to 00.yaml
endpoints:
-
httpMethods:
- GET
uri: api/user
metadata:
groupName: Endpoints
groupDescription: ''
subgroup: ''
subgroupDescription: ''
title: ''
description: ''
authenticated: true
custom: []
headers:
Authorization: 'Bearer {YOUR_AUTH_KEY}'
Content-Type: application/json
Accept: application/json
urlParameters: []
cleanUrlParameters: []
queryParameters: []
cleanQueryParameters: []
bodyParameters: []
cleanBodyParameters: []
fileParameters: []
responses:
-
status: 401
content: '{"error_code":"unauthorized","message":"Unauthorized","success":false}'
headers:
cache-control: 'no-cache, private'
content-type: application/json
access-control-allow-origin: '*'
description: null
custom: []
They're probably not, and that might be due to some restrictions by the OPEN API spec. Please look into it further and see if there's actually something missing, or this is what the spec expects. If we're missing something, I'll welcome a PR.
Ok, looked further into it. You are right, openapi mentions they are "not allowed". However when testing with different providers no exceptions are actually thrown, the invalid use-case is just highlighted like a typo.
I opened an issue with scalar. Thanks for the insight.
I'll link the scalar issue for others too: https://github.com/scalar/scalar/issues/5705