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

OpenAI/Swagger documentation for axum's API #25

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

JohnnyGuye
Copy link

@JohnnyGuye JohnnyGuye commented Aug 4, 2024

This PR embarks commits that are also in #23 so don't validate it until the other one is closed

Addition of an autogeneration of OpenAPI specs and a Swagger ui to easily navigate the API through utoipa.

  • The Swagger UI is accessible at /swagger-ui
  • The root route that returned Hello World! now redirects to /swagger-ui instead
  • Routes can be documented by using the #[utoipa::path] macro

Example:

/// Creates a new user
///
/// Creates a new user and returns the user.
#[utoipa::path(
    post,
    path = "/users",
    request_body = CreateUser,
    responses(
        (status = 201, description = "The user created", body = User)
    )
)]
async fn create_user(Json(payload): Json<CreateUser>) -> impl IntoResponse {
    // ... app logic
    (StatusCode::CREATED, Json(user))
}

Generates this swagger
image
image
And the Swagger UI is interactive

@Lauwed
Copy link
Contributor

Lauwed commented Aug 25, 2024

  • Lock the node version engine in package.json to v20
  • Create a new file .nvmrc and the content should be 20 (TOUT COURT, si vous avez la ref)

Copy link
Contributor

@lilymonad lilymonad left a comment

Choose a reason for hiding this comment

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

Some suggestions added

Comment on lines 78 to +79
#[derive(Deserialize)]
#[derive(ToSchema)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[derive(Deserialize)]
#[derive(ToSchema)]
#[derive(Deserialize, ToSchema)]

Comment on lines 85 to +86
#[derive(Serialize)]
#[derive(ToSchema)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[derive(Serialize)]
#[derive(ToSchema)]
#[derive(Serialize, ToSchema)]

engine-strict=true
engine-strict=true
Copy link
Contributor

Choose a reason for hiding this comment

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

is it the good formating or an artefact from your code editor ?
(same with web/.nvmrc but for some reason i cannot add a comment there)

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