juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.02k stars 160 forks source link

How do I add custom x-properties #643

Open coffeebe4code opened 1 year ago

coffeebe4code commented 1 year ago

I am using the actix example essentially.

We have custom requirements at our company to add several extra fields, usually for certain blocks. like the server block, or extra x-properties in the info block.

#[utoipa::path(
    get,
    path = "/echo",
    responses(
        (status = 200, description = "echos back all headers and request body in response"),
    ),
)]
#[get("/echo")]
    #[derive(OpenApi)]
    // ?insert more props on openapi?
    #[openapi(paths(echo))]
    struct ApiDoc;

    let mut openapi = ApiDoc::openapi();
    // ? insert more props on openapi?
    let mut file = std::fs::File::create("openapi.json")?;
    file.write_all(openapi.to_pretty_json().unwrap().as_bytes())?;

I would much rather build this file at compile time as well, but I can manage that on my end if there are no exposed means from this project.

Great freaking project btw, this all worked perfectly out of the box very quick to set up.

juhaku commented 1 year ago

In short, at the moment x-properties are not supported and there is no build in way to insert extension properties to the schema.

Perhaps this is something that could be explored in future, and of course PR:s are welcome. :slightly_smiling_face:

rlukata commented 11 months ago

@coffeebe4code You can build the server object using the modify trait.

lucasgranberg commented 9 months ago

https://github.com/juhaku/utoipa/pull/763 Are these the same x-properties? My PR is for openapi extensions