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

model swagger error after publish template to resource #413

Closed
LarryZhang opened this issue Apr 17, 2017 · 14 comments
Closed

model swagger error after publish template to resource #413

LarryZhang opened this issue Apr 17, 2017 · 14 comments

Comments

@LarryZhang
Copy link

I am trying to generate model swagger docs, and I found that final model file has error . then I figure out that $template = get_template('model.model', 'swagger-generator');
will get the model.model from the /resources/infyom/infyom-generator-templates/model/model.stub
and I think this is big error

@LarryZhang
Copy link
Author

#334 same issue

@dukenst2006
Copy link

What's the swagger URL, to have API documentation?
Try to use those:
www.example.com/docs <- swagger JSON files are visible
www.example.com/api-docs <- swagger ui is visible.
It's give Error NotFoundHttpException

@skys215
Copy link
Contributor

skys215 commented Oct 11, 2017

@dukenst2006
First of all, you need use the swagger-generator from infyom. But this package just add the swagger documentation in to the code. You need another package to browse them.

Install swaggervel package from https://github.com/slampenny/Swaggervel.

Add Jlapp\Swaggervel\SwaggervelServiceProvider::class in to the Provider section in the config/app.php.

Run vendor publish. php artisan vendor:publish --provider="Jlapp\Swaggervel\SwaggervelServiceProvider" (If your laravel version is 5.5, then you can typephp artisan vendor:publish only. It will ask you to select which provider you want to publish).

After that, you can browse /api/docs and /docs.

But, it still doesn't support Laravel v5.4+. To use under Laravel v5.4+, you need to manually delete two lines in the L51-52 or check the laravel version first as mentioned here.

@skys215
Copy link
Contributor

skys215 commented Oct 11, 2017

@LarryZhang
I found the same problem too.
Still finding for workarounds.

@skys215
Copy link
Contributor

skys215 commented Oct 23, 2017

@mitulgolakiya
Is this issue going to solve?

@mitulgolakiya
Copy link
Member

@skys215 we have new year holidays here. I will check it this weekend and will see if I can resolve it quickly.

@skys215
Copy link
Contributor

skys215 commented Oct 24, 2017

Currently I'm changing the helpers.php in the vendors file until the author fixes this problem.
Change get_template_file_path function like this:

    function get_template_file_path($templateName, $templateType = 'infyom-generator-templates')
    {
        $templateName = str_replace('.', '/', $templateName);

        $templatesPath = base_path('resources/infyom/'.$templateType.'/');

        $path = $templatesPath.$templateName.'.stub';

        if (file_exists($path)) {
            return $path;
        }

        return base_path('vendor/infyomlabs/'.$templateType.'/templates/'.$templateName.'.stub');
    }

Updated:
Actually this doesn't work too. Because sometime laravel-generator was passed as the templateType. The problem is, when using vendor:publish, the copied directory name is infyom-generator-templates, but it's called laravel-generator in the vendor directory.

So I changed like this:

    function get_template_file_path($templateName, $templateType = 'infyom-generator-templates')
    {
        $templateName = str_replace('.', '/', $templateName);

        if($templateType == 'laravel-generator'){
            $templateType = 'infyom-generator-templates';
        }

        $templatesPath = base_path('resources/infyom/'.$templateType.'/');

        $path = $templatesPath.$templateName.'.stub';

        if (file_exists($path)) {
            return $path;
        }

        if($templateType == 'infyom-generator-templates'){
            $templateType = 'laravel-generator';
        }

        return base_path('vendor/infyomlabs/'.$templateType.'/templates/'.$templateName.'.stub');
    }

Checked the templateType before file_exists.
Of course, it's not best approach, just a simple ugly workaround until the author fixes the problem.

Updated:
Still have bug, sometime $templateType is passed as adminlte-templates and the problem remains. So I have added it to if condition:

    function get_template_file_path($templateName, $templateType = 'infyom-generator-templates')
    {
        $templateName = str_replace('.', '/', $templateName);

        if ($templateType == 'laravel-generator' || $templateType == 'adminlte-templates') {
            $old_templateType = $templateType;
            $templateType = 'infyom-generator-templates';
        }

        $templatesPath = base_path('resources/infyom/' . $templateType . '/');

        $path = $templatesPath . $templateName . '.stub';

        if (file_exists($path)) {
            return $path;
        }
        dump($path . ' not exists' . "\n");

        if ($templateType == 'infyom-generator-templates') {
            $templateType = $old_templateType;
        }

        return base_path('vendor/infyomlabs/' . $templateType . '/templates/' . $templateName . '.stub');
    }

Actually, $templatesPath should be get from templateDir of the config/infyom/laravel_generator.php.

@skys215
Copy link
Contributor

skys215 commented Nov 21, 2017

@mitulgolakiya
How is it going?
Any solutions for this? Or need to refactor more code which is related to this issue, so would take more time to fix it?

@mitulgolakiya
Copy link
Member

mitulgolakiya commented Nov 21, 2017

@skys215 I have just fixed template error. It seems like slampenny/Swaggervel is no longer maintained. so not sure how can I fix 5.4 support. I am planning to have updated swagger ui package this weekend and will let you know once it's done.

@skys215
Copy link
Contributor

skys215 commented Nov 21, 2017

Ok, I'll have a check of new commits.

@gelinger777
Copy link

@mitulgolakiya are you sure you have fixed the problem? I have configured slampenny/Swaggervel and did publish but seems in /vendor/swaggervel folder which is in the /public folder js and css files are missing

GET https://apitest.localhost/vendor/swaggervel/swagger-ui.css net::ERR_ABORTED 404 (Not Found)
docs:69 GET https://apitest.localhost/vendor/swaggervel/swagger-ui-bundle.js net::ERR_ABORTED 404 (Not Found)
docs:70 GET https://apitest.localhost/vendor/swaggervel/swagger-ui-standalone-preset.js net::ERR_ABORTED 404 (Not Found)
docs:75 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at window.onload (docs:75)
window.onload @ docs:75
load (async)
(anonymous) @ docs:73
favicon-32x32.png:1 GET https://apitest.localhost/vendor/swaggervel/favicon-32x32.png 404 (Not Found)
favicon-16x16.png:1 GET https://apitest.localhost/vendor/swaggervel/favicon-16x16.png 404 (Not Found)


@mitulgolakiya
Copy link
Member

mitulgolakiya commented Dec 5, 2018

@gelinger777 I would say you give a try to use this new package appointer/swaggervel as per this issue #579 and it was reported that it works well.

@gelinger777
Copy link

gelinger777 commented Dec 5, 2018

@mitulgolakiya yes, you are right. In the docs you left the old name of the package. It messed me up a bit things.

http://labs.infyom.com/laravelgenerator/docs/5.7/generator-options here you can find jlapp/swaggervel and wrong link
Please fix .
image

@mitulgolakiya
Copy link
Member

@gelinger777 good finding. I updated it but in installation step only. Updated the docs everywhere now.

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

No branches or pull requests

5 participants