Code Monkey home page Code Monkey logo

Comments (5)

mtrajano avatar mtrajano commented on July 23, 2024

That is a great idea, I had this in my TODO list. I'll hopefully get to this soon

from laravel-swagger.

sanasol avatar sanasol commented on July 23, 2024

@mtrajano Proof Of Concept with shitty code :D

sanasol#1

Problems

  1. How to get any model with filled data
  2. Have no idea how to fill any resource with full data
  3. Have no idea how to correctly extract that structure from resource
  4. Need deep definition extraction/creation to avoid duplication and creating subresource definitions.
  5. Controller methods can return collection/single resource or even some custom response that contain resource deeply.

from laravel-swagger.

mtrajano avatar mtrajano commented on July 23, 2024

@sanasol thank you so much for submitting a pr for this. I need to think about this one a little more. I'm usually hesitant to include another annotation unless necessary (less bootstrapping needed to get the correct output), do you think it would be possible to rely on the return typehint of a specific Api Resource and leave the @model as is which would instruct which model should be passed into the resource? Also would appreciate some tests at least proving that the implementation works. I'm currently working on cleaning up this branch and trying to add as much test coverage as possible in order to do a more stable release. Thanks!

from laravel-swagger.

sanasol avatar sanasol commented on July 23, 2024

This is very PoC, so it wont work anywhere except my environment.
I tried replace @model with resource until found that need both for make it work somehow.
So with clean implementation it should some kind of @resource + @model.
But now I found out that attaching to resource also is bit useless, since response can be actually with any structure incuding some simple array.

So my current thoughts that need some custom response classes with full response structure written in annotation. i.e. empty classes with response structure and data types.

i.e. it will be just php-written swagger structure with autogeneration or something like.
I didnt see any other possible solutions that will generate swagger with reallife responses automatically.

So in my mind now:

Controller method annotation

/**
* @response App\Responses\ResumeResponse
*/

Response class that linked to some "sub responses"

namespace App\Responses;

class ResumeResponse
{
    public static function generate()
    {
        return [
            'id' => 'number',
            'name' => 'string',
            'experience' => [App\Responses\ExperienceResponse::class], // collection
            'common_skill' => App\Responses\CommonSkillResponse::class, // single object
        ];
    }
}

so ExperienceResponse and CommonSkillResponse have same generate() method inside with some structure.

Actually this is very close to writing full docs manually, but with php syntax.

from laravel-swagger.

mr-feek avatar mr-feek commented on July 23, 2024

I started prototyping a solution for this involving traversing the AST -- mr-feek@8f3bbad

from laravel-swagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.