001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.bean.mcp.v20250618; 018 019import static org.apache.juneau.commons.utils.CollectionUtils.*; 020import static org.apache.juneau.commons.utils.Shorts.*; 021 022import java.util.*; 023 024import org.apache.juneau.commons.bean.*; 025import org.apache.juneau.marshall.*; 026 027/** 028 * JSON Schema subset used by MCP tool {@code inputSchema} objects. 029 */ 030@Marshalled 031public class JsonSchema { 032 033 private String type; 034 private Map<String,JsonSchema> properties; 035 private List<String> required; 036 private Object additionalProperties; 037 private JsonSchema items; 038 039 @BeanProp(name="$defs") 040 private Map<String,JsonSchema> defs; 041 042 /** 043 * Schema {@code type} keyword (for example {@code object}). 044 * 045 * @return The type, or {@code null} if not set. 046 */ 047 public String getType() { 048 return type; 049 } 050 051 /** 052 * Sets the schema type keyword. 053 * 054 * @param value The new value. Can be <jk>null</jk> to unset the property. 055 * @return This object (for method chaining). 056 */ 057 public JsonSchema setType(String value) { 058 type = value; 059 return this; 060 } 061 062 /** 063 * Object property schemas. 064 * 065 * @return The properties map, or {@code null} if not set. 066 */ 067 public Map<String,JsonSchema> getProperties() { 068 return u(properties); 069 } 070 071 /** 072 * Sets object property schemas. 073 * 074 * @param value The new value. Can be <jk>null</jk> to unset the property. 075 * @return This object (for method chaining). 076 */ 077 public JsonSchema setProperties(Map<String,JsonSchema> value) { 078 properties = value; 079 return this; 080 } 081 082 /** 083 * Convenience method to add a single property schema. 084 * 085 * @param name The property name. Can be <jk>null</jk> ({@link LinkedHashMap} tolerates a <jk>null</jk> key). 086 * @param value The property schema. Can be <jk>null</jk> (stored as <jk>null</jk>). 087 * @return This object (for method chaining). 088 */ 089 public JsonSchema addProperty(String name, JsonSchema value) { 090 if (properties == null) 091 properties = map(); 092 properties.put(name, value); 093 return this; 094 } 095 096 /** 097 * Required property names. 098 * 099 * @return The required list, or {@code null} if not set. 100 */ 101 public List<String> getRequired() { 102 return u(required); 103 } 104 105 /** 106 * Sets required property names. 107 * 108 * @param value The new value. Can be <jk>null</jk> to unset the property. 109 * @return This object (for method chaining). 110 */ 111 public JsonSchema setRequired(List<String> value) { 112 required = value; 113 return this; 114 } 115 116 /** 117 * Sets required property names. 118 * 119 * @param value The new value. Can be <jk>null</jk> to unset the property. 120 * @return This object (for method chaining). 121 */ 122 public JsonSchema setRequired(String...value) { 123 required = list(value); 124 return this; 125 } 126 127 /** 128 * Appends to the required property names. 129 * 130 * @param value The values to append. 131 * @return This object (for method chaining). 132 */ 133 public JsonSchema addRequired(String...value) { 134 if (required == null) 135 required = list(); 136 Collections.addAll(required, value); 137 return this; 138 } 139 140 /** 141 * Appends to the required property names. 142 * 143 * @param value The values to append. 144 * @return This object (for method chaining). 145 */ 146 public JsonSchema addRequired(Collection<String> value) { 147 if (required == null) 148 required = list(); 149 required.addAll(value); 150 return this; 151 } 152 153 /** 154 * {@code additionalProperties} keyword (boolean or nested schema). 155 * 156 * @return The value, or {@code null} if not set. 157 */ 158 public Object getAdditionalProperties() { 159 return additionalProperties; 160 } 161 162 /** 163 * Sets {@code additionalProperties}. 164 * 165 * @param value The new value. Can be <jk>null</jk> to unset the property. 166 * @return This object (for method chaining). 167 */ 168 public JsonSchema setAdditionalProperties(Object value) { 169 additionalProperties = value; 170 return this; 171 } 172 173 /** 174 * Array {@code items} schema. 175 * 176 * @return The items schema, or {@code null} if not set. 177 */ 178 public JsonSchema getItems() { 179 return items; 180 } 181 182 /** 183 * Sets array items schema. 184 * 185 * @param value The new value. Can be <jk>null</jk> to unset the property. 186 * @return This object (for method chaining). 187 */ 188 public JsonSchema setItems(JsonSchema value) { 189 items = value; 190 return this; 191 } 192 193 /** 194 * {@code $defs} map for reusable sub-schemas. 195 * 196 * @return The defs map, or {@code null} if not set. 197 */ 198 public Map<String,JsonSchema> getDefs() { 199 return u(defs); 200 } 201 202 /** 203 * Sets {@code $defs}. 204 * 205 * @param value The new value. Can be <jk>null</jk> to unset the property. 206 * @return This object (for method chaining). 207 */ 208 public JsonSchema setDefs(Map<String,JsonSchema> value) { 209 defs = value; 210 return this; 211 } 212 213 /** 214 * Convenience method to add a single reusable sub-schema. 215 * 216 * @param name The sub-schema name. Can be <jk>null</jk> ({@link LinkedHashMap} tolerates a <jk>null</jk> key). 217 * @param value The sub-schema. Can be <jk>null</jk> (stored as <jk>null</jk>). 218 * @return This object (for method chaining). 219 */ 220 public JsonSchema addDef(String name, JsonSchema value) { 221 if (defs == null) 222 defs = map(); 223 defs.put(name, value); 224 return this; 225 } 226}