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

Nullable and patern #595

Open
ntnchrrn07 opened this issue Feb 15, 2024 · 1 comment
Open

Nullable and patern #595

ntnchrrn07 opened this issue Feb 15, 2024 · 1 comment

Comments

@ntnchrrn07
Copy link

ntnchrrn07 commented Feb 15, 2024

Hi,
I could not use for a string pattern and nullable, is it normal ?

OpenApiSpex.schema(%{
  title: "mySchema",
  type: :object,
  properties: %{
    dummy: %Schema{
      type: :string,
      nullable: true,
      pattern: "^[0-9]{3}$"
    }

}

I would like to allow :

{dummy: null}
and {dummy: "010"}

@marciotoze
Copy link

I have same problem here, nullable: true does not work with pattern, an workaround is "accept null" in your regex.

adding |^$ to end of your regex should works.

some like pattern: "^[0-9]{3}$|^$"

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

2 participants