extractModelDefinition static method

SerializableModelDefinition? extractModelDefinition(
  1. ModelSource modelSource,
  2. List<TypeDefinition> extraClasses
)

Best effort attempt to extract a model definition from a yaml file.

Implementation

static SerializableModelDefinition? extractModelDefinition(
    ModelSource modelSource, List<TypeDefinition> extraClasses) {
  var outFileName = _transformFileNameWithoutPathOrExtension(
    modelSource.yamlSourceUri,
  );
  var yamlErrorCollector = ErrorCollector();
  YamlMap? documentContents = _loadYamlMap(
    modelSource.yaml,
    modelSource.yamlSourceUri,
    yamlErrorCollector,
  );

  if (yamlErrorCollector.errors.isNotEmpty) return null;
  if (documentContents == null) return null;

  var definitionType = _findDefinitionType(documentContents);
  var docsExtractor = YamlDocumentationExtractor(modelSource.yaml);

  if (definitionType == null) return null;

  switch (definitionType) {
    case Keyword.classType:
      return ModelParser.serializeClassFile(
        Keyword.classType,
        modelSource,
        outFileName,
        documentContents,
        docsExtractor,
        extraClasses,
      );
    case Keyword.exceptionType:
      return ModelParser.serializeClassFile(
        Keyword.exceptionType,
        modelSource,
        outFileName,
        documentContents,
        docsExtractor,
        extraClasses,
      );
    case Keyword.enumType:
      return ModelParser.serializeEnumFile(
        modelSource,
        outFileName,
        documentContents,
        docsExtractor,
      );
    default:
      return null;
  }
}