Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placing annotations in external files #619

Open
BigBlockStudios opened this issue Aug 23, 2024 · 3 comments
Open

Placing annotations in external files #619

BigBlockStudios opened this issue Aug 23, 2024 · 3 comments

Comments

@BigBlockStudios
Copy link

  • L5-Swagger Version: 8.6.1
  • PHP Version: 8.2.22
  • OS: Ubuntu

Description:

Annotations placed in external files not read.
I would like to place annotations in external files beside the class/models/resources/etc. Creating a User.php model/class and an annotation file beside it UserAnnotation.php with just the annotation in it is ignored. No errors are thrown.
It appears that only php files with annotations are scanned if there is a matching class or method declaration.

Steps To Reproduce:

Create a file with class Foo.php
Create a file FooAnnotation.php containing only the annotation block.

@DerManoMann
Copy link

Correct. The annotations need a class, interface or class-like. Those can be empty dummy classes.
https://zircote.github.io/swagger-php/guide/faq.html#warning-required-oa-info-not-found

@BigBlockStudios
Copy link
Author

Thanks - I did find and read that little bit and wondered if your package was doing something different ... I did try the dummy class several times but the annotations were not getting picked up.

What did finally work was adding the namespace to the dummy class...

`<?php

namespace App\Models;

/**

  • @OA\Schema(
  • schema="Project",
    
  • type="object",
    
  • required={"title", "creator_id"},
    
  • @OA\Property(
    
  •     property="id",
    
  •     type="integer",
    
  •     example=1
    
  • ),
    
  • @OA\Property(
    
  •     property="title",
    
  •     type="string",
    
  •     example="Project Title"
    
  • )
    
  • )
    */
    class ProjectAnnotation
    {

}`

should have been obvious I suppose.

@DerManoMann
Copy link

Correct. For reflection to work the classes need to be Auto loadable and that requires correct namespaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants