Scala
Generate Scala classes, one file per class, enum and type.
ohi get w3c/prov-oohi linkml to scala --package org.example.prov \ --to src/org/example/prov/ prov-o.linkml.yamlimport ohi_linkml
with ohi_linkml.load_file("prov-o.linkml.yaml") as schema: files = schema.scala(package="org.example.prov")import { readFileSync } from "node:fs";import { LinkML } from "@neverblink/linkml";
const yaml = readFileSync("prov-o.linkml.yaml", "utf8");const { view, report } = LinkML.loadFromString(yaml, {});if (!view) throw new Error(JSON.stringify(report));const files = view.scala({ package: "org.example.prov" });import eu.neverblink.linkml.generator.options.ScalaGeneratorOptionsimport eu.neverblink.linkml.generator.scala.ScalaGeneratorimport eu.neverblink.linkml.schemaview.{SchemaIssues, SchemaView}
val loaded = SchemaView.loadSchemaViewFromUri("prov-o.linkml.yaml")given SchemaView = SchemaIssues.orThrow(loaded)val files = ScalaGenerator().generate( ScalaGeneratorOptions(`package` = "org.example.prov"),)#include <stddef.h>#include "ohi_linkml.h"
linkml_init_threads();char *report = NULL, *error = NULL;long long schema = linkml_load_file("prov-o.linkml.yaml", NULL, &report, &error);char *files = linkml_scala( schema, "{\"package\": \"org.example.prov\"}", &error);linkml_free(files);linkml_free(report);linkml_free(error);linkml_close(schema);Options
Section titled “Options”error_handlingScalaErrorHandlingdefault annotationCLI
--error-handlingScala errorHandlingHow the functions of the schema report their errors.
annotationEach error class gets an exception class, and the method is annotated with@throwsfor each of them.eitherThe method returnsEither[E1 | E2, R], with the error classes themselves on the left. No exception classes are generated. A function with noerrorsreturnsRas it is.
generate_emit_prefixesbooleandefault trueCLI
--generate-emit-prefixesScala generateEmitPrefixesWhether to generate a Prefixes object with the schema's emit_prefixes.
metadata_languagestringdefault enCLI
--metadata-languageScala metadataLanguageThe language of the titles and descriptions in the output, for schemas with text in more than one language.
packagestringdefault eu.neverblink.linkml.metamodelCLI
--packageScala `package`The package of the generated classes.
skip_leaf_interfacesbooleandefault trueCLI
--skip-leaf-interfacesScala skipLeafInterfacesWhether a concrete class that no other class extends with is_a or mixins becomes one case class, instead of an interface and an ...Impl case class. Turn it off when other code has to extend the generated classes.