Skip to content

[BUG][Rust] nullable additionalProperties cannot be represented by model #19989

@PaulWagener

Description

@PaulWagener

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

In the latest version of the generator the following definition:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Bug
paths: {}
components:
  schemas:
    MyModel:
      type: object
      required:
      - my_field
      properties:
        my_field:
          type: object
          additionalProperties:
            type: string
            nullable: true

Will produce the following Rust model:

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct MyModel {
    #[serde(rename = "my_field")]
    pub my_field: std::collections::HashMap<String, String>,
}

This fails to decode JSON which has additional null properties, for example:

{
    "my_field": {
        "extra_field": null
    }
}

The proper type to use for my_field would be:

HashMap<String, Option<String>>

I've created a possible fix for this problem in this commit.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions