# OasMediaType

CLASS in `@skmtc/core 0.63.4`

Represents a Media Type Object in the OpenAPI Specification.

The `OasMediaType` class encapsulates the definition of content for different
media types in request bodies and responses. It defines the structure, format,
and validation rules for content using schemas and provides examples for
documentation and testing purposes.

This class supports various content types including JSON, XML, form data,
file uploads, and binary content, making it essential for describing API
request and response payloads.


**Key Features**


- **Schema Validation**: Define content structure through OpenAPI schemas
- **Multiple Examples**: Rich example support for documentation and testing
- **Encoding Support**: Handle multipart and form data encoding
- **Content Type Support**: JSON, XML, binary, form data, and more
- **Reference Integration**: Work seamlessly with schema references

## Signature

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

class OasMediaType extends OasBase
```

## Examples

JSON content type:

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

const jsonContent = new OasMediaType({
  mediaType: 'application/json',
  schema: new OasObject({
    properties: {
      name: new OasString(),
      email: new OasString({ format: 'email' })
    }
  }),
  examples: {
    user: new OasExample({
      summary: 'Sample user',
      value: { name: 'John Doe', email: 'john@example.com' }
    })
  }
});
```

File upload with multipart form data:

```ts
const fileUpload = new OasMediaType({
  mediaType: 'multipart/form-data',
  schema: new OasObject({
    properties: {
      file: new OasString({ format: 'binary' }),
      description: new OasString()
    }
  }),
  encoding: {
    file: {
      contentType: 'image/png, image/jpeg',
      style: 'form'
    }
  }
});
```

XML content with namespace:

```ts
const xmlContent = new OasMediaType({
  mediaType: 'application/xml',
  schema: new OasObject({
    properties: {
      product: new OasRef({ $ref: '#/components/schemas/Product' })
    }
  }),
  examples: {
    sample: new OasExample({
      value: '<product><name>Widget</name><price>19.99</price></product>'
    })
  }
});
```

## Constructor

### constructor

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

Creates a new OasMediaType instance.

- `fields`: Media type configuration including content schema, examples, and encoding

## Properties

- `oasType` ('mediaType'): Type identifier for this OAS media type
- `mediaType` (string): The media type identifier (e.g., 'application/json', 'text/xml')
- `schema` (OasSchema | OasRef<'schema'> | undefined): The schema defining the structure and validation rules for the content
- `itemSchema` (OasSchema | OasRef<'schema'> | undefined): The schema of each item in a sequential media type (OpenAPI 3.2)
- `examples` (Record<string, OasExample | OasRef<'example'>> | undefined): Example values demonstrating the media type content
- `extensionFields` (Record<string, unknown> | undefined): Custom extension fields (x-* properties) defined for this media type
- `encoding` (Record<string, unknown> | undefined): Encoding information for multipart and form data serialization
- `prefixEncoding` (Record<string, unknown>[] | undefined): Positional Encoding Objects for a multipart array (OpenAPI 3.2), stored as-is
- `itemEncoding` (Record<string, unknown> | undefined): Encoding Object for each array item (OpenAPI 3.2), stored as-is

## Methods

### toJsonSchema

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

Converts this OAS media type to an OpenAPI v3 JSON schema representation.

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

Returns: OpenAPI v3 media type object with schema and examples
