swagger-api / swagger-api/swagger-codegen

[Rust] Generated models compiler warnings

Open
#8,929 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I encountered two issues with rust generator ('rust' one, not 'rust-server'). I generated models for Docker API.

Problems:

  1. Uppercase fields and variables:
BuildCache:
    type: "object"
    properties:
      ID:
        type: "string"
    ...

gives

#[derive(Debug, Serialize, Deserialize)]
pub struct BuildCache {
    #[serde(rename = "ID")]
    ID: Option<String>,
    ...
}

getters, setters etc. of this field also have uppercase ID. It results with many compiler warnings.

  1. Double underscore.
LogConfig:
  type: "object"
  description: "The logging configuration for this container"
  properties:
    Type:
      type: "string"
      enum:
        - "json-file"
        - "syslog"
        - "journald"
        - "gelf"
        ...

produces

#[derive(Debug, Serialize, Deserialize)]
pub struct HostConfigLogConfig {
    #[serde(rename = "Type")]
    _type: Option<String>,
    ...
}

Problem is that names for _type methods have incorrect names for rust: set__type, get__type. Maybe it should be _set_type insted.

Swagger-codegen version

2.3.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust generator's model generation path and reproduce the reported output using the Docker API models. Verify generated field and accessor names for uppercase properties and the Type property, with completion shown by warning-free Rust output and corrected setter/getter names.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.