Moves a specific definition to the top of the JSON schema object.

Example:

const schema = {
definitions: {
name: { type: "string" },
age: { type: "number" },
},
type: "object",
properties: {
name: { $ref: "#/definitions/name" },
age: { $ref: "#/definitions/age" },
},
required: ["name", "age"],
};
const newSchema = bringDefinitionToTop(schema, "age");
console.log(newSchema);
// {
// type: "object",
// properties: {
// name: { $ref: "#/definitions/name" },
// age: { $ref: "#/definitions/age" },
// },
// required: ["name", "age"],
// definitions: {
// age: { type: "number" },
// name: { type: "string" },
// },
// }
  • Parameters

    • schema: JSONSchema7

      The JSON schema to modify.

    • name: string

      The name of the definition to move to the top.

    Returns JSONSchema7

    A new JSON schema object with the specified definition moved to the top.