utoipa icon indicating copy to clipboard operation
utoipa copied to clipboard

Schema options in params(...) are ignored

Open Patrick-Lehner-Woven-by-Toyota opened this issue 7 months ago • 4 comments

Hi utoipa folks! First of all, thank you very much for your great work on this library, it has helped us a bunch to manage our API spec!

We're just trying to update from v3.3.0 to v4.1.0, and it seems that additional schema options in params(...) inside of the #[utoipa::path(...)] now get ignored 🥲 We're using axum and have the axum feature in utoipa turned on.

For example, we have an endpoint similar to this (reduced to essential stuff):

#[utoipa::path(
    get,
    path = "/user/{user_id}",
    params(
        ("user_id", min_length = 1),
    )
)]
#[tracing::instrument(err(Debug))]
async fn get_user(
    AxumState(state): AxumState<State>,
    Path(user_id): Path<String>,
) -> Result<Json<User>> {
  // . . .

With v3.3.0, this used to emit something like this in the OAPI doc:

  /user/{user_id}:
    get:
      operationId: get_user
      parameters:
      - name: user_id
        in: path
        required: true
        schema:
          type: string
          minLength: 1

With v4.1.0, the minLength: 1 gets removed from the OAPI doc output :(

Randomly, I also tried adding the nullable annotation to the same parameter, i.e. turning it into:

    params(
        ("user_id", min_length = 1, nullable),
    )

In v4.1.0, this didn't affect the output at all. In v3.3.0, this changed the output as expected:

  /user/{user_id}:
    get:
      operationId: get_user
      parameters:
      - name: user_id
        in: path
        required: true
        schema:
          type: string
          nullable: true
          minLength: 1

Is this a known issue? I looked around in the issues, but couldn't find one that exactly seems to match this problem (but could be that the description/title is too different.) The only slightly similar issue I could find is https://github.com/juhaku/utoipa/issues/693, but I'm not sure if that one might be a separate problem affecting only format 🤔

If there's something we can do to help isolate this, please let me know!