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 java.util.function.*; 022 023import org.apache.juneau.*; 024import org.apache.juneau.annotation.*; 025import org.apache.juneau.collections.*; 026import org.apache.juneau.parser.*; 027 028/** 029 * Metadata on classes specific to the JSON-Schema serializer and pulled from the {@link Schema @Schema} annotation on 030 * the class. 031 * 032 * <h5 class='section'>See Also:</h5><ul> 033 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JsonSchemaDetails">JSON-Schema Support</a> 034 035 * </ul> 036 */ 037public class JsonSchemaClassMeta extends ExtendedClassMeta { 038 039 private final JsonMap schema = new JsonMap(); 040 041 /** 042 * Constructor. 043 * 044 * @param cm The class that this annotation is defined on. 045 * @param mp JSON-schema metadata provider (for finding information about other artifacts). 046 */ 047 public JsonSchemaClassMeta(ClassMeta<?> cm, JsonSchemaMetaProvider mp) { 048 super(cm); 049 Consumer<Schema> c = x -> { 050 try { 051 schema.append(SchemaAnnotation.asMap(x)); 052 } catch (ParseException e) { 053 throw asRuntimeException(e); 054 } 055 }; 056 cm.forEachAnnotation(Schema.class, x -> true, c); 057 } 058 059 /** 060 * Returns the {@link Schema @Schema} annotation defined on the class. 061 * 062 * @return The value of the annotation, or <jk>null</jk> if not specified. 063 */ 064 protected JsonMap getSchema() { 065 return schema; 066 } 067}