Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@scalar/openapi-types

Package Overview
Dependencies
Maintainers
7
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scalar/openapi-types - npm Package Compare versions

Comparing version
0.8.0
to
0.9.0
+18
dist/helpers/is-array-schema.d.ts
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'array'`.
*
* After narrowing, array-specific properties such as `items`, `prefixItems`,
* `minItems`, `maxItems`, and `uniqueItems` become accessible without a
* manual cast.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export declare const isArraySchema: <T>(schema: T) => schema is [Extract<T, {
type: "array";
}>] extends [never] ? T & {
type: "array";
} : Extract<T, {
type: "array";
}>;
//# sourceMappingURL=is-array-schema.d.ts.map
{"version":3,"file":"is-array-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-array-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAC7B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CACjB,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'array'`.
*
* After narrowing, array-specific properties such as `items`, `prefixItems`,
* `minItems`, `maxItems`, and `uniqueItems` become accessible without a
* manual cast.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export const isArraySchema = (schema) => typeof schema === 'object' && schema !== null && schema.type === 'array';
/**
* Type guard that checks whether a value is a boolean JSON Schema.
*
* In JSON Schema (and therefore OpenAPI 3.1+), a schema can be the literal
* `true` (matches any value) or `false` (matches no value), used in place of
* an object schema. This is different from `isBooleanSchema`, which checks
* for an object schema with `type: 'boolean'`.
*
* Note: the strict `SchemaObject` types in `@scalar/openapi-types/3.0`,
* `/3.1`, and `/3.2` do not include `boolean` in the union, but boolean
* schemas are legal where `SchemaObject | ReferenceObject | boolean` is
* accepted (for example inside `properties` or `additionalProperties`).
*/
export declare const isBooleanJsonSchema: (schema: unknown) => schema is boolean;
//# sourceMappingURL=is-boolean-json-schema.d.ts.map
{"version":3,"file":"is-boolean-json-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-boolean-json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,OAAO,KAAG,MAAM,IAAI,OAAsC,CAAA"}
/**
* Type guard that checks whether a value is a boolean JSON Schema.
*
* In JSON Schema (and therefore OpenAPI 3.1+), a schema can be the literal
* `true` (matches any value) or `false` (matches no value), used in place of
* an object schema. This is different from `isBooleanSchema`, which checks
* for an object schema with `type: 'boolean'`.
*
* Note: the strict `SchemaObject` types in `@scalar/openapi-types/3.0`,
* `/3.1`, and `/3.2` do not include `boolean` in the union, but boolean
* schemas are legal where `SchemaObject | ReferenceObject | boolean` is
* accepted (for example inside `properties` or `additionalProperties`).
*/
export const isBooleanJsonSchema = (schema) => typeof schema === 'boolean';
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'boolean'`.
*
* Note: this checks the OpenAPI/JSON Schema `type` keyword (i.e. a schema
* that validates boolean values). It is different from `isBooleanJsonSchema`,
* which checks whether the schema itself is the literal `true` or `false`.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export declare const isBooleanSchema: <T>(schema: T) => schema is [Extract<T, {
type: "boolean";
}>] extends [never] ? T & {
type: "boolean";
} : Extract<T, {
type: "boolean";
}>;
//# sourceMappingURL=is-boolean-schema.d.ts.map
{"version":3,"file":"is-boolean-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-boolean-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC1D,CAAC,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACvB,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CACkE,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'boolean'`.
*
* Note: this checks the OpenAPI/JSON Schema `type` keyword (i.e. a schema
* that validates boolean values). It is different from `isBooleanJsonSchema`,
* which checks whether the schema itself is the literal `true` or `false`.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export const isBooleanSchema = (schema) => typeof schema === 'object' && schema !== null && schema.type === 'boolean';
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'integer'`.
*
* Note: this guard matches `'integer'` exclusively. Use `isNumericSchema` to
* match both `'number'` and `'integer'`.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export declare const isIntegerSchema: <T>(schema: T) => schema is [Extract<T, {
type: "integer";
}>] extends [never] ? T & {
type: "integer";
} : Extract<T, {
type: "integer";
}>;
//# sourceMappingURL=is-integer-schema.d.ts.map
{"version":3,"file":"is-integer-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-integer-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC1D,CAAC,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACvB,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CACkE,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'integer'`.
*
* Note: this guard matches `'integer'` exclusively. Use `isNumericSchema` to
* match both `'number'` and `'integer'`.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export const isIntegerSchema = (schema) => typeof schema === 'object' && schema !== null && schema.type === 'integer';
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is an
* array of primitive types (e.g. `type: ['string', 'null']`).
*
* Multi-type schemas were introduced in OpenAPI 3.1 (JSON Schema 2020-12).
* In OpenAPI 3.0, `type` is always a single string.
*
* Works with `SchemaObject` types from OpenAPI 3.1 and 3.2.
*/
export declare const isMultiTypeSchema: <T>(schema: T) => schema is [Extract<T, {
type: readonly string[];
}>] extends [never] ? T & {
type: string[];
} : Extract<T, {
type: readonly string[];
}>;
//# sourceMappingURL=is-multi-type-schema.d.ts.map
{"version":3,"file":"is-multi-type-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-multi-type-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EACjC,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAClE,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GACtB,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAC2D,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is an
* array of primitive types (e.g. `type: ['string', 'null']`).
*
* Multi-type schemas were introduced in OpenAPI 3.1 (JSON Schema 2020-12).
* In OpenAPI 3.0, `type` is always a single string.
*
* Works with `SchemaObject` types from OpenAPI 3.1 and 3.2.
*/
export const isMultiTypeSchema = (schema) => typeof schema === 'object' && schema !== null && Array.isArray(schema.type);
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'null'`.
*
* The `'null'` type was introduced in OpenAPI 3.1 (aligning with JSON Schema
* 2020-12). In OpenAPI 3.0, nullability is expressed via `nullable: true`,
* not via `type: 'null'`.
*
* Works with `SchemaObject` types from OpenAPI 3.1 and 3.2.
*/
export declare const isNullSchema: <T>(schema: T) => schema is [Extract<T, {
type: "null";
}>] extends [never] ? T & {
type: "null";
} : Extract<T, {
type: "null";
}>;
//# sourceMappingURL=is-null-schema.d.ts.map
{"version":3,"file":"is-null-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-null-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAC5B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CACf,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'null'`.
*
* The `'null'` type was introduced in OpenAPI 3.1 (aligning with JSON Schema
* 2020-12). In OpenAPI 3.0, nullability is expressed via `nullable: true`,
* not via `type: 'null'`.
*
* Works with `SchemaObject` types from OpenAPI 3.1 and 3.2.
*/
export const isNullSchema = (schema) => typeof schema === 'object' && schema !== null && schema.type === 'null';
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'number'`.
*
* Note: this guard matches `'number'` exclusively. Use `isIntegerSchema` for
* integers, or `isNumericSchema` to match both `'number'` and `'integer'`.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export declare const isNumberSchema: <T>(schema: T) => schema is [Extract<T, {
type: "number";
}>] extends [never] ? T & {
type: "number";
} : Extract<T, {
type: "number";
}>;
//# sourceMappingURL=is-number-schema.d.ts.map
{"version":3,"file":"is-number-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-number-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAC9B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACzD,CAAC,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GACtB,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CACkE,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'number'`.
*
* Note: this guard matches `'number'` exclusively. Use `isIntegerSchema` for
* integers, or `isNumericSchema` to match both `'number'` and `'integer'`.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export const isNumberSchema = (schema) => typeof schema === 'object' && schema !== null && schema.type === 'number';
/**
* Type guard that narrows a `SchemaObject` to the variants whose `type` is
* either `'number'` or `'integer'`.
*
* Numeric schemas share the same validation keywords (`multipleOf`,
* `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`), so a single
* guard is often more convenient than checking both types separately.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export declare const isNumericSchema: <T>(schema: T) => schema is [Extract<T, {
type: "number" | "integer";
}>] extends [never] ? T & {
type: "number" | "integer";
} : Extract<T, {
type: "number" | "integer";
}>;
//# sourceMappingURL=is-numeric-schema.d.ts.map
{"version":3,"file":"is-numeric-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-numeric-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACrE,CAAC,GAAG;IAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,GAClC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,CAM5C,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variants whose `type` is
* either `'number'` or `'integer'`.
*
* Numeric schemas share the same validation keywords (`multipleOf`,
* `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`), so a single
* guard is often more convenient than checking both types separately.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export const isNumericSchema = (schema) => {
if (typeof schema !== 'object' || schema === null) {
return false;
}
const type = schema.type;
return type === 'number' || type === 'integer';
};
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'object'`.
*
* After narrowing, object-specific properties such as `properties`,
* `required`, `additionalProperties`, `patternProperties`, and `propertyNames`
* become accessible without a manual cast.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*
* @example
* ```ts
* const petSchema = specification.components?.schemas?.Pet
*
* if (isObjectSchema(petSchema)) {
* // `petSchema.properties` is now accessible without a cast.
* for (const [name, property] of Object.entries(petSchema.properties ?? {})) {
* console.log(name, property)
* }
* }
* ```
*/
export declare const isObjectSchema: <T>(schema: T) => schema is [Extract<T, {
type: "object";
}>] extends [never] ? T & {
type: "object";
} : Extract<T, {
type: "object";
}>;
//# sourceMappingURL=is-object-schema.d.ts.map
{"version":3,"file":"is-object-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-object-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAC9B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACzD,CAAC,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GACtB,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CACkE,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'object'`.
*
* After narrowing, object-specific properties such as `properties`,
* `required`, `additionalProperties`, `patternProperties`, and `propertyNames`
* become accessible without a manual cast.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*
* @example
* ```ts
* const petSchema = specification.components?.schemas?.Pet
*
* if (isObjectSchema(petSchema)) {
* // `petSchema.properties` is now accessible without a cast.
* for (const [name, property] of Object.entries(petSchema.properties ?? {})) {
* console.log(name, property)
* }
* }
* ```
*/
export const isObjectSchema = (schema) => typeof schema === 'object' && schema !== null && schema.type === 'object';
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'string'`.
*
* After narrowing, string-specific properties such as `minLength`,
* `maxLength`, `pattern`, `contentMediaType`, and `contentEncoding` become
* accessible without a manual cast.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export declare const isStringSchema: <T>(schema: T) => schema is [Extract<T, {
type: "string";
}>] extends [never] ? T & {
type: "string";
} : Extract<T, {
type: "string";
}>;
//# sourceMappingURL=is-string-schema.d.ts.map
{"version":3,"file":"is-string-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-string-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAC9B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACzD,CAAC,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GACtB,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CACkE,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant whose `type` is
* `'string'`.
*
* After narrowing, string-specific properties such as `minLength`,
* `maxLength`, `pattern`, `contentMediaType`, and `contentEncoding` become
* accessible without a manual cast.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export const isStringSchema = (schema) => typeof schema === 'object' && schema !== null && schema.type === 'string';
/**
* Type guard that narrows a `SchemaObject` to the variant where `type` is not
* set.
*
* Untyped schemas are common in OpenAPI documents, for example when the
* schema only uses compositional keywords like `allOf`, `oneOf`, `anyOf`,
* `not`, or `enum` without an explicit `type`.
*
* `ReferenceObject` values (objects with a string `$ref`) and arrays are not
* untyped schemas and are explicitly rejected, so this guard is safe to use
* when walking a `SchemaObject | ReferenceObject` union. To narrow away
* references first, reach for `isDereferenced`.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export declare const isUntypedSchema: <T>(schema: T) => schema is [Extract<T, {
type?: undefined;
$ref?: undefined;
}>] extends [never] ? T & {
type?: undefined;
$ref?: undefined;
} : Extract<T, {
type?: undefined;
$ref?: undefined;
}>;
//# sourceMappingURL=is-untyped-schema.d.ts.map
{"version":3,"file":"is-untyped-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/is-untyped-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,QAAQ,CAAC,KACR,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC7E,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,GAC1C,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,CAKI,CAAA"}
/**
* Type guard that narrows a `SchemaObject` to the variant where `type` is not
* set.
*
* Untyped schemas are common in OpenAPI documents, for example when the
* schema only uses compositional keywords like `allOf`, `oneOf`, `anyOf`,
* `not`, or `enum` without an explicit `type`.
*
* `ReferenceObject` values (objects with a string `$ref`) and arrays are not
* untyped schemas and are explicitly rejected, so this guard is safe to use
* when walking a `SchemaObject | ReferenceObject` union. To narrow away
* references first, reach for `isDereferenced`.
*
* Works with `SchemaObject` types from OpenAPI 2.0, 3.0, 3.1, and 3.2.
*/
export const isUntypedSchema = (schema) => typeof schema === 'object' &&
schema !== null &&
!Array.isArray(schema) &&
schema.type === undefined &&
typeof schema.$ref !== 'string';
+0
-1

@@ -38,3 +38,2 @@ export type { ApiKeySecuritySchemeObject } from './api-key-security-scheme'

Extensions,
MultiTypeObject,
NumericFormat,

@@ -41,0 +40,0 @@ PrimitiveSchemaType,

@@ -96,18 +96,7 @@ import type { DiscriminatorObject } from './discriminator'

} & Extensions
export type MultiTypeObject = SharedProperties &
NumericKeywords &
StringKeywords &
ArrayKeywords &
ObjectKeywords & {
type?: PrimitiveSchemaType
format?: StringFormat | NumericFormat | string
} & Extensions
export type SchemaObject =
| UntypedObject
| OtherTypes
| NumericObject
| StringObject
| ObjectObject
| ArrayObject
| MultiTypeObject
// OpenAPI 3.0 does not support multi-type schemas (`type` must be a single
// string), so there is no MultiTypeObject variant. The single-type case is
// already covered by OtherTypes, NumericObject, StringObject, ObjectObject,
// and ArrayObject.
export type SchemaObject = UntypedObject | OtherTypes | NumericObject | StringObject | ObjectObject | ArrayObject
export {}

@@ -147,3 +147,8 @@ import type { ReferenceObject } from './reference'

ObjectKeywords & {
type?: PrimitiveSchemaType | PrimitiveSchemaType[]
/**
* MultiTypeObject only models the array form. Single-type schemas are
* covered by the dedicated variants (OtherTypes, NumericObject,
* StringObject, ObjectObject, ArrayObject) of the SchemaObject union.
*/
type: PrimitiveSchemaType[]
format?: StringFormat | NumericFormat

@@ -150,0 +155,0 @@ } & Extensions

@@ -19,5 +19,5 @@ import type { EncodingObject } from './encoding'

/** A schema describing the complete content of the request, response, parameter, or header. */
schema?: SchemaObject
schema?: SchemaObject | ReferenceObject
/** A schema describing each item within a [sequential media type](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.2.0.md#sequential-media-types). */
itemSchema?: SchemaObject
itemSchema?: SchemaObject | ReferenceObject
/** A map between a property name and its encoding information, as defined under [Encoding By Name](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.2.0.md#encoding-by-name). The `encoding` field SHALL only apply when the media type is `multipart` or `application/x-www-form-urlencoded`. If no Encoding Object is provided for a property, the behavior is determined by the default values documented for the Encoding Object. This field MUST NOT be present if `prefixEncoding` or `itemEncoding` are present. */

@@ -24,0 +24,0 @@ encoding?: Record<string, EncodingObject>

@@ -147,6 +147,12 @@ import type { ReferenceObject } from './reference'

ObjectKeywords & {
type?: PrimitiveSchemaType | PrimitiveSchemaType[]
/**
* MultiTypeObject only models the array form. Single-type schemas are
* covered by the dedicated variants (OtherTypes, NumericObject,
* StringObject, ObjectObject, ArrayObject) of the SchemaObject union.
*/
type: PrimitiveSchemaType[]
format?: StringFormat | NumericFormat
} & Extensions
export type SchemaObject =
| boolean
| UntypedObject

@@ -153,0 +159,0 @@ | OtherTypes

# @scalar/openapi-types
## 0.9.0
### Minor Changes
- [#9261](https://github.com/scalar/scalar/pull/9261): Add schema discriminator helpers (`isObjectSchema`, `isArraySchema`, `isStringSchema`, `isNumberSchema`, `isIntegerSchema`, `isNumericSchema`, `isBooleanSchema`, `isNullSchema`, `isMultiTypeSchema`, `isUntypedSchema`, `isBooleanJsonSchema`) for narrowing `SchemaObject` unions across OpenAPI 2.0, 3.0, 3.1, and 3.2.
Also tightens `MultiTypeObject` in the strict 3.1 and 3.2 schema types so that `type` is a required `PrimitiveSchemaType[]` (the single-type case is already covered by the dedicated variants), and removes `MultiTypeObject` from the strict 3.0 schema since OpenAPI 3.0 does not support multi-type schemas.
### Patch Changes
- [#9244](https://github.com/scalar/scalar/pull/9244): Allow OpenAPI 3.2 boolean schemas and media type schema references.
## 0.8.0

@@ -4,0 +16,0 @@

@@ -0,2 +1,13 @@

export { isArraySchema } from './is-array-schema.js';
export { isBooleanJsonSchema } from './is-boolean-json-schema.js';
export { isBooleanSchema } from './is-boolean-schema.js';
export { isDereferenced } from './is-dereferenced.js';
export { isIntegerSchema } from './is-integer-schema.js';
export { isMultiTypeSchema } from './is-multi-type-schema.js';
export { isNullSchema } from './is-null-schema.js';
export { isNumberSchema } from './is-number-schema.js';
export { isNumericSchema } from './is-numeric-schema.js';
export { isObjectSchema } from './is-object-schema.js';
export { isStringSchema } from './is-string-schema.js';
export { isUntypedSchema } from './is-untyped-schema.js';
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA"}

@@ -0,1 +1,12 @@

export { isArraySchema } from './is-array-schema.js';
export { isBooleanJsonSchema } from './is-boolean-json-schema.js';
export { isBooleanSchema } from './is-boolean-schema.js';
export { isDereferenced } from './is-dereferenced.js';
export { isIntegerSchema } from './is-integer-schema.js';
export { isMultiTypeSchema } from './is-multi-type-schema.js';
export { isNullSchema } from './is-null-schema.js';
export { isNumberSchema } from './is-number-schema.js';
export { isNumericSchema } from './is-numeric-schema.js';
export { isObjectSchema } from './is-object-schema.js';
export { isStringSchema } from './is-string-schema.js';
export { isUntypedSchema } from './is-untyped-schema.js';

@@ -1,7 +0,31 @@

import type { OpenAPIV3_1 } from '../openapi-types.js';
/**
* Type guard to check if an object is not a ReferenceObject.
* A ReferenceObject is defined by having a $ref property that is a string.
* Type guard that returns `true` when `value` is not a `ReferenceObject`.
*
* A `ReferenceObject` is identified by the presence of a string `$ref`
* property. Use this helper while walking a document that may still contain
* references to narrow values down to their inline shape.
*
* Like the schema discriminators, this works with the `SchemaObject` and
* `ReferenceObject` types from every supported OpenAPI version (2.0, 3.0,
* 3.1, and 3.2). It removes the reference members from the union when they
* can be told apart, and otherwise falls back to an intersection so callers
* still get a usable narrowed type.
*
* @example
* ```ts
* const schema = components.schemas?.Pet
*
* if (isDereferenced(schema)) {
* // `schema` is the inline SchemaObject; `$ref` is ruled out.
* schema.type
* }
* ```
*/
export declare const isDereferenced: <T>(obj: T | OpenAPIV3_1.ReferenceObject) => obj is T;
export declare const isDereferenced: <T>(value: T) => value is [Exclude<T, {
$ref: string;
}>] extends [never] ? T & {
$ref?: undefined;
} : Exclude<T, {
$ref: string;
}>;
//# sourceMappingURL=is-dereferenced.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"is-dereferenced.d.ts","sourceRoot":"","sources":["../../src/helpers/is-dereferenced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC,eAAe,KAAG,GAAG,IAAI,CAGG,CAAA"}
{"version":3,"file":"is-dereferenced.d.ts","sourceRoot":"","sources":["../../src/helpers/is-dereferenced.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAC9B,OAAO,CAAC,KACP,KAAK,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CACZ,CAAA"}
/**
* Type guard to check if an object is not a ReferenceObject.
* A ReferenceObject is defined by having a $ref property that is a string.
* Type guard that returns `true` when `value` is not a `ReferenceObject`.
*
* A `ReferenceObject` is identified by the presence of a string `$ref`
* property. Use this helper while walking a document that may still contain
* references to narrow values down to their inline shape.
*
* Like the schema discriminators, this works with the `SchemaObject` and
* `ReferenceObject` types from every supported OpenAPI version (2.0, 3.0,
* 3.1, and 3.2). It removes the reference members from the union when they
* can be told apart, and otherwise falls back to an intersection so callers
* still get a usable narrowed type.
*
* @example
* ```ts
* const schema = components.schemas?.Pet
*
* if (isDereferenced(schema)) {
* // `schema` is the inline SchemaObject; `$ref` is ruled out.
* schema.type
* }
* ```
*/
export const isDereferenced = (obj) => typeof obj === 'object' &&
obj !== null &&
!('$ref' in obj && typeof obj.$ref === 'string');
export const isDereferenced = (value) => typeof value === 'object' && value !== null && typeof value.$ref !== 'string';

@@ -19,3 +19,3 @@ {

],
"version": "0.8.0",
"version": "0.9.0",
"engines": {

@@ -22,0 +22,0 @@ "node": ">=22"

@@ -55,2 +55,69 @@ # Scalar OpenAPI Types

## Helpers
`@scalar/openapi-types/helpers` ships a small set of runtime helpers for working
with the type definitions above. They are written to work with `SchemaObject`
across all supported OpenAPI versions (2.0, 3.0, 3.1, and 3.2).
### `isDereferenced(value)`
Type guard that returns `true` when `value` is not a `ReferenceObject` (i.e. it
does not have a string `$ref` property). Useful when walking a document that may
mix references and inline objects. Like the schema discriminators, it narrows
the reference members out of a `SchemaObject | ReferenceObject` union from any
supported OpenAPI version.
```ts
import { isDereferenced } from '@scalar/openapi-types/helpers'
const schema = components.schemas?.Pet
if (isDereferenced(schema)) {
// `schema` is narrowed to the inline SchemaObject and `$ref` is ruled out
schema.type
}
```
### Schema discriminators
Schema discriminators narrow a `SchemaObject` union to the variant whose `type`
matches the guard, so type-specific properties (such as `properties`, `items`,
or `minLength`) become accessible without a manual cast.
| Helper | Matches when… |
| --------------------- | ------------------------------------------------------ |
| `isObjectSchema` | `type === 'object'` |
| `isArraySchema` | `type === 'array'` |
| `isStringSchema` | `type === 'string'` |
| `isNumberSchema` | `type === 'number'` |
| `isIntegerSchema` | `type === 'integer'` |
| `isNumericSchema` | `type === 'number'` or `type === 'integer'` |
| `isBooleanSchema` | `type === 'boolean'` |
| `isNullSchema` | `type === 'null'` (OpenAPI 3.1+) |
| `isMultiTypeSchema` | `type` is an array of primitive types (OpenAPI 3.1+) |
| `isUntypedSchema` | `type` is not set |
| `isBooleanJsonSchema` | the schema itself is the literal `true` or `false` |
```ts
import { isArraySchema, isObjectSchema } from '@scalar/openapi-types/helpers'
import type { SchemaObject } from '@scalar/openapi-types/3.1'
function describe(schema: SchemaObject) {
if (isObjectSchema(schema)) {
return Object.keys(schema.properties ?? {})
}
if (isArraySchema(schema)) {
return schema.items
}
return null
}
```
> `isBooleanSchema` matches an OpenAPI schema with `type: 'boolean'`.
> `isBooleanJsonSchema` matches the JSON Schema shorthand where the schema
> itself is `true` (allow any value) or `false` (allow no value). Use the one
> that fits your check.
## Community

@@ -57,0 +124,0 @@