Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Support RegularExpressionAttribute for string collections. #343

Open
Drake53 opened this issue May 11, 2024 · 0 comments

Comments

@Drake53
Copy link

Drake53 commented May 11, 2024

Currently when using JSchemaGenerator, if a property is of type ICollection<string> (for example List<string>), the [RegularExpressionAttribute] is ignored, for example the following class:

public class MyClass
{
  [RegularExpression("^[A-Z]+$")]
  public List<string> PropertyName { get; set; }
}

Generates the following schema:

{
  "$schema": "...",
  "type": "object",
  "properties": {
    "PropertyName": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  }
}

It would be nice if there was built-in support for this, so the schema would be generated as follows:

{
  "$schema": "...",
  "type": "object",
  "properties": {
    "PropertyName": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[A-Z]+$"
      }
    }
  }
}

The same probably applies to [StringLengthAttribute] as well, though I haven't tested this.

As a workaround, a custom JSchemaGenerationProvider implementation can be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant