Skip to content

Conversation

@StefanHenke
Copy link
Contributor

Describes the basic feature set of the new @assert annotation. The full blown CXN documentation is pending and will be provided by Patrice later. Once available, we will link it here. That´s why the expressions in the examples are kept simple by intention.

Copy link
Contributor

@agoerler agoerler left a comment

Choose a reason for hiding this comment

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

Please introduce in smaller steps

  • one case
  • multiple cases
  • error function

cosider using ? :

Please add some examples for moderately more complex expressions.

Like, e.g.

  • "if an order has items the order's total amount must be larger then 0"
  • "a book's author's name must not be null"

@StefanHenke
Copy link
Contributor Author

Please introduce in smaller steps

  • one case
  • multiple cases
  • error function

cosider using ? :

Please add some examples for moderately more complex expressions.

Like, e.g.

  • "if an order has items the order's total amount must be larger then 0"
  • "a book's author's name must not be null"

What exactly do you mean with consider using ? :`?

We agreed with Johannes and Patrice yesterday that we will keep the expressions simple here and wait for the CXL docs. But I can check for a "moderately more complex expression".

@rjayasinghe
Copy link
Contributor

Please introduce in smaller steps

  • one case
  • multiple cases
  • error function

cosider using ? :
Please add some examples for moderately more complex expressions.
Like, e.g.

  • "if an order has items the order's total amount must be larger then 0"
  • "a book's author's name must not be null"

What exactly do you mean with consider using ? :`?

We agreed with Johannes and Patrice yesterday that we will keep the expressions simple here and wait for the CXL docs. But I can check for a "moderately more complex expression".

I think @agoerler meant that we split up this single block into 3 examples. After each example we explain the nature of the used expression.

@StefanHenke
Copy link
Contributor Author

Please introduce in smaller steps

  • one case
  • multiple cases
  • error function

cosider using ? :
Please add some examples for moderately more complex expressions.
Like, e.g.

  • "if an order has items the order's total amount must be larger then 0"
  • "a book's author's name must not be null"

What exactly do you mean with consider using ? :`?
We agreed with Johannes and Patrice yesterday that we will keep the expressions simple here and wait for the CXL docs. But I can check for a "moderately more complex expression".

I think @agoerler meant that we split up this single block into 3 examples. After each example we explain the nature of the used expression.

Yes, I have split up the examples already. But was not sure if ?: is something in addition

Copy link
Contributor

@patricebender patricebender left a comment

Choose a reason for hiding this comment

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

👍 As Adrian stated, it would be nice to have a little more (complex) real life scenarios. I would have probably taken the well known Bookshop for showcasing the different scenarios. But that may be my personal taste.

@patricebender
Copy link
Contributor

What exactly do you mean with consider using ? :`?

You can use the ternary operator as syntactic sugar for the clumsy case … when … then … statements:

> cds.parse.xpr`1 > 2 ? true : false`
[
  'case',         'when',
  { val: 1 },     '>',
  { val: 2 },     'then',
  { val: true },  'else',
  { val: false }, 'end'
]

@agoerler
Copy link
Contributor

agoerler commented Nov 21, 2025

What exactly do you mean with consider using ? :`?

You can use the ternary operator as syntactic sugar for the clumsy case … when … then … statements:

> cds.parse.xpr`1 > 2 ? true : false`
[
  'case',         'when',
  { val: 1 },     '>',
  { val: 2 },     'then',
  { val: true },  'else',
  { val: false }, 'end'
]

@patricebender - could you also omit the :-clause and it would default to else null ? E.g.

size > 100 ? 'size must be below 100'

@StefanHenke
Copy link
Contributor Author

What exactly do you mean with consider using ? :`?

You can use the ternary operator as syntactic sugar for the clumsy case … when … then … statements:

> cds.parse.xpr`1 > 2 ? true : false`
[
  'case',         'when',
  { val: 1 },     '>',
  { val: 2 },     'then',
  { val: true },  'else',
  { val: false }, 'end'
]

@patricebender - could you also omit the :-clause and it would default to else null ? E.g.

size > 100 ? 'size must be below 100'

That makes sense. When I tested it, compiler still required the default else null a few weeks back.

@StefanHenke
Copy link
Contributor Author

👍 As Adrian stated, it would be nice to have a little more (complex) real life scenarios. I would have probably taken the well known Bookshop for showcasing the different scenarios. But that may be my personal taste.

I have improved the examples to use Bookshop related entities. Regarding the ternary operator, we still have to put the : else as the compiler complains otherwise.

@agoerler
Copy link
Contributor

I would like to suggest that you introduce a few sub-sections for

  • condition
  • error messages
  • message targets

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Linting Errors

  • guides/providing-services.md:1021:1 container type should be specified [Context: "::: "]

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Linting Errors

  • guides/providing-services.md:1021:1 container type should be specified [Context: "::: "]

@StefanHenke StefanHenke requested a review from Akatuoro December 15, 2025 07:53
@StefanHenke StefanHenke requested a review from Akatuoro December 15, 2025 09:07
Copy link
Contributor

@Akatuoro Akatuoro left a comment

Choose a reason for hiding this comment

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

👍 lgtm

@DanSchlachter DanSchlachter self-requested a review December 15, 2025 14:11
@renejeglinsky renejeglinsky merged commit 6ad35b4 into main Dec 16, 2025
8 checks passed
@renejeglinsky renejeglinsky deleted the assert-docs branch December 16, 2025 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment