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.rest.server.vars; 018 019import org.apache.juneau.commons.svl.*; 020import org.apache.juneau.http.response.*; 021import org.apache.juneau.marshall.objecttools.*; 022import org.apache.juneau.rest.server.*; 023 024/** 025 * OpenAPI 3.1 attribute variable resolver — sibling of {@link SwaggerVar} for the OpenAPI 3.1 path. 026 * 027 * <p> 028 * The format for this var is <js>"$OS{key1[,key2...]}"</js>. 029 * <br>When multiple keys are used, returns the first non-null/empty value. 030 * 031 * <h5 class='section'>Notes:</h5><ul> 032 * <li class='note'> 033 * This variable resolver requires that a {@link RestRequest} bean be available in the session bean store. 034 * <li class='note'> 035 * For security reasons, nested and recursive variables are not resolved. 036 * </ul> 037 * 038 * <h5 class='section'>See Also:</h5><ul> 039 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 040 * </ul> 041 */ 042public class OpenApiVar extends MultipartResolvingVar { 043 044 /** The name of this variable. */ 045 public static final String NAME = "OS"; 046 047 /** 048 * Constructor. 049 */ 050 public OpenApiVar() { 051 super(NAME); 052 } 053 054 @Override /* Overridden from Var */ 055 public boolean canResolve(VarResolverSession session) { 056 return session.getBean(RestRequest.class).isPresent(); 057 } 058 059 @Override /* Overridden from Var */ 060 public String resolve(VarResolverSession session, String key) { 061 RestRequest req = session.getBean(RestRequest.class).orElseThrow(InternalServerError::new); 062 return new PathTraversal(req.getOpenApi()).getString(key); 063 } 064 065 @Override /* Overridden from Var */ 066 protected boolean allowNested() { 067 return false; 068 } 069 070 @Override /* Overridden from Var */ 071 protected boolean allowRecurse() { 072 return false; 073 } 074}