Forum Discussion

kurtosys's avatar
kurtosys
New Contributor
5 years ago

OpenAPI spec - unique keys, how to model a star schema

I'm trying to spec a requestBody which conforms this:

 

{
"caseT": {... spec T...} "exts": {"caseU": {... spec U...}, "caseX": {... spec X...} } }

There are a number of known cases, the names are known - this means, all possible keys are known (case T, case U, case X, case ..., this is limited). For each case, the spec is known as well (there's no problem with modelling the specs).

 

Where I'm struggling a bit with is: how can I make sure that

  • there is exactly 1 of the cases in the 'root' of the request (in this example, this is case T),
  • in 'exts', there are any number of other specs, but max 1 of each and if possible at all any case except the one that's in the root (which I don't think is possible).

Is this possible, of how can this be modelled as closely as possible in openapi 3.0?

4 Replies

    • RonRatovsky's avatar
      RonRatovsky
      Moderator

      Unfortunately, there's no way to define that.

       

      You can say that the top-level object can have at most 1 property, but that won't allow to add 'ext', or 2 properties, but that can also allow 'Case T' and 'Case X' to co-exist. Under 'ext', each case can exist only once as a key as they have to be unique, but you can't force it to not be the same case as the root level.

      • kurtosys's avatar
        kurtosys
        New Contributor

        Too bad... any plans to support something like ajv or so (which makes some more logic possible)?