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

feat: OpenAPI integration #984

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

Conversation

NexVeridian
Copy link

@NexVeridian NexVeridian commented Nov 13, 2024

related #855

cargo check -F all_openapi
cargo nextest run --test-threads 1 -F all_openapi

TODO:

  • config.yaml
    • maybe no enable: true since that's handled by the feature
      openapi:
        redoc:
          !Redoc
            url: /redoc
            spec_json_url: /redoc/openapi.json
            spec_yaml_url: /redoc/openapi.yaml
        scalar:
          !Scalar
            url: /scalar
            spec_json_url: /scalar/openapi.json
            spec_yaml_url: /scalar/openapi.yaml
        swagger:
          !Swagger
            url: /swagger-ui
            spec_json_url: /api-docs/openapi.json
            spec_yaml_url: /api-docs/openapi.yaml
    • finish .merge(Redoc::with_url("/redoc", api.clone()))
    • openapi.josn and openapi.yaml endpoints for all types
  • split feature openapi into feature all_openapi swagger-ui redoc scalar
  • rstest feature flagged cases
  • SecurityAddon
    • put impl Modify for SecurityAddon somewhere, maybe with config
    • set the jwt token location
  • tests
    • update src/tests_cfg/db.rs:86:1
    • src/tests_cfg/config.rs
    • config from file test_from_folder_openapi()
    • snapshots
  • docs
  • maybe auto fill / wrap utoipa::path if possible
  • check that get in get(get_action_openapi) is still grabbed with routes!(get_action_openapi)
  • fix AppContext - check that api_router.routes(method.with_state::<AppContext>(())) doesn't break the ctx with .layer
  • cargo test is broken with JWT_LOCATION.get_or_init, nextest works correctly
  • codegen
    • cargo loco generate controller --openapi
    • adding #[derive[utoipa::ToSchema)] if used in utoipa::path
    • routes! macro

cc @DenuxPlays

@DenuxPlays
Copy link
Contributor

Looks like a good start.

I think the yaml also should contain a few other things:

  • openapi and ui endpoints (I am not sure if this is want you mean in your description)
  • whether it serves json, yaml or both (Perhaps this can be controlled by using features to exclude unnecessary dependencies)

@NexVeridian NexVeridian force-pushed the OpenAPI-integration branch 4 times, most recently from 9055d99 to 3e106d0 Compare November 22, 2024 09:21
@DenuxPlays
Copy link
Contributor

Hey @NexVeridian

Can I help you finish this pr?

@NexVeridian
Copy link
Author

@DenuxPlays yeah of course

@DenuxPlays
Copy link
Contributor

How can I help?

Also just one Note to your pr description.
I wouldn't wrap the utoipa path macro.
Its working very well just how it is and wrapping it would make upgrading and maintaining very difficult

@NexVeridian
Copy link
Author

NexVeridian commented Nov 27, 2024

Also just one Note to your pr description. I wouldn't wrap the utoipa path macro. Its working very well just how it is and wrapping it would make upgrading and maintaining very difficult

thanks!

this would be nice if possible:

impl Routes {
/// .add_openapi(routes!(get_action, post_action))
pub fn add_openapi(mut self, method: UtoipaMethodRouter<AppContext>) -> Self {}
}

any of the unchecked ones in the pr description would be great:
maybe cargo loco generate controller --openapi and docs first

@NexVeridian NexVeridian marked this pull request as ready for review December 13, 2024 22:42
@NexVeridian NexVeridian force-pushed the OpenAPI-integration branch 2 times, most recently from 85cf36a to ca7efbd Compare December 14, 2024 01:16
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.

Looks good just one comment.

Haven't tested it yet just reviewed the code.

src/controller/openapi.rs Outdated Show resolved Hide resolved
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