juhaku / utoipa

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

Manual ordering of header names in security section. #793

Open dayvejones opened 11 months ago

dayvejones commented 11 months ago

Hey! I use:

#[utoipa::path(
  get,
  path = "/api/v1/items",
  responses(
      (status = 200,  body = String),
      (status = 400,  body = String)
  ),
  security(
      ("x-client-name" = []),
      ("x-auth-token" = [])
  )
)]

and

#[derive(OpenApi)]
    #[openapi(
        modifiers(&SecurityAddon),
    )]
    struct ApiDoc;
    struct SecurityAddon;

    impl Modify for SecurityAddon {
        fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
            if let Some(components) = openapi.components.as_mut() {
                 components.add_security_scheme(
                    "x-client-name",
                    SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::new("x-client-name"))),
                );
                components.add_security_scheme(
                    "x-auth-token",
                    SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::new("x-auth-token"))),
                );
            }
        }
    }

but the SwaggerUI automatically re-sorts header names alphabetically:

image

Is it possible to add a feature for manual sorting?

dayvejones commented 11 months ago

There was the same problem with routes https://github.com/juhaku/utoipa/issues/597

juhaku commented 1 week ago

We could make it sortable similar way as the paths are optionally e.g. in insertion order with indexmap. They are for now sorted alphabetically because of BTreeMap.