001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.oapi.annotation;
014
015import org.apache.juneau.*;
016import org.apache.juneau.httppart.*;
017import org.apache.juneau.oapi.*;
018import org.apache.juneau.reflect.*;
019import org.apache.juneau.svl.*;
020
021/**
022 * Utility classes and methods for the {@link OpenApiConfig @OpenApiConfig} annotation.
023 *
024 * <h5 class='section'>See Also:</h5><ul>
025 *    <li class='link'><a class="doclink" href="../../../../../index.html#jm.OpenApiDetails">OpenAPI Details</a>
026 * </ul>
027 */
028public class OpenApiConfigAnnotation {
029
030   /**
031    * Applies {@link OpenApiConfig} annotations to a {@link org.apache.juneau.oapi.OpenApiSerializer.Builder}.
032    */
033   public static class SerializerApply extends AnnotationApplier<OpenApiConfig,OpenApiSerializer.Builder> {
034
035      /**
036       * Constructor.
037       *
038       * @param vr The resolver for resolving values in annotations.
039       */
040      public SerializerApply(VarResolverSession vr) {
041         super(OpenApiConfig.class, OpenApiSerializer.Builder.class, vr);
042      }
043
044      @Override
045      public void apply(AnnotationInfo<OpenApiConfig> ai, OpenApiSerializer.Builder b) {
046         OpenApiConfig a = ai.inner();
047
048         string(a.format()).map(HttpPartFormat::valueOf).ifPresent(x -> b.format(x));
049         string(a.collectionFormat()).map(HttpPartCollectionFormat::valueOf).ifPresent(x -> b.collectionFormat(x));
050      }
051   }
052
053   /**
054    * Applies {@link OpenApiConfig} annotations to a {@link org.apache.juneau.oapi.OpenApiParser.Builder}.
055    */
056   public static class ParserApply extends AnnotationApplier<OpenApiConfig,OpenApiParser.Builder> {
057
058      /**
059       * Constructor.
060       *
061       * @param vr The resolver for resolving values in annotations.
062       */
063      public ParserApply(VarResolverSession vr) {
064         super(OpenApiConfig.class, OpenApiParser.Builder.class, vr);
065      }
066
067      @Override
068      public void apply(AnnotationInfo<OpenApiConfig> ai, OpenApiParser.Builder b) {
069         OpenApiConfig a = ai.inner();
070
071         string(a.format()).map(HttpPartFormat::valueOf).ifPresent(x -> b.format(x));
072         string(a.collectionFormat()).map(HttpPartCollectionFormat::valueOf).ifPresent(x -> b.collectionFormat(x));
073      }
074   }
075}