HttpMediaType
Package: @opra/common
HttpMediaType is the base class that describes a typed content block — a body payload with an optional MIME type, an OPRA data type for validation, and multipart field declarations. It is extended by both HttpRequestBody content entries and HttpOperationResponse.
Inheritance
DocumentElement
└── HttpMediaType
├── HttpOperationResponse
└── HttpMultipartField
Properties
| Property | Type | Description |
|---|---|---|
type | DataType | undefined | The OPRA data type used to decode/encode the body. |
contentType | string | string[] | undefined | Expected MIME type(s) (e.g. 'application/json', ['application/json', 'application/xml']). |
contentEncoding | string | undefined | Content encoding (e.g. 'gzip'). |
description | string | undefined | Human-readable description. |
isArray | boolean | undefined | Whether the body is an array of the declared type. |
example | string | undefined | A single inline example. |
examples | Record<string, string> | undefined | Named examples. |
multipartFields | HttpMultipartField[] | Declared multipart fields (files and form fields). |
maxFields | number | undefined | Maximum number of multipart fields. |
maxFieldsSize | number | undefined | Maximum total size of non-file fields in bytes. |
maxFiles | number | undefined | Maximum number of uploaded files. |
maxFileSize | number | undefined | Maximum size per uploaded file in bytes. |
maxTotalFileSize | number | undefined | Maximum total size of all uploaded files in bytes. |
Methods
findMultipartField(fieldName, fieldType?)
Finds a declared multipart field by name (case-insensitive string or RegExp) and optional type ('file' or 'field').
mediaType.findMultipartField('avatar', 'file');
mediaType.findMultipartField('description', 'field');
findMultipartField(
fieldName: string,
fieldType?: 'file' | 'field'
): HttpMultipartField | undefined
generateCodec(codec, options?)
Compiles a validation/transformation function for the body's data type. If the body has no declared type but specifies a JSON content type, falls back to an object validator. Wraps in an array validator when isArray is true.
generateCodec(
codec: 'encode' | 'decode',
options?: DataType.GenerateCodecOptions
): Validator
toJSON(options?)
Returns an OpraSchema.HttpMediaType plain object for schema export.
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpMediaType
→ HttpRequestBody · HttpOperationResponse · HttpMultipartField