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

Example: Implementing Crow with Swagger UI #603

Closed
xia-stan opened this issue Mar 16, 2023 · 5 comments
Closed

Example: Implementing Crow with Swagger UI #603

xia-stan opened this issue Mar 16, 2023 · 5 comments

Comments

@xia-stan
Copy link
Contributor

To keep #585 's message thread clean, I wanted to make this comment to address the question posed about implementing Crow and Swagger UI. The implementation is pretty straight forward. For a long answer, I've made an example repository for reference.

For the quick and dirty answer, define and register a blueprint

crow::Blueprint swag("swagger", "docs/swagger/static", "docs/swagger/templates");
CROW_BP_ROUTE(swag, "/")
  ([]() {
    auto page = crow::mustache::load("swagger.html");
    return page.render();
});

Then point swagger-initializer.js to your OpenAPI yaml file and update Swagger UI's index.html to use the blueprinted paths. Finally, execute your program from the same directory as your blueprint base path definition.

@xia-stan
Copy link
Contributor Author

@julianxhokaxhiu : Here's the answer to the question you posed on #585 .

@julianxhokaxhiu
Copy link

Will check this and let you know if I have more questions on top. But looking through the demo repo looks pretty much self-explanatory. Thanks a lot in the meantime!

@julianxhokaxhiu
Copy link

julianxhokaxhiu commented Mar 19, 2023

@xia-stan I have one question on top of your project. I've seen the whole structure and that's super clear to me. The only part I'm missing is how the Swagger template will pick my endpoints, will I have to declare them manually somewhere or are they going to be auto discovered? Also how is documentation of this API endpoints ( and parameters ) are supposed to work? Do I have to type that manually? Thank you in advance.

//EDIT: I see also this in your documentation point swagger-initializer.js to your OpenAPI yaml file which means at this stage Crow doesn't provide an OpenAPI generator based on top of the APIs we declare in code right? Because Drogon for example does, and I was hoping Crow does offer this functionality as well.

@xia-stan
Copy link
Contributor Author

That's correct. Crow (v1.0+5) doesn't automatically generate the OpenAPI specification file. You have to generate that yourself.

@julianxhokaxhiu
Copy link

Thank you @xia-stan I'll see what I can make out of this. Appreciated :)

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