knuckleswtf / scribe

Generate API documentation for humans from your Laravel codebase.✍
https://scribe.knuckles.wtf/laravel/
MIT License
1.76k stars 318 forks source link

Can't generate documentation without Content-Type header for custom endpoint #897

Open Kamrul-Haque opened 1 month ago

Kamrul-Haque commented 1 month ago

Scribe version

4.37.2

PHP version

8.3.6

Framework

Laravel

Framework version

11.25.0

Scribe config

title => "Serp API Client"
type => "laravel"
theme => "elements"
try_it_out.enabled => false
try_it_out.base_url => "http://serp-api.test"
auth.enabled => true
auth.name => "Authorization"
auth.placeholder => "{ACCESS_TOKEN}"
postman.enabled => false
openapi.enabled => false
examples.faker_seed => ""
strategies.headers => added [
    'override',
    [
        'Accept' => 'application/json',
    ],
]: removed [
    'override',
    [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
    ],
]

What happened?

custom.0.yml

- httpMethods:
    - POST
  uri: oauth/token
  metadata:
    groupName: Authentication
    groupDescription:
    title: Generate Access Token
    description: 'This endpoint generates access token required to make subsequent requests.'
    authenticated: false
  headers:
    Accept: application/json
  urlParameters:
  queryParameters:
  bodyParameters:
    grant_type:
      name: grant_type
      required: true
      description: "Type of authentication used.<br> Value: <b>client_credentials</b>"
      type: string
    client_id:
      name: client_id
      required: true
      description: Identifies the client consuming the API. Generated & provided by the API server.
      example: '9d259499-c8cc-4c26-a76e-01f4a705816c'
      type: string
    client_secret:
      name: client_secret
      description: Validates the client consuming the API. Generated & provided by the API server.
      required: true
      example: 'soZgyNUwwjxSZ7Z6EDJcvh2a5ZkJcNhnmRjjIuRk'
      type: string
  responses:
    - status: 200
      content: # Your response content can be an object, an array, a string or empty.
        {
          "token_type": "Bearer",
          "expires_in": 31536000,
          "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI5ZDIxZDYxNS0wN2ExLTQ2YTctOWVkMC04Y2EyNjQ4MDA2Y2UiLCJqdGkiOiI3NTcyMmY1MTVkMzBhMWZlYmQyOGFjZWU0YmE2M2VhMzk3NTRmNzhiMmFhNzI3ZmQwN2Y4YTUzNDVjM2VmODFlMjE4MDE0MWZhZWYxODViOCIsImlhdCI6MTcyNzc2MTQwNC42Mzc1NzEsIm5iZiI6MTcyNzc2MTQwNC42Mzc1NzUsImV4cCI6MTc1OTI5NzQwNC42MzQ0MDksInN1YiI6IiIsInNjb3BlcyI6W119.Met3OfcG9DR8ntLdro7kYOhX5HnMnETpcydWKvaEFkgkiXJ0_Ky59lqUeW2ItkmH8mh3Oh_cMd8knQ1jKeNPCm0RB_XWybgMtUsplhye9lM-SCMBRcXtSgsqqEAuKpPqBfDepBz1xsOyCm3EUGxmBC-0CIsJ_aIvNJ1YOUHXiqjBExR-ZnRj3_UWUOFkRFkRzi0U1gXH3mcVvcu2v7wUvqlyBtyVhyNP-zBqseyJetK_iU8WQZwnwkXwlDeIizZ2UDzrpal6UNh8FeYdEu5TUhvJuwjxyav8D_7Apm7TZAIKBb8-lBwkJyKBYPSnCrXh-lGIkKEPdGBT_gPhkuD66iPQFHCvkFWVs6PN8c1xRlSo855D0kYK1qoewgvcofiuM6f_sqKTvF9sTUk27OUv3zrbiThTkYGs2ZM-30yHcF4xUnjhjAszBJZ0uZ6G980AKm9nNr0Rr1BwZPlUQ7PZ9x2Vy9C56AJLfUZwGZ0E53wZsfreLh4_lmxB8t6p9CDKTydjNtimE-b8I8DJ85cMcy2DGI8eEtffEsuxo_vQ1taeYL6XGNANUb16G_Ah2fBj189xYcetKfj9zPATyws8vo5Nm3f7i2LGHh4CD7yu0ltJR-7VQobaW9Mx8muN3jG-bMDd98WIzFWVz8FuLHslLOcL4z6apEYG8OVQVmWWZ4o"
        }

getting error while generating documentation:

 Illuminate\View\ViewException 

  Undefined array key "Content-Type" (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/views/partials/example-requests/php.md.blade.php) (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/views/themes/elements/endpoint.blade.php) (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/views/themes/elements/endpoint.blade.php) (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/views/themes/elements/endpoint.blade.php)

  at storage/framework/views/8969fcdc5c6efa6a9ef21e4b9652b84f.php:38
     34▕ <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
     35▕ <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
     36▕         ],
     37▕ <?php elseif(count($endpoint->cleanBodyParameters)): ?>
  ➜  38▕ <?php if($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded'): ?>
     39▕         'form_params' => <?php echo u::printPhpValue($endpoint->cleanBodyParameters, 8); ?>,
     40▕ <?php else: ?>
     41▕         'json' => <?php echo u::printPhpValue($endpoint->cleanBodyParameters, 8); ?>,
     42▕ <?php endif; ?>

      +1 vendor frames 

  2   storage/framework/views/8969fcdc5c6efa6a9ef21e4b9652b84f.php:38
      Illuminate\View\ViewException::("Undefined array key "Content-Type" (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/views/partials/example-requests/php.md.blade.php) (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/views/themes/elements/endpoint.blade.php) (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/views/themes/elements/endpoint.blade.php)")
      +1 vendor frames 

  4   storage/framework/views/8969fcdc5c6efa6a9ef21e4b9652b84f.php:38
      Illuminate\View\ViewException::("Undefined array key "Content-Type" (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/views/partials/example-requests/php.md.blade.php) (View: /home/kamrul-haque/projects/serp-api/vendor/knuckleswtf/scribe/resources/v

Docs

shalvah commented 3 weeks ago

Is there a reason you don't want to add a Content-Type header to your custom endpoint? It has bodyParameters, so its body must have a content type.