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