@@ -108,22 +108,6 @@ public static JsonSchema setIdNull(JsonSchema schema) {
108108 return schema ;
109109 }
110110
111- /**
112- * Generates a JSON schema for the given class, with the option to specify required fields.
113- * This method uses the Jackson library to generate the schema and customize it based on the provided required fields.
114- * It sets the ID of the schema and its nested schemas to null and adds the required fields to the schema's "required" property.
115- *
116- * @param clazz The class for which the JSON schema should be generated.
117- * @param requiredFields A varargs array of field names that should be marked as "required" in the schema.
118- * @return A JsonNode representing the generated schema, or null if an exception occurs during generation.
119- */
120- public static JsonNode getJsonNodeFor (Class <?> clazz , String ... requiredFields ) {
121- JsonSchema schema = generateSchema (clazz );
122- assert schema != null ;
123- schema .setId (null );
124- return addRequiredFields (schema , requiredFields );
125- }
126-
127111 /**
128112 * Generates a JSON schema for the given class, with the option to specify required fields.
129113 * This method uses the Jackson library to generate the schema.
@@ -156,32 +140,6 @@ public static JsonSchema generateSchema(Class<?> clazz) {
156140 return null ;
157141 }
158142 }
159-
160- /**
161- * Adds the specified required fields to the "required" property of a JSON schema.
162- * This method adds each field name from the provided array to the "required" property of the schema.
163- *
164- * @param schema The JSON schema to modify.
165- * @param requiredFields An array of field names that should be marked as required in the schema.
166- * @return
167- */
168- private static JsonNode addRequiredFields (JsonSchema schema , String [] requiredFields ) {
169- JsonNode schemaNode = mapper .valueToTree (schema );
170-
171- if (!(schemaNode instanceof ObjectNode root )) {
172- throw new IllegalArgumentException ("Schema must be an ObjectNode" );
173- }
174-
175- ArrayNode required = root .withArray ("required" );
176-
177- for (String fieldName : requiredFields ) {
178- required .add (fieldName );
179- }
180-
181- // Convert the modified JsonNode back to JsonSchema
182- return mapper .valueToTree (root );
183- }
184-
185143 }
186144 }
187145}
0 commit comments