dedoc / scramble

Modern Laravel OpenAPI (Swagger) documentation generator. No PHPDoc annotations required.
https://scramble.dedoc.co/
MIT License
1.24k stars 119 forks source link

Add a way to document model attributes with description, examples, etc. #453

Open sNok3 opened 4 months ago

sNok3 commented 4 months ago

As the title suggests, when generating the docs for a controller which has model binding, the schema for the model will result in just the fields that the model has, without the annotations it has.

romalytvynenko commented 4 months ago

@sNok3 please share the example of your code and resulting docs. Also would be great to understand what your expected

sNok3 commented 4 months ago
image
class Driver extends Model
{
    use HasFactory;
    use HasStatuses;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        /**
         * The internal ID of the associated route
         *
         * @var int
         *
         * @example 1
         */
        'route_id',
        /**
         * The identifier of the activity
         *
         * @example 3d4b6f0e-2b0b-4b0b-8b4b-0b2b4b0b2b4b
         */
        'identifier'
   ];

So as you can see, I have annotations for both fields here, but under the schemas, there are is no information about the model.

image
romalytvynenko commented 4 months ago

@sNok3 ooh, gotcha. So basically you want to annotate the model fields with descriptions and examples?

Currently this is not supported.

You can use API resources and there you can add the descriptions.

However, I'll keep this issue open to add this possibility in future.

sNok3 commented 4 months ago

Yeah, that is exactly what I needed. However, using API resources in the controller method isn't really my way to go for now since I have a big codebase.

However, I'll gladly wait for this to get implemented!