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.oapi; 018 019import org.apache.juneau.commons.httppart.*; 020import org.apache.juneau.commons.reflect.*; 021import org.apache.juneau.commons.svl.*; 022import org.apache.juneau.marshall.*; 023 024/** 025 * Utility classes and methods for the {@link OpenApiConfig @OpenApiConfig} annotation. 026 * 027 * <h5 class='section'>See Also:</h5><ul> 028 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/OpenApiSupport">OpenApi</a> 029 * </ul> 030 */ 031public class OpenApiConfigAnnotation { 032 033 /** 034 * Prevents instantiation. 035 */ 036 private OpenApiConfigAnnotation() {} 037 038 /** 039 * Applies {@link OpenApiConfig} annotations to a {@link OpenApiParser.Builder}. 040 */ 041 public static class ParserApply extends AnnotationApplier<OpenApiConfig,OpenApiParser.Builder> { 042 043 /** 044 * Constructor. 045 * 046 * @param vr The resolver for resolving values in annotations. 047 * <br>Must not be <jk>null</jk>. 048 */ 049 public ParserApply(VarResolverSession vr) { 050 super(OpenApiConfig.class, OpenApiParser.Builder.class, vr); 051 } 052 053 @Override 054 public void apply(AnnotationInfo<OpenApiConfig> ai, OpenApiParser.Builder b) { 055 OpenApiConfig a = ai.inner(); 056 057 string(a.format()).map(HttpPartFormat::valueOf).ifPresent(b::format); 058 string(a.collectionFormat()).map(HttpPartCollectionFormat::valueOf).ifPresent(b::collectionFormat); 059 } 060 } 061 062 /** 063 * Applies {@link OpenApiConfig} annotations to a {@link OpenApiSerializer.Builder}. 064 */ 065 public static class SerializerApply extends AnnotationApplier<OpenApiConfig,OpenApiSerializer.Builder> { 066 067 /** 068 * Constructor. 069 * 070 * @param vr The resolver for resolving values in annotations. 071 * <br>Must not be <jk>null</jk>. 072 */ 073 public SerializerApply(VarResolverSession vr) { 074 super(OpenApiConfig.class, OpenApiSerializer.Builder.class, vr); 075 } 076 077 @Override 078 public void apply(AnnotationInfo<OpenApiConfig> ai, OpenApiSerializer.Builder b) { 079 OpenApiConfig a = ai.inner(); 080 081 string(a.format()).map(HttpPartFormat::valueOf).ifPresent(b::format); 082 string(a.collectionFormat()).map(HttpPartCollectionFormat::valueOf).ifPresent(b::collectionFormat); 083 } 084 } 085}