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

Doctests not displayed correctly and #[doc = "string"] not visible in swagger UI #743

Open
DragonDev1906 opened this issue Feb 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@DragonDev1906
Copy link

DragonDev1906 commented Feb 6, 2024

Expected Behavior

Everything in the docstring to be visible in the resulting openapi document, similar to how it is shown in cargo doc.

This unfortunately makes it hard to use doctests or include a string literal used in another test in the generated docs to ensure they're kept up-to-date. Which in my opinion would be a big benefit of putting the api specification in the rust code in the first place.

Note that so far I was not able to get code_sample(lang = "rust", source = "examples::JSON_WITNESS") to show up in the generated swagger UI either, which was my first attempt at adding additional information that is also checked with cargo test.

Actual Behavior

Code openapi cargo doc rust_analyzer
/// Something Yes Yes Yes
#[doc = "Test 123"] No Yes Yes Yes
#[doc = include_str!("../../README.md")] No Yes No
Doctests As written, not hiding lines starting with # Yes Yes

In cargo doc

I've had to use a separate struct because the openapi type wasn't added to cargo doc due to being private.
2024-02-06-185827_1022x298_scrot
2024-02-06-185835_340x147_scrot

In the swagger UI

2024-02-06-190017_772x268_scrot

Steps to Reproduce the Problem

  1. Use the OpenApi macro, add a method to it and add the following docstring:
    /// Retrieve previously stored key material
    ///
    /// This also returns the access control list
    ///
    /// ### Example value (before encryption and base64 encoding)
    #[doc = include_str!("../../README.md")]
    #[doc = "Test 123"]
    ///
    /// ### Attempt 2
    /// ```
    /// println!("Hello");
    /// # todo!();
    /// println!("World")
    /// ```
    #[oai(
        path = "/session/:session_id/keys/:id",
        method = "get",
        tag = Tags::KeyManagement
    )]
    async fn get_key(
    // ...
  1. Run cargo doc to see the results it generates
  2. Run a binary with this API and the swagger UI enabled
  3. Have a look at the description in the swagger UI (see screenshots)

Specifications

  • Version: 4.0.0
  • Platform: Linux
  • Subsystem: poem-openapi
@DragonDev1906 DragonDev1906 added the bug Something isn't working label Feb 6, 2024
@DragonDev1906 DragonDev1906 changed the title <Title> Doctests and #[doc = "string"] not visible in swagger UI Feb 6, 2024
@DragonDev1906 DragonDev1906 changed the title Doctests and #[doc = "string"] not visible in swagger UI Doctests not displayed correctly and #[doc = "string"] not visible in swagger UI Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant