Skip to content

Automap Dictionary maps unwanted properties of the dictionary type #1852

@russcam

Description

@russcam

An example

public class MockContract
{
    public List<string> Keywords { get; set; }
    public Dictionary<string, string> Names { get; set; }
}

client.Map<MockContract>(m => m
    // automap will infer field types and use attributes
    .AutoMap()
    // then override any mappings with explicit fluent mappings
    .Properties(p => p
        .Object<object>(o => o
            .Name(n => n.Names)
            .Properties(op => op
                .String(s => s
                    .Name("en")
                    .Analyzer("english")
                )
                .String(s => s
                    .Name("de")
                    .Analyzer("german")
                )
            )
        )
    )
);

yields

{
  "properties": {
    "keywords": {
      "type": "string"
    },
    "names": {
      "properties": {
        "comparer": {
          "properties": {},
          "type": "object"
        },
        "count": {
          "type": "integer"
        },
        "keys": {
          "properties": {
            "count": {
              "type": "integer"
            }
          },
          "type": "object"
        },
        "values": {
          "properties": {
            "count": {
              "type": "integer"
            }
          },
          "type": "object"
        },
        "item": {
          "type": "string"
        }
      },
      "type": "object"
    },
    "names": {
      "type": "object",
      "properties": {
        "en": {
          "type": "string",
          "analyzer": "english"
        },
        "de": {
          "type": "string",
          "analyzer": "german"
        }
      }
    }
  }
}

comparer, count, keys and values properties of the dictionary end up being mapped when they shouldn't, in addition to the explicit property mapping not overriding the inferred mapping for names

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions