"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getJsonSchema = void 0;
const configuration_js_1 = require("./configuration.js");
const simpleSchemaToJsonSchema_js_1 = require("./simpleSchemaToJsonSchema.js");
/**
 * Creates a {@link https://json-schema.org/ | JSON Schema} representation of the provided {@link TreeNodeSchema}.
 *
 * @remarks
 * Useful when communicating the schema to external libraries or services.
 * Caches the result for future calls.
 *
 * @example
 *
 * A Shared Tree schema like the following:
 *
 * ```typescript
 * class MyObject extends schemaFactory.object("MyObject", {
 * 	foo: schemaFactory.number,
 * 	bar: schemaFactory.optional(schemaFactory.string),
 * });
 * ```
 *
 * Will yield JSON Schema like the following:
 *
 * ```json
 * {
 * 	"$defs": {
 * 		"com.fluidframework.leaf.string": {
 * 			"type": "string",
 * 		},
 * 		"com.fluidframework.leaf.number": {
 * 			"type": "number",
 * 		},
 * 		"com.myapp.MyObject": {
 * 			"type": "object",
 * 			"properties": {
 * 				"foo": { "$ref": "com.fluidframework.leaf.number" },
 * 				"bar": { "$ref": "com.fluidframework.leaf.string" },
 * 			},
 * 			"required": ["foo"],
 * 		},
 * 	},
 * 	"$ref": "#/$defs/com.myapp.MyObject",
 * }
 * ```
 *
 * @privateRemarks In the future, we may wish to move this to a more discoverable API location.
 * For now, while still an experimental API, it is surfaced as a free function.
 *
 * TODO:
 * This API should allow generating JSON schema for the whole matrix of combinations:
 *
 * 1. VerboseTree and (Done) ConciseTree
 * 2. (Done) With and without requiring values with defaults (for insertion vs reading)
 * 3. (Done) Using stored keys and property keys.
 * 4. Control over unknown optional fields and staged allowed types (able to manually control them and/or get them from some context).
 *
 * This takes in `ImplicitAllowedTypes` since underlying `toJsonSchema` can't handle optional roots.
 *
 * @alpha
 */
function getJsonSchema(schema, options) {
    const treeSchema = new configuration_js_1.TreeViewConfigurationAlpha({ schema });
    return (0, simpleSchemaToJsonSchema_js_1.toJsonSchema)(treeSchema, options);
}
exports.getJsonSchema = getJsonSchema;
//# sourceMappingURL=getJsonSchema.js.map