Skip to main content

dicebear_schema/
schema.rs

1// -----------------------------------------------------------------------------
2// MIT License
3//
4// Copyright (c) 2026 Florian Körner
5//
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the "Software"), to deal
8// in the Software without restriction, including without limitation the rights
9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10// copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12//
13// The above copyright notice and this permission notice shall be included in all
14// copies or substantial portions of the Software.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22// SOFTWARE.
23// -----------------------------------------------------------------------------
24
25//! DiceBear JSON Schema definitions, embedded at compile time.
26//!
27//! This is a pure-data crate. It mirrors the npm (`@dicebear/schema`), Composer
28//! (`dicebear/schema`) and PyPI (`dicebear-schema`) packages: the same source
29//! schemas under `src/`, with no logic. Consumers parse and validate (e.g. with
30//! the `jsonschema` crate); this crate only ships the bytes.
31//!
32//! Unlike npm — which serves the minified `dist/` over the browser — Rust embeds
33//! the JSON into the binary and parses it at runtime, so the unminified `src/`
34//! files are used directly, matching the Python and PHP packages.
35
36/// `definition.json` — JSON Schema for DiceBear style definition files.
37pub const DEFINITION: &str = include_str!("src/definition.json");
38
39/// `options.json` — JSON Schema for DiceBear avatar options.
40pub const OPTIONS: &str = include_str!("src/options.json");
41
42/// Returns the raw JSON for the named schema (`"definition"` or `"options"`), or
43/// `None` if the name is unknown.
44///
45/// Companion to `all`: `all()` lists the names, `get(name)` fetches one. Mirrors
46/// the `dicebear-styles` crate's API.
47pub fn get(name: &str) -> Option<&'static str> {
48    match name {
49        "definition" => Some(DEFINITION),
50        "options" => Some(OPTIONS),
51        _ => None,
52    }
53}
54
55/// Names of every embedded schema (`"definition"`, `"options"`).
56pub fn all() -> Vec<&'static str> {
57    vec!["definition", "options"]
58}