Skip to content

openapi: overly permissive types in spec #19543

@acud

Description

@acud

I have searched the existing issues, both open and closed, to make sure this is not a duplicate report.

  • Yes

The bug

The OpenAPI spec has overly permissive numeral types defined for certain fields. This in turn causes code generators to generate downstream code which allows for invalid input which in turn may cause clients to error unnecessarily.

For example, the /search/metadata/ endpoint which takes the MetadataSearchDto as the query specifier. Since page and size are defined as number, not integer as per the OpenAPI spec, in a rust generated client, those fields are rendered by the generator as f64 (meaning 64-bit floats) instead of integers:

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct MetadataSearchDto {
    ...
    #[serde(rename = "page", skip_serializing_if = "Option::is_none")]
    pub page: Option<f64>,
    ...
    #[serde(rename = "size", skip_serializing_if = "Option::is_none")]
    pub size: Option<f64>,
    ...
}

Besides from this being confusing, it may cause clients to call the endpoints with invalid call data since it may require further hand-written input validation written on API consumers.

This adds all sorts of ugly conversions for those who want to want to interact with the API through the spec rather than implementing by hand (many) endpoints. In the example above, when paging the results from the API, the caller must convert the returned nextPage value string (this should probably be an integer as well, as it has the value of the number of the next page) to a float which seems a bit odd.
The problem exists for many other types.
Proposed solution: go through the spec and change the necessary fields to the relevant OpenAPI type.

The OS that Immich Server is running on

Arch

Version of Immich Server

v1.132.3

Version of Immich Mobile App

v1.132.3

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

-

Your .env content

-

Reproduction steps

  1. cd open-api
  2. run:
  -v ${PWD}:/local openapitools/openapi-generator-cli generate \
  -i /local/immich-openapi-specs.json \
  -g rust \
  -o /local/out/rust
  1. inspect the resulting generated code

Relevant log output

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions