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