Docs@skmtc/core

Schemas

CLASS

OasVoid

@skmtc/core 0.63.4

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 OasBase

Examples

Basic void schema for empty responses
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 responses
Using the empty factory method
const voidSchema = OasVoid.empty();

// Equivalent to new OasVoid({})
// Commonly used as a fallback or placeholder
In operation responses
const 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 value
As a schema fallback
function processSchema(schema: OasSchema | undefined): OasSchema {
  if (!schema) {
    return OasVoid.empty(); // Fallback for missing schemas
  }
  return schema;
}

// Ensures type safety even when schemas are missing
In optional object properties
const 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
  }
});
HTTP operations with void responses
// 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'
});
In code generation
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

oasType, 'schema'

Object is part the 'schema' set which is used to define data types in an OpenAPI document.

type, 'void'

Constant value 'void' useful for type narrowing and tagged unions.

title, string | undefined

A short summary of the value.

description, string | undefined

A description of the value.

Methods

OasVoid.empty

OasVoid.empty(): OasVoid

isRef

isRef(): this is OasRef<'schema'>

isReadOnly

isReadOnly(): boolean

Always false: this schema has no readOnly.

isWriteOnly

isWriteOnly(): boolean

Always false: this schema has no writeOnly.

resolve

resolve(): OasVoid

resolveOnce

resolveOnce(): OasVoid