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.jsonschema; 018 019import static org.apache.juneau.common.utils.ThrowableUtils.*; 020 021import org.apache.juneau.*; 022import org.apache.juneau.annotation.*; 023import org.apache.juneau.collections.*; 024import org.apache.juneau.parser.*; 025 026/** 027 * Metadata on bean properties specific to the JSON-Schema pulled from the {@link Schema @Schema} annotation 028 * on the bean property. 029 * 030 * <h5 class='section'>See Also:</h5><ul> 031 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JsonSchemaDetails">JSON-Schema Support</a> 032 033 * </ul> 034 */ 035public class JsonSchemaBeanPropertyMeta extends ExtendedBeanPropertyMeta { 036 037 /** 038 * Default instance. 039 */ 040 public static final JsonSchemaBeanPropertyMeta DEFAULT = new JsonSchemaBeanPropertyMeta(); 041 042 private final JsonMap schema; 043 044 /** 045 * Constructor. 046 * 047 * @param bpm The metadata of the bean property of this additional metadata. 048 * @param mp JSON-schema metadata provider (for finding information about other artifacts). 049 */ 050 public JsonSchemaBeanPropertyMeta(BeanPropertyMeta bpm, JsonSchemaMetaProvider mp) { 051 super(bpm); 052 053 this.schema = new JsonMap(); 054 055 try { 056 bpm.forEachAnnotation(Schema.class, x -> true, x -> schema.append(SchemaAnnotation.asMap(x))); 057 } catch (ParseException e) { 058 throw asRuntimeException(e); 059 } 060 } 061 062 private JsonSchemaBeanPropertyMeta() { 063 super(null); 064 this.schema = JsonMap.EMPTY_MAP; 065 } 066 067 /** 068 * Returns the schema information gathered from all the {@link Schema @Schema} annotations on the bean property. 069 * 070 * @return The schema information as a generic map. Never <jk>null</jk>. 071 */ 072 protected JsonMap getSchema() { 073 return schema; 074 } 075}