raml-spec
raml-spec copied to clipboard
[Request] New type - map
It seems it's impossible to define maps in RAML other than via object with manually defined all the keys and values.
It would be nice if we had another type called map which would work like:
types:
BasicMapDefinition:
type: map
keys: string
values: integer
# map from any string -> integer
# eg. valid json { "one": 1, "two": 2, "three": 3 }
# eg. valid json { "foo": 1, "bar": 2, "baz": 3 }
FooBarBazEnum:
type: string
enum: ["foo", "bar", "baz"]
EnumMapDefinition:
type: map
keys: FooBarBazEnum
values: integer
# map from "foo", "bar" or "baz" strings-> integer
# eg. valid json { "foo": 1, "bar": 2, "baz": 3 }
# eg. invalid json { "one": 1, "two": 2, "three": 3 }
Is there any valid form in JSON schema for this?
Have you tried patterProperties to do that? https://github.com/raml-org/raml-spec/issues/573#issuecomment-247135710
Actually, we need something more generic. The keys are not necessarily limited to a set of values. Probably your intention is to support any scalar or user-defined type for keys: and values:
sichvoge - what are patterProperties?
Here is another Map in JSON that I cannot figure out how to define in RAML. We can define a pattern for the strings but there is no other limit on actual values. This is how Jackson renders a Map<String, String> property named "translations" in a Java class. { "translations": {"M80":"McDonnell Douglas MD-80", "M82":"McDonnell Douglas MD-82", "M81":"McDonnell Douglas MD-81", "M83":"McDonnell Douglas MD-83", "DFL":"Dassault Falcon", "M88":"McDonnell Douglas MD-88", "M87":"McDonnell Douglas MD-87"} } This is an abbreviated example. There are many, many more items.
I don't see any helpful answer.
How do you define a mapping whose keys are strings and values are integers? Like this one:
{
"a": 1,
"b": 2
}
Actually it's possible! But the explanation is a bit in the dark: https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#additional-properties
The definition of the above example would be:
types:
MyMappingType:
properties:
//:
type: integer