Skip to content

ReferenceContainer

JonathanMontane edited this page May 9, 2016 · 3 revisions

A ReferenceContainer component acts as a central component that lists all the References of an API. It stores each Reference in a ReferenceCache that acts as a helper to speed-up resolutions.

Import

/* if in src/ */
import { ReferenceContainer } from './models/Core'

Interface

ReferenceContainer extends Immutable.Record using the following pattern:

class ReferenceContainer extends Immutable.Record({
    cache: new Immutable.OrderedMap()
})

Fields

ReferenceContainer.cache
  • ReferenceContainer.cache contains all the ReferenceCaches. We strongly advise against manipulating it directly. Use the class methods instead.

Methods

ReferenceContainer.set
  • ReferenceContainer.set(uri, reference) returns a new ReferenceContainer also containing the new uri, reference pair, where the Reference is stored in a ReferenceCache. If an equivalent uri already exists in this ReferenceContainer, it will be replaced.
ReferenceContainer.get
  • ReferenceContainer.get(uri, depth = 0) returns the Reference corresponding to the uri, resolved to the depth level.
ReferenceContainer.delete
  • ReferenceContainer.delete(uri) returns a new ReferenceContainer without the uri key in the ReferenceContainer.cache.

Example

Please note that this example is abstract, and is there purely to represent the different interactions with ReferenceContainer. The data may be non-sensical.

import references from './samples/references-examples'
import referenceCaches from './samples/reference-caches-examples'

import { ReferenceContainer } from './models/Core'

let container = new ReferenceContainer({
    cache: new Immutable.OrderedMap({
        '#/definitions/User': referenceCaches[0],
        '#/definitions/Admin': referenceCaches[1],
    })
})

container = container
    .set('cache', new Immutable.OrderedMap({
        '#/definitions/User': referenceCaches[1],
        '#/definitions/Admin': referenceCaches[2],
    }))

container = container
    .set('#/definitions/Company', referenceCaches[0])
    .delete('#/definitions/Company')

let resolvedReference = container.get('#/definitions/User', 3)