Schemas
OasVoid
Represents a void (empty) schema in the OpenAPI Specification.
The OasVoid class represents the absence of a value or content, commonly used in scenarios where operations don't return any content (like HTTP 204 No Content responses), optional properties that might not be present, or fallback cases in schema processing where no specific type is defined.
This class serves as a type-safe representation of "nothing" in the OpenAPI type system, enabling proper handling of void responses and empty schemas throughout the SKMTC pipeline.
Key Features
- Empty Content Representation: Models operations that return no content
- Type Safety: Provides a concrete type for void/empty scenarios
- Schema Processing: Handles missing or undefined schema definitions
- Factory Pattern: Convenient
empty()static method for common usage - Pipeline Integration: Works seamlessly with the SKMTC processing pipeline
Signature
import { OasVoid } from '@skmtc/core'
class OasVoid extends OasBaseExamples
import { OasVoid } from '@skmtc/core';
const emptyResponse = new OasVoid({
title: 'No Content',
description: 'Operation completed successfully with no response body'
});
// Used for HTTP 204 No Content responsesconst voidSchema = OasVoid.empty();
// Equivalent to new OasVoid({})
// Commonly used as a fallback or placeholderconst deleteOperation = new OasOperation({
path: '/users/{id}',
method: 'delete',
responses: {
'204': new OasResponse({
description: 'User deleted successfully',
content: {
// No content for successful deletion
}
}),
'404': new OasResponse({
description: 'User not found'
})
}
});
// The void response indicates successful deletion with no return valuefunction processSchema(schema: OasSchema | undefined): OasSchema {
if (!schema) {
return OasVoid.empty(); // Fallback for missing schemas
}
return schema;
}
// Ensures type safety even when schemas are missingconst userProfile = new OasObject({
properties: {
name: new OasString({ description: 'User name' }),
avatar: new OasString({
description: 'Avatar URL',
nullable: true
}),
// Some properties might be processed as void if not defined
metadata: processOptionalSchema(rawSchema.metadata) // might return OasVoid
}
});// Common HTTP operations that return void/empty content:
// DELETE - Resource removal
const deleteResponse = new OasVoid({
title: 'Deletion Successful',
description: 'Resource was successfully deleted'
});
// PUT - Update with no response body
const updateResponse = new OasVoid({
title: 'Update Successful',
description: 'Resource was successfully updated'
});
// POST - Action with no return value
const actionResponse = new OasVoid({
title: 'Action Completed',
description: 'Action was successfully performed'
});class TypeScriptGenerator extends ModelProjectionBase {
generateType(schema: OasSchema): string {
if (schema.type === 'void') {
return 'void'; // TypeScript void type
}
// Handle other types...
return 'unknown';
}
}
// Generates:
// async function deleteUser(id: string): Promise<void>Constructor
constructor
constructor(fields?: VoidFields, context?: ParseContextType)Properties
Object is part the 'schema' set which is used to define data types in an OpenAPI document.
Constant value 'void' useful for type narrowing and tagged unions.
A short summary of the value.
A description of the value.
Methods
OasVoid.empty
OasVoid.empty(): OasVoidisRef
isRef(): this is OasRef<'schema'>isReadOnly
isReadOnly(): booleanAlways false: this schema has no readOnly.
isWriteOnly
isWriteOnly(): booleanAlways false: this schema has no writeOnly.
resolve
resolve(): OasVoidresolveOnce
resolveOnce(): OasVoid