scribe icon indicating copy to clipboard operation
scribe copied to clipboard

Missing 'Accept' => 'application/json'

Open Forsakenrox opened this issue 1 year ago • 5 comments

Scribe version

4.36

Your question

I have this in my config file: image But "Accept" header is missing in result output: image Did i do something wrong ? i need to add default header to all my requests.

Docs

Forsakenrox avatar Jun 06 '24 16:06 Forsakenrox

Hmmm, that's not right. Do you also have the config key 'routes' => 'apply'?

shalvah avatar Jun 10 '24 20:06 shalvah

I am running into this issue as well. I have set routes.apply but I still have the issue.

emaadali avatar Jun 11 '24 15:06 emaadali

You actually shouldn't set routes.apply.

shalvah avatar Jun 14 '24 17:06 shalvah

Still running into the issue, the headers overrides aren't applied

emaadali avatar Jun 14 '24 17:06 emaadali

Weird. I added a test, but I can't reproduce this. Both ways work. https://github.com/knuckleswtf/scribe/commit/a1cb38e76f1e67b198348293768ba872d633e298

shalvah avatar Jun 17 '24 19:06 shalvah

@Forsakenrox you use the elements theme right? If we use the default theme, the override works. Screenshot 2024-10-25 at 10 37 57

If we use the scalar theme (or like you, the elements theme), the override does not work. Screenshot 2024-10-25 at 10 36 41

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

AryaSvitkona avatar Oct 25 '24 08:10 AryaSvitkona

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 avatar Nov 05 '24 21:11 shalvah

@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.

KasparRosin avatar May 21 '25 11:05 KasparRosin

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: []

KasparRosin avatar May 21 '25 11:05 KasparRosin

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.

shalvah avatar May 21 '25 18:05 shalvah

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.

KasparRosin avatar May 22 '25 10:05 KasparRosin

I'll link the scalar issue for others too: https://github.com/scalar/scalar/issues/5705

KasparRosin avatar Jul 09 '25 13:07 KasparRosin