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" }, // }, // } Copy
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" }, // }, // }
The JSON schema to modify.
The name of the definition to move to the top.
A new JSON schema object with the specified definition moved to the top.
Moves a specific definition to the top of the JSON schema object.
Example: