# OasIntersection

CLASS in `@skmtc/core 0.63.4`

An `allOf` that keeps at least one reference: a value matches every member.

Core merges the members of an `allOf` into one schema. A reference that
`skmtc.config.json` `parse.intersections` keeps is not merged: the schema is an
`OasIntersection` of the kept references, and at most one other member, which
the other members of the `allOf` merge into. By default those are the
references that close a cycle.

## Signature

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

class OasIntersection extends OasBase
```

## Examples

Example:

```ts
// LineString: { allOf: [{ $ref: Geometry }, { properties: { coordinates } }] },
// where a property of Geometry leads back to LineString
lineString.members // [OasRef Geometry, OasObject { coordinates }]
```

## Constructor

### constructor

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

## Properties

- `oasType` ('schema'): Object is part the 'schema' set which is used to define data types in an OpenAPI document.
- `type` ('intersection'): Constant value 'intersection' useful for type narrowing and tagged unions.
- `title` (string | undefined): A short summary of the intersection.
- `description` (string | undefined): A description of the intersection.
- `externalDocs` (OasExternalDocs | undefined): External documentation for the intersection.
- `nullable` (boolean | undefined): Indicates whether the value can be null.
- `readOnly` (boolean | undefined): Whether the value is sent by the API only.
- `writeOnly` (boolean | undefined): Whether the value is sent in a request only.
- `deprecated` (boolean | undefined): Whether the value is deprecated.
- `members` ((OasSchema | OasRef<'schema'>)[]): The schemas, or references to schemas, that a value matches all of.
- `extensionFields` (Record<string, unknown> | undefined): Specification Extension fields
- `example` (unknown): An example of the value.
- `default` (unknown): The default value.
- `not` (OasUnknown | undefined): The schema's `not`, kept as an `OasUnknown` under `skmtc.config.json` `parse.not: unknown`. `undefined` otherwise.

## Methods

### isRef

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

### isReadOnly

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

Whether the value is `readOnly`: the intersection or one of its members is.

### isWriteOnly

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

Whether the value is `writeOnly`: the intersection or one of its members is.

### toParts

```ts
toParts(): Exclude<OasSchema, OasIntersection>[]
```

The schemas a value matches all of, with each reference resolved and each
intersection inside replaced by its own members. Each is given once, so a
member that leads back to an intersection ends. A reference that names
nothing is left out.

### toTargetParts

```ts
toTargetParts(): Exclude<OasSchema, OasIntersection>[]
```

`toParts` without the keywords next to the references. `clone` reads
these while a reference to this intersection resolves, so no reference may
be resolved with its keywords here.

### clone

```ts
clone(ref?: OasRef<'schema'>): OasIntersection
```

A copy of this schema with what `ref` adds at its site applied, as
`OasUnion.clone` does: the keywords that this type takes, a
sibling's value winning. The keywords of an object next to `ref`
(`properties`, `required`) are one more member, unless the members say
the same. This schema does not
change, and the copy shares its members.

### traverse

```ts
traverse(path: SchemaPath): OasSchema | OasRef<'schema'>
```

### resolve

```ts
resolve(): OasIntersection
```

### resolveOnce

```ts
resolveOnce(): OasIntersection
```

### toJsonSchema

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