Company
Date Published
Author
Phil Sturgeon
Word count
1024
Language
English
Hacker News points
None

Summary

OpenAPI v3.x introduces the discriminator field, often used with oneOf, anyOf, or allOf to handle polymorphism by indicating which schema to apply based on certain field values. However, its practical utility is questioned, as JSON Schema can manage similar tasks without this OpenAPI-specific feature. The discriminator acts merely as a hint for tools like code generators to quickly determine the relevant schema but does not contribute to validation, documentation, or other functions. The text argues that OpenAPI's oneOf and anyOf keywords, alongside schema properties like const, are sufficient for managing schema selection and validation without relying on discriminator, which is seen as an outdated concept. Modern tools and practices favor a more straightforward approach that leverages the natural structure of data and the flexibility of JSON Schema to provide meaningful validation and documentation without the need for discriminator fields.