Skip to content

Duplicated pattern within allOf when a class is reused #143

@coder925

Description

@coder925

In v6.0.0 of MicroElements.Swashbuckle.FluentValidation, I get duplicated pattern rules in swagger.json:

"phone": {
    "type": "string",
    "allOf": [
          {
              "pattern": "^$|\\+(?:[0-9] ?){6,14}[0-9]"
          },
          {
              "pattern": "^$|\\+(?:[0-9] ?){6,14}[0-9]"
          },
          {
              "pattern": "^$|\\+(?:[0-9] ?){6,14}[0-9]"
          }
      ],
    "nullable": true
}

whereas in v5.7.0 I only get one pattern as expected:

"phone": {
    "pattern": "^$|\\+(?:[0-9] ?){6,14}[0-9]",
    "type": "string",
    "nullable": true
}

for a class ContactInfo that has a regex validation on Phone number.

This happens when I have multiple classes that uses the ContactInfo class by composition:

classDiagram
    class ContactInfo {
        +String Phone
    }
    class Teacher {
        +ContactInfo ContactInfo
    }
    class Student {
        +ContactInfo ContactInfo
    }
    Teacher --|> ContactInfo
    Student --|> ContactInfo
Loading

Full sample

https://github.com/coder925/fluentvalidation-withregex

Consequence

The multiple patterns gives issues when generating TypeScript files for this swagger.json in openapi-generator-cli. The property phone will not be a string but an interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions