Refactor OpenAPI schemas and type definitions across versions 2.0, 3.0, and 3.1 for improved clarity and consistency. Update example files and tests to align with the latest specifications. Adjust package dependencies and enhance README documentation for better guidance on usage and testing.

This commit is contained in:
Luke Hagar
2025-09-30 20:36:16 +00:00
parent 4a82aa3b32
commit 3e81d0b30d
100 changed files with 141724 additions and 157789 deletions

View File

@@ -89,140 +89,140 @@ import type { XML } from "../xml";
* ```
*/
export interface ObjectSchema extends Extension {
/**
* The type identifier for object schemas.
* Must be "object".
*/
type: "object";
/**
* The type identifier for object schemas.
* Must be "object".
*/
type: "object";
/**
* A map of property names to their schemas.
* Each property in the object must conform to its corresponding schema.
*
* Example: `{ name: { type: "string" }, age: { type: "number" } }`
*/
properties?: Record<string, Schema>;
/**
* A map of property names to their schemas.
* Each property in the object must conform to its corresponding schema.
*
* Example: `{ name: { type: "string" }, age: { type: "number" } }`
*/
properties?: Record<string, Schema>;
/**
* An array of required property names.
* These properties must be present in the object.
*
* Example: `["name", "email"]`
*/
required?: string[];
/**
* An array of required property names.
* These properties must be present in the object.
*
* Example: `["name", "email"]`
*/
required?: string[];
/**
* The schema for additional properties not defined in properties.
* If false, no additional properties are allowed.
* If true, any additional properties are allowed.
* If a schema, additional properties must conform to this schema.
*
* Example: `{ type: "string" }` or `false` or `true`
*/
additionalProperties?: Schema | boolean;
/**
* The schema for additional properties not defined in properties.
* If false, no additional properties are allowed.
* If true, any additional properties are allowed.
* If a schema, additional properties must conform to this schema.
*
* Example: `{ type: "string" }` or `false` or `true`
*/
additionalProperties?: Schema | boolean;
/**
* A map of regex patterns to schemas.
* Properties whose names match a pattern must conform to the corresponding schema.
*
* Example: `{ "^S_": { type: "string" } }`
*/
patternProperties?: Record<string, Schema>;
/**
* A map of regex patterns to schemas.
* Properties whose names match a pattern must conform to the corresponding schema.
*
* Example: `{ "^S_": { type: "string" } }`
*/
patternProperties?: Record<string, Schema>;
/**
* The schema for property names.
* All property names in the object must conform to this schema.
*
* Example: `{ type: "string", pattern: "^[A-Za-z][A-Za-z0-9]*$" }`
*/
propertyNames?: Schema;
/**
* The schema for property names.
* All property names in the object must conform to this schema.
*
* Example: `{ type: "string", pattern: "^[A-Za-z][A-Za-z0-9]*$" }`
*/
propertyNames?: Schema;
/**
* The minimum number of properties in the object.
* Must be a non-negative integer.
*
* Example: `1`
*/
minProperties?: number;
/**
* The minimum number of properties in the object.
* Must be a non-negative integer.
*
* Example: `1`
*/
minProperties?: number;
/**
* The maximum number of properties in the object.
* Must be a non-negative integer.
*
* Example: `10`
*/
maxProperties?: number;
/**
* The maximum number of properties in the object.
* Must be a non-negative integer.
*
* Example: `10`
*/
maxProperties?: number;
/**
* A map of property names to arrays of required properties.
* If a property is present, the properties in its array must also be present.
*
* Example: `{ credit_card: ["billing_address"] }`
*/
dependentRequired?: Record<string, string[]>;
/**
* A map of property names to arrays of required properties.
* If a property is present, the properties in its array must also be present.
*
* Example: `{ credit_card: ["billing_address"] }`
*/
dependentRequired?: Record<string, string[]>;
/**
* A map of property names to schemas.
* If a property is present, the object must conform to the corresponding schema.
*
* Example: `{ credit_card: { type: "object", properties: { number: { type: "string" } } } }`
*/
dependentSchemas?: Record<string, Schema>;
/**
* A map of property names to schemas.
* If a property is present, the object must conform to the corresponding schema.
*
* Example: `{ credit_card: { type: "object", properties: { number: { type: "string" } } } }`
*/
dependentSchemas?: Record<string, Schema>;
/**
* An array of allowed values for the object.
* The value must be one of the values in this array.
*
* Example: `[{ name: "John" }, { name: "Jane" }]`
*/
enum?: Record<string, unknown>[];
/**
* An array of allowed values for the object.
* The value must be one of the values in this array.
*
* Example: `[{ name: "John" }, { name: "Jane" }]`
*/
enum?: Record<string, unknown>[];
/**
* A single allowed value for the object.
* The value must be exactly this value.
*
* Example: `{ name: "John" }`
*/
const?: Record<string, unknown>;
/**
* A single allowed value for the object.
* The value must be exactly this value.
*
* Example: `{ name: "John" }`
*/
const?: Record<string, unknown>;
/**
* An array of example values for the object.
* These are for documentation purposes only.
*
* Example: `[{ name: "John", age: 30 }]`
*/
examples?: Record<string, unknown>[];
/**
* An array of example values for the object.
* These are for documentation purposes only.
*
* Example: `[{ name: "John", age: 30 }]`
*/
examples?: Record<string, unknown>[];
/**
* The default value for the object.
* This value will be used if no value is provided.
*
* Example: `{}`
*/
default?: Record<string, unknown>;
/**
* The default value for the object.
* This value will be used if no value is provided.
*
* Example: `{}`
*/
default?: Record<string, unknown>;
/**
* A short title for the schema.
* This is for documentation purposes only.
*
* Example: `"User"`
*/
title?: string;
/**
* A short title for the schema.
* This is for documentation purposes only.
*
* Example: `"User"`
*/
title?: string;
/**
* A description of the schema.
* CommonMark syntax MAY be used for rich text representation.
*
* Example: `"A user object"`
*/
description?: string;
/**
* A description of the schema.
* CommonMark syntax MAY be used for rich text representation.
*
* Example: `"A user object"`
*/
description?: string;
/**
* XML representation metadata for the schema.
* Allows for fine-tuned XML model definitions using the modernized
* nodeType approach in OpenAPI 3.2.0.
*
* Example: `{ nodeType: "element", name: "user" }`
*/
xml?: XML;
/**
* XML representation metadata for the schema.
* Allows for fine-tuned XML model definitions using the modernized
* nodeType approach in OpenAPI 3.2.0.
*
* Example: `{ nodeType: "element", name: "user" }`
*/
xml?: XML;
}