You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2018/09/15 15:29:28 UTC
[juneau] branch master updated: Add $SS variable
This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new f414f89 Add $SS variable
f414f89 is described below
commit f414f89debba9d51354bbbc418088c1c8af1c9be
Author: JamesBognar <ja...@apache.org>
AuthorDate: Sat Sep 15 11:29:14 2018 -0400
Add $SS variable
---
.../Topics/05.juneau-svl/02.SvlVariables.html | 4 ++
.../apache/juneau/rest/BasicRestInfoProvider.java | 6 --
.../java/org/apache/juneau/rest/RestContext.java | 1 +
.../org/apache/juneau/rest/vars/SwaggerVar.java | 80 ++++++++++++++++++++++
4 files changed, 85 insertions(+), 6 deletions(-)
diff --git a/juneau-doc/src/main/resources/Topics/05.juneau-svl/02.SvlVariables.html b/juneau-doc/src/main/resources/Topics/05.juneau-svl/02.SvlVariables.html
index 45b1ca4..0e18f06 100644
--- a/juneau-doc/src/main/resources/Topics/05.juneau-svl/02.SvlVariables.html
+++ b/juneau-doc/src/main/resources/Topics/05.juneau-svl/02.SvlVariables.html
@@ -168,6 +168,10 @@ SVL Variables
<td class='code'>$SA{contentType,key[,default]}</td>
</tr>
<tr class='dark'>
+ <td>{@link oajr.vars.SwaggerVar}</td>
+ <td class='code'>$SS{key1[,key2...]}</td>
+ </tr>
+ <tr class='dark'>
<td>{@link oajr.vars.UrlVar}</td>
<td class='code'>$U{uri}></td>
</tr>
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
index 029b731..08f7083 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
@@ -331,9 +331,6 @@ public class BasicRestInfoProvider implements RestInfoProvider {
String title = context.getMessages().findFirstString(req.getLocale(), "title");
if (title != null)
return vr.resolve(title);
- Swagger s = getSwagger(req);
- if (s != null && s.getInfo() != null && s.getInfo().hasTitle())
- return s.getInfo().getTitle();
return null;
}
@@ -387,9 +384,6 @@ public class BasicRestInfoProvider implements RestInfoProvider {
String description = context.getMessages().findFirstString(req.getLocale(), "description");
if (description != null)
return vr.resolve(description);
- Swagger s = getSwagger(req);
- if (s != null && s.getInfo() != null && s.getInfo().hasDescription())
- return s.getInfo().getDescription();
return null;
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 4d49b96..c3d0782 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -3136,6 +3136,7 @@ public final class RestContext extends BeanContext {
RestInfoVar.class,
SerializedRequestAttrVar.class,
ServletInitParamVar.class,
+ SwaggerVar.class,
UrlVar.class,
UrlEncodeVar.class,
WidgetVar.class
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/SwaggerVar.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/SwaggerVar.java
new file mode 100644
index 0000000..0fb9dba
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/SwaggerVar.java
@@ -0,0 +1,80 @@
+// ***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
+// * with the License. You may obtain a copy of the License at *
+// * *
+// * http://www.apache.org/licenses/LICENSE-2.0 *
+// * *
+// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
+// * specific language governing permissions and limitations under the License. *
+// ***************************************************************************************************************************
+package org.apache.juneau.rest.vars;
+
+import org.apache.juneau.rest.*;
+import org.apache.juneau.svl.*;
+
+/**
+ * Swagger attribute variable resolver.
+ *
+ * <p>
+ * The format for this var is <js>"$SS{key1[,key2...]}"</js>.
+ * <br>When multiple keys are used, returns the first non-null/empty value.
+ *
+ * <p>
+ * Example values:
+ * <ul>
+ * <li><js>"info/title"</js>
+ * <li><js>"info/description"</js>
+ * <li><js>"info/contact/name"</js>
+ * </ul>
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * This variable resolver requires that a {@link RestRequest} object be set as a context object on the resolver
+ * or a session object on the resolver session.
+ * <li>
+ * For security reasons, nested and recursive variables are not resolved.
+ * </ul>
+ *
+ * <h5 class='section'>See Also:</h5>
+ * <ul>
+ * <li class='link'>{@doc juneau-rest-server.SvlVariables}
+ * </ul>
+ */
+public class SwaggerVar extends MultipartResolvingVar {
+
+ /**
+ * The name of the session or context object that identifies the {@link RestRequest} object.
+ */
+ public static final String SESSION_req = "req";
+
+
+ /** The name of this variable. */
+ public static final String NAME = "SS";
+
+ /**
+ * Constructor.
+ */
+ public SwaggerVar() {
+ super(NAME);
+ }
+
+ @Override /* Var */
+ protected boolean allowNested() {
+ return false;
+ }
+
+ @Override /* Var */
+ protected boolean allowRecurse() {
+ return false;
+ }
+
+ @Override /* Parameter */
+ public String resolve(VarResolverSession session, String key) {
+ RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req, true);
+ return req.getProperties().getString(key);
+ }
+}
\ No newline at end of file