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

[Request] New type - map #650

Open
ioleo opened this Issue Aug 6, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@ioleo

ioleo commented Aug 6, 2017

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 }
@sichvoge

This comment has been minimized.

Contributor

sichvoge commented Aug 7, 2017

Is there any valid form in JSON schema for this?

@sichvoge

This comment has been minimized.

Contributor

sichvoge commented Aug 12, 2017

Have you tried patterProperties to do that? #573 (comment)

@edunkle

This comment has been minimized.

edunkle commented Dec 18, 2017

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.

@alexpirine

This comment has been minimized.

alexpirine commented Jun 21, 2018

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
}
@alexpirine

This comment has been minimized.

alexpirine commented Jun 21, 2018

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment