Skip to content

Specify and add TCK test cases for @Digits constraint processing#733

Draft
MikeEdgar wants to merge 1 commit into
microprofile:mainfrom
MikeEdgar:issue-717
Draft

Specify and add TCK test cases for @Digits constraint processing#733
MikeEdgar wants to merge 1 commit into
microprofile:mainfrom
MikeEdgar:issue-717

Conversation

@MikeEdgar
Copy link
Copy Markdown
Contributor

Closes #717

  • Add specification of @Digits constraint processing for schema properties
  • Include new TCK test cases covering the specification
  • Fix TCKMatchers.NUMERIC_COMPARATOR to create BigDecimal instances from string representations of the Number arguments, avoiding conversion errors in cast from float to double.

Signed-off-by: Michael Edgar <michael@xlate.io>
| `@DecimalMin(value = a)` | `number` or `integer` | `minimum = a`
| `@DecimalMin(value = a, inclusive = false)` | `number` or `integer` | `exclusiveMinimum = a`
| `@Digits(integer = <any>, fraction = f)` | `number` or `integer` | `multipleOf` equal to `1` for integer types or 10^-f for non-integer types
| `@Digits(integer = i, fraction = f)` | `string` | `pattern` matching any string value that satisfies the constraint
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Azquelt did we discuss having the string case in the specification or only the multipleOf for numbers?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to have both.

The only reason we don't have @Digits for strings already was that it was odd to have it for strings but not numbers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I need to review the BV spec to make sure it's aligned there. I can imagine various gaps in how BV implementations validate cases like integer = 0 or fraction = 0. For example, do we expect @Digits(integer = 0, fraction = 2) to allow both ".25" and "0.25" or maybe the TCK just stays away from those edge cases.

| `@DecimalMax(value = a, inclusive = false)` | `number` or `integer` | `exclusiveMaximum = a`
| `@DecimalMin(value = a)` | `number` or `integer` | `minimum = a`
| `@DecimalMin(value = a, inclusive = false)` | `number` or `integer` | `exclusiveMinimum = a`
| `@Digits(integer = <any>, fraction = f)` | `number` or `integer` | `multipleOf` equal to `1` for integer types or 10^-f for non-integer types
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to generate multipleOf: 1 if the schema type is integer, since that's already implied.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a better way to specify this would be in terms of fraction rather than in terms of the schema type. When fraction < 1, we expect multipleOf = 1, otherwise it will be 10^-f.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well possibly, but consider this field:

@Digits(integer = 4, fraction = 0)
int myNumber;

We'd expect this schema:

{
    "type": "integer",
    "multipleOf": 1
}

Here the multipleOf: 1 is redundant since the schema already requires an integer. I don't think we should require this.

This might mean that in the TCK we have to check for both cases: either the schema type is integer, or multipleOf: 1 is present.

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

Successfully merging this pull request may close these issues.

Support for multipleOf schema assertion from @Digits BV constraint

2 participants