question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for patternProperties in schemas

See original GitHub issue

JSON Schema draft 4 has patternProperties which is not supported by Swagger 2.0. patternProperties allows to have loosely defined objects where the list of keys is not fixed in the spec (like additionalProperties allows in Swagger 2.0), but the format of the keys is restricted with a regexp (contrary to additionalProperties where keys are not at all limited).

Here is a use case from #380:

name: pop
description: population by country
type: object
patternProperties:
  '^[A-Z]{2}$':
    type: integer
    description: the population of the country indicated by the property name.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:48
  • Comments:22 (14 by maintainers)

github_iconTop GitHub Comments

27reactions
webroncommented, Mar 20, 2017

No, patternProperties did not make it into 3.0.

11reactions
hotgazpachocommented, Oct 3, 2017

So, how can we help get patternProperties into the OAS spec? The lack of this is really hampering our ability to express our response objects in OAS.

Use case:

We have an API that allows a customer to ask “what do you know about these things?”, where things can be of different types. We use the values passed in as the keys in the response to say “here’s what we know about this item”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use patternProperties in the Json Schema
additionalProperties only works by evaluating properties and patternProperties within the same schema object. "sensor_aaa" is consider valid ...
Read more >
object — Understanding JSON Schema 2020-12 documentation
The additionalProperties keyword is used to control the handling of extra stuff, that is, properties whose names are not listed in the properties...
Read more >
Support for patternProperties? - JSON Forms community
What I want is some kind ability to add/delete a new field/property. I am imagining something similar to what I see with arrays...
Read more >
JSON Schema - Advanced Example
This example shows a possible JSON representation of a hypothetical machine's mount points as represented in an /etc/fstab file.
Read more >
Additional Properties - Liquid Technologies
Second step: schemas in "patternProperties"; 8.3.3.4. ... The schema defined by "additionalProperties" is added to "s" if and only if, at this stage, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found