Class SchemaGenerator

java.lang.Object
com.hypixel.hytale.server.core.schema.SchemaGenerator

public class SchemaGenerator extends Object
Central registry and generator for JSON schemas.

Provides registration APIs for config schemas and custom asset schemas, and a generate(Path, Path) method that orchestrates full schema generation including asset schemas from AssetRegistry.

  • Constructor Details

    • SchemaGenerator

      public SchemaGenerator()
  • Method Details

    • registerConfig

      public static void registerConfig(@Nonnull String name, @Nonnull BuilderCodec<?> codec, @Nullable String virtualPath, @Nullable List<String> fileMatchPatterns)
      Registers a config schema for generation.
      Parameters:
      name - the display name and schema identifier (e.g. "HytaleServerConfig")
      codec - the codec to generate the schema from
      virtualPath - optional virtual path for documentation navigation (e.g. "Config")
      fileMatchPatterns - optional file match patterns relative to server root for VSCode
    • registerAssetSchema

      public static void registerAssetSchema(@Nonnull String fileName, @Nonnull Function<SchemaContext, Schema> factory, @Nullable List<String> fileMatchPatterns, @Nullable String extension)
      Registers a custom asset-like schema for generation (e.g. InstanceConfig, NPCRole).
      Parameters:
      fileName - the output filename (e.g. "InstanceConfig.json")
      factory - a function that creates the schema given a context
      fileMatchPatterns - optional file match patterns relative to /Server/ for VSCode
      extension - optional file extension (e.g. ".bson"); null defaults to ".json"
    • generateAssetSchemas

      @Nonnull public static Map<String,Schema> generateAssetSchemas()
      Generates all asset schemas (from AssetRegistry and registered custom schemas) and returns them in memory, including shared definitions.

      This is used by the Asset Editor to send schemas to clients without writing to disk.

      Returns:
      a map of filename to schema, including asset schemas and shared definitions
    • generate

      public static void generate(@Nullable Path assetOutputDir, @Nullable Path configOutputDir)
      Generates all schemas and writes them to the specified output directories.

      All schemas are always processed through the shared context to build complete shared definitions. Output is written only to non-null directories.

      Parameters:
      assetOutputDir - if non-null, asset schemas are written here
      configOutputDir - if non-null, config schemas are written here
    • toFileName

      @Nonnull public static String toFileName(@Nonnull String name)
      Converts a schema name to a safe filename. Replaces colons with dots for cross-platform compatibility.
      Parameters:
      name - the schema name
      Returns:
      a safe filename ending in ".json"
    • writeSchemas

      public static void writeSchemas(@Nonnull Map<String,Schema> schemas, @Nonnull Path schemaDir)
      Writes a map of schemas to disk as JSON files.
      Parameters:
      schemas - the schemas to write, keyed by filename
      schemaDir - the directory to write schema files into
    • addVsCodeSchemaLink

      public static void addVsCodeSchemaLink(@Nonnull org.bson.BsonDocument vsCodeConfig, @Nonnull String schemaFileName, @Nonnull List<String> fileMatchPatterns, @Nullable String extension)
      Adds a VSCode schema association to the given config document.
      Parameters:
      vsCodeConfig - the VSCode settings document
      schemaFileName - the schema filename (without path prefix)
      fileMatchPatterns - the file match patterns for VSCode
      extension - optional file extension to associate with JSON (e.g. ".bson")