json-schema-org / vocab-idl

Help and clarify how JSON Schema can be interpreted from validation rules to data definition. This extends to how those data definitions can be represented in any programming language
19 stars 4 forks source link

How to interpret simple schemas that contains `patternProperties` #17

Open jonaslagoni opened 3 years ago

jonaslagoni commented 3 years ago

Similar to #12, with the very same side effects, we need to figure out how to interact with patternProperties. I only see the very same approach as outlined in #12, so let's use that issue as a baseline for this one.

jdesrosiers commented 3 years ago

For the most part, I see this the same way I see addtionalProperties. It's a way to constrain how a type is allowed to be extended. However, it's more than that as well.

{
  "type": "object",
  "properties": {
    "i_value": { "maximum": 10 },
    "s_description": { "maxLength": 32 }
  },
  "patternProperties": {
    "^s_": { "type": "string" },
    "^i_": { "type": "integer" }
  }
}

In this case the type I would expect is this,

type Example = {
  i_value: number;
  s_description: string;
};

In this example patternProperties is not just constraining how it can be extended, it's also contributing to the types of a properties.

jonaslagoni commented 3 years ago

In this example patternProperties is not just constraining how it can be extended

That is a good point 👀

Let's leave the discussion whether it needs to be included in https://github.com/json-schema-org/vocab-idl/issues/12 and follow the same behavior from there 🙂