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: manually serving the OpenAPI doc #855

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

NexVeridian
Copy link

  • serves the OpenAPI doc using swagger, redoc, and scalar
  • uses utoipa-axum to auto collect the schemas which is slightly different compared to 320ebbf
  • adds OpenAPI to auth

@NexVeridian NexVeridian force-pushed the Serving-the-OpenAPI-doc branch from e24885c to 9e01579 Compare October 26, 2024 00:51
@NexVeridian NexVeridian force-pushed the Serving-the-OpenAPI-doc branch from 9e01579 to 912d218 Compare October 26, 2024 00:58
Copy link
Contributor

@DenuxPlays DenuxPlays left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still missing a SecurityAddon like here.

Without it you cannot access secured routes.

@DenuxPlays
Copy link
Contributor

DenuxPlays commented Nov 7, 2024

Also wouldn't it be possible to integrate the utoipa-axum crate into the Routes struct and put it behind a feature flag?
That I do not have to have two functions where I have to list all the routes.

@NexVeridian NexVeridian marked this pull request as draft November 8, 2024 03:33
@NexVeridian
Copy link
Author

NexVeridian commented Nov 8, 2024

This is still missing a SecurityAddon like here.
Without it you cannot access secured routes.

Nice, thanks, I think SecurityAddon is for fixing the curl command in the ui to be correct

Without SecurityAddon the routes should work, utoipa shouldn't effect that? but the entire auth section is broken for the demo?

both on this branch and main, but if I create a new loco project and add the utoipa code it works correctly?

curl --location 'localhost:5150/api/auth/register' \
     --header 'Content-Type: application/json' \
     --data-raw '{
         "name": "Loco user",
         "email": "[email protected]",
         "password": "12341234"
     }'


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome to Loco!</title>
...

Also wouldn't it be possible to integrate the utoipa-axum crate into the Routes struct and put it behind a feature flag?
That I do not have to have two functions where I have to list all the routes.

it should be possible to combine them, OpenApiRouter::new() is a wrapper struct for axum::Router, but where exactly to put it is messy? the easiest would be to replace AxumRouter with OpenApiRouter::new(), or somewhere in either routes::Routes, controller::AppRoutes

All the data, except for the return type, for the #[utoipa::path()] exists in the function parameters or routes::Routes it should be possible to fill in the macro

@DenuxPlays
Copy link
Contributor

Yes its only for fixing the curl command and for supplying a little lock icon so its easier to use the "Try it out" feature.
It will not actually break the route just the documentation.

I think the replacement to use the OpenApiRouter should be in routes::Routes struct to make the transition as seamless as possible.
So the only thing needed is to add a utoipa::path macro to all the routes.

However I do not know if you can add routes that do not use the utoipa::path macro to the OpenApiRouter this is something we need to test.
And if its not possible I would open a feature request or maybe even a pr to add this functionality.

@DenuxPlays
Copy link
Contributor

Or we replace this with utoipauto which I used in my actix-web backend.
But personally I think the OpenAPiRouter is the cleaner solution.

@NexVeridian NexVeridian changed the title example: serving the OpenAPI doc example: manually serving the OpenAPI doc Nov 13, 2024
@NexVeridian NexVeridian marked this pull request as ready for review November 13, 2024 03:24
@NexVeridian NexVeridian force-pushed the Serving-the-OpenAPI-doc branch from 71b66c9 to e210000 Compare November 13, 2024 03:30
@NexVeridian NexVeridian mentioned this pull request Nov 13, 2024
17 tasks
@NexVeridian NexVeridian force-pushed the Serving-the-OpenAPI-doc branch from e210000 to 1636fa2 Compare November 22, 2024 09:21
@NexVeridian NexVeridian force-pushed the Serving-the-OpenAPI-doc branch from 1636fa2 to be7c6ed Compare November 23, 2024 12:37
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

Successfully merging this pull request may close these issues.

3 participants