register method

void register(
  1. String name,
  2. T component, {
  3. Type? representation,
})

Adds a component for name so that it can be referenced later.

component will be stored in the OpenAPI document. The component will be usable by other objects by its name.

If this component is represented by a class, provide it as representation. Objects may reference either name or representation when using a component.

Implementation

void register(String name, T component, {Type? representation}) {
  if (_componentMap.containsKey(name)) {
    return;
  }

  if (representation != null &&
      _typeReferenceMap.containsKey(representation)) {
    return;
  }

  _componentMap[name] = component;

  if (representation != null) {
    final refObject = getObject(name);
    _typeReferenceMap[representation] = refObject;

    if (_resolutionMap.containsKey(representation)) {
      _resolutionMap[representation]!.complete(refObject);
      _resolutionMap.remove(representation);
    }
  }
}