What is the best way to define a currency datatype that allows 0.00 as a value?


#1

I have a datatype for Currency that is defined as:

#%RAML 1.0 DataType
type: number
multipleOf: 0.01

Problem is, it won’t allow a value of 0.00, which is an often-needed value. I know I could do null or ? as possible ways to express no amount, but I need 0 or 0.00 in this case, to be valid values.

Any thoughts on how best to describe this in RAML 1.0?

Thanks in advance!


#2

You can use a union type. See this Monetary value example.


#3

@jnthodge: can you confirm if it worked?


#4

Hi jstoiko,

I tried your example as-is, and it does not work for some reason.

It appears Anypoint Design Center allows it, but Anypoint Studio and runtime 7.3.1 does not. It seems to complain regardless of what all I’ve tried:

  1. The usage of multiple inheritance in the “type:” element
  2. The usage of a union datatype that are external raml files (!include someType.raml | !include someOtherType.raml)
  3. The usage of type: union, anyOf: as found in some examples out on the internet, seems not to be implemented.

Your RAML is exactly what I’m trying to express. Anypoint Design Center likes it, Anypoint Studio does not…won’t start and shows errors.

Jason


#5

Why version of Studio? I would raise a ticket, this is likely a bug.


#6

Hi jstoiko,

I’ve been analyzing this with a MuleSoft engineer that is more experienced than me. We suspect that you are correct and it is a bug. It looks like it might not be supported till the next version of the runtime/Studio. Neither is released yet to the public, so releasing the Anypoint Cloud-based validation before the dev tools were ready was probably an oversight.

By trial and error, we did wire a simple datatype together that seems to behave (in the current runtime) the way we require. I hope we’re not “coding to a bug” such that it will break later!!

Example follows:

#%RAML 1.0 DataType

description: non-zero two-decimal place values (positive and negative) 
type: number
multipleOf: 0.01
minimum: -9999999999999.99
maximum: 9999999999999.99

For some reason, the min/max seem to allow 0, 0.0, 0.00 as values, even though they are not considered multiples of 0.01 (which is again arguable). :wink: We did both positive and negative testing and it seems to allow everything it should and prevent what it should. So for the moment, life is good.

Thanks for your help!

P.S. my Studio is v. 7.2.3 and my runtime is v. 4.1.2.