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`), PyPI (`dicebear-schema`), Go and pub.dev
29//! (`dicebear_schema`) packages: the same source schemas under `src/`, with no
30//! logic. Consumers parse and validate (e.g. with the `jsonschema` crate); this
31//! crate only ships the bytes.
32//!
33//! Unlike npm — which serves the minified `dist/` over the browser — Rust embeds
34//! the JSON into the binary and parses it at runtime, so the unminified `src/`
35//! files are used directly, matching the Python, PHP, Go and Dart packages.
36
37/// `definition.json` — JSON Schema for DiceBear style definition files.
38pub const DEFINITION: &str = include_str!("src/definition.json");
39
40/// `options.json` — JSON Schema for DiceBear avatar options.
41pub const OPTIONS: &str = include_str!("src/options.json");
42
43/// Returns the raw JSON for the named schema (`"definition"` or `"options"`), or
44/// `None` if the name is unknown.
45///
46/// Companion to `all`: `all()` lists the names, `get(name)` fetches one. Mirrors
47/// the `dicebear-styles` crate's API.
48pub fn get(name: &str) -> Option<&'static str> {
49    match name {
50        "definition" => Some(DEFINITION),
51        "options" => Some(OPTIONS),
52        _ => None,
53    }
54}
55
56/// Names of every embedded schema (`"definition"`, `"options"`).
57pub fn all() -> Vec<&'static str> {
58    vec!["definition", "options"]
59}