knuckleswtf / scribe

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

Custom Endpoint Scenario 1 bug with generate #752

Open Nicolas-Mousten-WeCode opened 8 months ago

Nicolas-Mousten-WeCode commented 8 months ago

Scribe version

4.25

PHP version

8.2.9

Framework

Laravel

Framework version

9

Scribe config

title => "SC Tracker API Documentation"
base_url => "https://localhost:8000/"
type => "laravel"
try_it_out.enabled => false
try_it_out.base_url => "http://127.0.0.1:8000"
auth.enabled => true
auth.name => "Authorization"
auth.placeholder => "{ACCESS_TOKEN}"
translations => "en"

What happened?

I have run scribe:generate and produced the yaml files. i changed the one named 0.yaml where i removed some body parameters data and replaced with an empty string, then i ran generate again and the changes were respected and not changed. but if i make some new changes and run the command again it dosen't respect the changes anymore, so if you make some changes and then run 2 generate commands after each other then they remove the changes.

Docs

shalvah commented 8 months ago

Let me get this straight:

Odd. Can you share an example of the YAML contents and the changes you're making? (It's also possible there might be an easier way to make those changes.)

Nicolas-Mousten-WeCode commented 8 months ago

The file i changed by replacing the body parameter with empty array:

httpMethods:
      - DELETE
    uri: 'reseller-api/v1/agreements/{uuid}'
    metadata:
      groupName: Endpoints
      groupDescription: ''
      subgroup: ''
      subgroupDescription: ''
      title: ''
      description: ''
      authenticated: true
      custom: []
    headers:
      Authorization: 'Bearer {ACCESS_TOKEN}'
      Content-Type: application/json
      Accept: application/json
    urlParameters:
      uuid:
        name: uuid
        description: ''
        required: true
        example: b7643176-eab3-3375-8fa3-4d5e0c0cf4a0
        type: string
        enumValues: []
        custom: []
    cleanUrlParameters:
      uuid: b7643176-eab3-3375-8fa3-4d5e0c0cf4a0
    queryParameters: []
    cleanQueryParameters: []
    bodyParameters: []
    cleanBodyParameters:
      uuid: 2f6c2919-6b50-3a5e-af04-44042b8c13f9
      status: sunt
    fileParameters: []
    responses:
      -
        status: 200
        content: '{"data":{"id":"f41fbc81-2f42-452b-b9f4-764a59df65a0","type":"Flexleasing","status":"Oprettet","has_driver_book":false,"customer":{"id":"0dfeabf5-fef1-426d-99dd-d5153689eac8","name":"Kuphal Ltd","contact_person_email":"kkonopelski@luettgen.com","contact_person_phone":"25451062","created_at":"2023-10-19 15:19:51"}}}'
        headers: []
        description: ''
        custom: []
    responseFields: []
    auth:
      - headers
      - Authorization
    controller: null
    method: null
    route: null
    custom: []
  -

Then i run the command "php artisan scribe:generate --no-interaction" one time and it keeps the changes, but then after i run the command again it returns to this:

httpMethods:
      - DELETE
    uri: 'reseller-api/v1/agreements/{uuid}'
    metadata:
      groupName: Endpoints
      groupDescription: ''
      subgroup: ''
      subgroupDescription: ''
      title: ''
      description: ''
      authenticated: true
      custom: []
    headers:
      Authorization: 'Bearer {ACCESS_TOKEN}'
      Content-Type: application/json
      Accept: application/json
    urlParameters:
      uuid:
        name: uuid
        description: ''
        required: true
        example: 89db235b-ed4a-3d47-86ca-6d706ef34f40
        type: string
        enumValues: []
        custom: []
    cleanUrlParameters:
      uuid: 89db235b-ed4a-3d47-86ca-6d706ef34f40
    queryParameters: []
    cleanQueryParameters: []
    bodyParameters:
      uuid:
        name: uuid
        description: ''
        required: false
        example: 97f22934-f8ed-3f98-a3f1-dcd6a094a352
        type: integer
        enumValues: []
        custom: []
      status:
        name: status
        description: ''
        required: false
        example: et
        type: String
        enumValues: []
        custom: []
    cleanBodyParameters:
      uuid: 97f22934-f8ed-3f98-a3f1-dcd6a094a352
      status: et
    fileParameters: []
    responses:
      -
        status: 200
        content: '{"data":{"id":"e38ca50f-545b-4df6-b07c-20194f3fedb9","type":"Flexleasing","status":"Oprettet","has_driver_book":false,"customer":{"id":"db78c211-fda5-4523-804f-647946c4ed75","name":"Beatty-Vandervort","contact_person_email":"malinda.wuckert@hotmail.com","contact_person_phone":"85700999","created_at":"2023-10-20 08:31:47"}}}'
        headers: []
        description: ''
        custom: []
    responseFields: []
    auth:
      - headers
      - Authorization
    controller: null
    method: null
    route: null
    custom: []
  -

i have added no phpdoc to the function since i could not find any annotation that works for hiding the body parameter:

#[UrlParam('uuid', 'string')]
    #[ResponseFromApiResource(ResellerCustomerAgreementResource::class, CustomerAgreement::class, with: ['customer'])]
    public function destroy(string $uuid, DeleteResellerCustomerAgreementRequest $request): SuccessfulResponse
    {
        $agreement = CustomerAgreement::query()
            ->where('uuid', $uuid)
            ->with('customer')
            ->first();

        $this->authorize('accessAgreement', [$request->get('reseller'), $agreement]);

        $this->deleteAgreement->execute($agreement);

        return new SuccessfulResponse(
            message: 'Aftale slettet'
        );
    }