# OasParameter

CLASS in `@skmtc/core 0.63.4`

Represents a Parameter Object in the OpenAPI Specification.

The `OasParameter` class encapsulates the definition of a single operation parameter,
including its location, data type, validation rules, and serialization behavior.
Parameters can be located in the path, query string, headers, or cookies.

This class provides comprehensive support for parameter validation, serialization
styles, and complex data types through schema definitions or content specifications.


**Key Features**


- **Location Support**: Path, query, header, and cookie parameters
- **Schema Validation**: Comprehensive data type validation through schemas
- **Serialization Styles**: Various parameter serialization formats
- **Content Types**: Support for complex parameter content with media types
- **Examples & Documentation**: Parameter examples and descriptive documentation
- **Advanced Options**: Empty values, reserved characters, and explode behavior

## Signature

```ts
import { OasParameter } from '@skmtc/core'

class OasParameter extends OasBase
```

## Examples

Basic path parameter:

```ts
import { OasParameter, OasString } from '@skmtc/core';

const userIdParam = new OasParameter({
  name: 'userId',
  location: 'path',
  description: 'Unique identifier for the user',
  required: true,
  schema: new OasString({
    pattern: '^[0-9a-f]{24}$',
    example: '507f1f77bcf86cd799439011'
  }),
  style: 'simple',
  explode: false
});

// Used in path: /users/{userId}
```

Query parameter with validation:

```ts
const pageSizeParam = new OasParameter({
  name: 'pageSize',
  location: 'query',
  description: 'Number of items to return per page',
  required: false,
  schema: new OasInteger({
    minimum: 1,
    maximum: 100,
    default: 20
  }),
  style: 'form',
  explode: true,
  examples: {
    small: new OasExample({ value: 10 }),
    medium: new OasExample({ value: 25 }),
    large: new OasExample({ value: 50 })
  }
});

// Used in query: ?pageSize=20
```

Header parameter:

```ts
const authHeaderParam = new OasParameter({
  name: 'Authorization',
  location: 'header',
  description: 'Bearer token for authentication',
  required: true,
  schema: new OasString({
    pattern: '^Bearer [A-Za-z0-9+/=]+$',
    example: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
  }),
  style: 'simple',
  explode: false
});
```

Complex parameter with content:

```ts
const filterParam = new OasParameter({
  name: 'filter',
  location: 'query',
  description: 'Complex filter object',
  required: false,
  content: {
    'application/json': new OasMediaType({
      schema: new OasObject({
        properties: {
          category: new OasString(),
          priceRange: new OasObject({
            properties: {
              min: new OasNumber(),
              max: new OasNumber()
            }
          })
        }
      })
    })
  },
  style: 'deepObject',
  explode: true
});

// Used as: ?filter[category]=electronics&filter[priceRange][min]=100
```

Array parameter with explode:

```ts
const tagsParam = new OasParameter({
  name: 'tags',
  location: 'query',
  description: 'Filter by multiple tags',
  required: false,
  schema: new OasArray({
    items: new OasString(),
    minItems: 1,
    maxItems: 10
  }),
  style: 'form',
  explode: true // Results in: ?tags=tech&tags=api&tags=rest
});

// Without explode: ?tags=tech,api,rest
// With explode: ?tags=tech&tags=api&tags=rest
```

Cookie parameter:

```ts
const sessionParam = new OasParameter({
  name: 'sessionId',
  location: 'cookie',
  description: 'Session identifier cookie',
  required: false,
  schema: new OasString({
    minLength: 32,
    maxLength: 128
  }),
  style: 'form',
  explode: false
});
```

## Constructor

### constructor

```ts
constructor(fields: ParameterFields, context?: ParseContextType)
```

Creates a new OasParameter instance.

- `fields`: Parameter configuration fields including name, location, schema, and serialization options

## Properties

- `oasType` ('parameter'): Type identifier for OAS parameter objects
- `name` (string): The name of the parameter
- `location` (OasParameterLocation): Where the parameter is located (path, query, header, cookie)
- `description` (string | undefined): A brief description of the parameter's purpose and usage
- `required` (boolean | undefined): Determines whether this parameter is mandatory for the operation
- `deprecated` (boolean | undefined): Indicates that the parameter is deprecated and should be avoided
- `allowEmptyValue` (boolean | undefined): Whether to allow empty values for this parameter
- `allowReserved` (boolean | undefined): Whether reserved characters are allowed in parameter values
- `schema` (OasSchema | OasRef<'schema'> | undefined): The schema defining the parameter's data type and validation rules
- `examples` (Record<string, OasExample | OasRef<'example'>> | undefined): Example values demonstrating parameter usage
- `content` (Record<string, OasMediaType> | undefined): Media type definitions for complex parameter content
- `style` (OasParameterStyle | undefined): The serialization style for the parameter (form, simple, etc.)
- `explode` (boolean | undefined): Whether to explode parameter values into separate key-value pairs
- `extensionFields` (Record<string, unknown> | undefined): Custom extension fields (x-* properties) defined for this parameter

## Methods

### isRef

```ts
isRef(): this is OasRef<'parameter'>
```

Determines if this parameter is a reference object.

Returns: Always false since this is a concrete parameter instance, not a reference

### isReadOnly

```ts
isReadOnly(): boolean
```

Always `false`: `readOnly` is a schema keyword.

### isWriteOnly

```ts
isWriteOnly(): boolean
```

Always `false`: `writeOnly` is a schema keyword.

### resolve

```ts
resolve(): OasParameter
```

Resolves this parameter object.

Returns: The parameter instance itself since it's already a concrete object

### resolveOnce

```ts
resolveOnce(): OasParameter
```

Resolves this parameter object one level.

Returns: The parameter instance itself since it's already a concrete object

### toSchema

```ts
toSchema(mediaType?: string): OasSchema | OasRef<'schema'>
```

Extracts the schema for this parameter.

Returns the direct schema if available, or extracts schema from content
for the specified media type. When `content` has exactly one entry, its
schema is used whatever the media type.

- `mediaType`: Media type to extract schema from when using content definitions, an exact lookup. Omitted: the JSON media type (`application/json`, else the first JSON-like type, else `*\/*`).

Returns: The parameter's schema object

Throws:

- `Error`: Error if the parameter has neither schema nor content, or no schema is found for the specified media type

### toJsonSchema

```ts
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.ParameterObject
```

Converts this OAS parameter to an OpenAPI v3 JSON schema representation.

- `options`: Conversion options including reference handling and formatting preferences

Returns: OpenAPI v3 parameter object with all properties and validation constraints
