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 c8703dbda6 SonarQube bug fixes and fix for intermittent failure in
Common_UonTest
c8703dbda6 is described below
commit c8703dbda65824a78922c0e53803b537976dff32
Author: James Bognar <[email protected]>
AuthorDate: Wed Feb 4 10:18:39 2026 -0500
SonarQube bug fixes and fix for intermittent failure in Common_UonTest
---
.../juneau/commons/utils/ThrowableUtils.java | 15 +-
.../juneau/serializer/SerializerSession.java | 5 +
.../rest/swagger/BasicSwaggerProviderSession.java | 522 ++++++++++++---------
3 files changed, 315 insertions(+), 227 deletions(-)
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ThrowableUtils.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ThrowableUtils.java
index 693dc61da2..9130fa9058 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ThrowableUtils.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ThrowableUtils.java
@@ -419,11 +419,22 @@ public class ThrowableUtils {
/**
* Convenience method for calling {@link
Throwable#getLocalizedMessage()}.
*
+ * <p>
+ * Long messages (>2000 characters) are truncated to prevent stack
overflow issues
+ * when exception messages contain circular references. The format is:
+ * "first-1000-chars<truncated-#-chars>last-1000-chars"
+ *
* @param t The throwable.
- * @return The localized message of the throwable.
+ * @return The localized message of the throwable, truncated if
necessary.
*/
public static String lm(Throwable t) {
- return t.getLocalizedMessage();
+ String msg = t.getLocalizedMessage();
+ if (msg == null)
+ return null;
+ if (msg.length() <= 2000)
+ return msg;
+ int truncated = msg.length() - 2000;
+ return msg.substring(0, 1000) + "<truncated-" + truncated +
"-chars>" + msg.substring(msg.length() - 1000);
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
index d465d16827..fd0a90dddf 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
@@ -950,6 +950,11 @@ public class SerializerSession extends BeanTraverseSession
{
* @throws SerializeException Thrown if
ignoreInvocationExceptionOnGetters is false.
*/
protected final void onBeanGetterException(BeanPropertyMeta p,
Throwable t) throws SerializeException {
+ // If it's a StackOverflowError, let it propagate so it can be
caught by serialize() method
+ // and converted to a proper SerializeException with recursion
detection message
+ if (t instanceof StackOverflowError t2)
+ throw t2;
+
if (nn(listener))
listener.onBeanGetterException(this, t, p);
String prefix = (isDebug() ? getStack(false) + ": " : "");
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
index 9de727a8d7..aa128532ad 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
@@ -59,9 +59,81 @@ import jakarta.servlet.*;
* <li class='link'><a class="doclink"
href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a>
* </ul>
*/
-@SuppressWarnings({"resource","java:S1168"})
+@SuppressWarnings({"resource","java:S1168","java:S115"})
public class BasicSwaggerProviderSession {
+ // Swagger JSON property name constants
+ private static final String SWAGGER_additionalProperties =
"additionalProperties";
+ private static final String SWAGGER_allOf = "allOf";
+ private static final String SWAGGER_body = "body";
+ private static final String SWAGGER_collectionFormat =
"collectionFormat";
+ private static final String SWAGGER_consumes = "consumes";
+ private static final String SWAGGER_contact = "contact";
+ private static final String SWAGGER_default = "default";
+ private static final String SWAGGER_definitions = "definitions";
+ private static final String SWAGGER_deprecated = "deprecated";
+ private static final String SWAGGER_description = "description";
+ private static final String SWAGGER_discriminator = "discriminator";
+ private static final String SWAGGER_email = "email";
+ private static final String SWAGGER_enum = "enum";
+ private static final String SWAGGER_example = "example";
+ private static final String SWAGGER_examples = "examples";
+ private static final String SWAGGER_exclusiveMaximum =
"exclusiveMaximum";
+ private static final String SWAGGER_exclusiveMinimum =
"exclusiveMinimum";
+ private static final String SWAGGER_externalDocs = "externalDocs";
+ private static final String SWAGGER_format = "format";
+ private static final String SWAGGER_headers = "headers";
+ private static final String SWAGGER_ignore = "ignore";
+ private static final String SWAGGER_in = "in";
+ private static final String SWAGGER_info = "info";
+ private static final String SWAGGER_items = "items";
+ private static final String SWAGGER_license = "license";
+ private static final String SWAGGER_maxItems = "maxItems";
+ private static final String SWAGGER_maxLength = "maxLength";
+ private static final String SWAGGER_maxProperties = "maxProperties";
+ private static final String SWAGGER_maximum = "maximum";
+ private static final String SWAGGER_minItems = "minItems";
+ private static final String SWAGGER_minLength = "minLength";
+ private static final String SWAGGER_minProperties = "minProperties";
+ private static final String SWAGGER_minimum = "minimum";
+ private static final String SWAGGER_multipleOf = "multipleOf";
+ private static final String SWAGGER_name = "name";
+ private static final String SWAGGER_object = "object";
+ private static final String SWAGGER_operationId = "operationId";
+ private static final String SWAGGER_parameters = "parameters";
+ private static final String SWAGGER_paths = "paths";
+ private static final String SWAGGER_pattern = "pattern";
+ private static final String SWAGGER_produces = "produces";
+ private static final String SWAGGER_properties = "properties";
+ private static final String SWAGGER_readOnly = "readOnly";
+ private static final String SWAGGER_required = "required";
+ private static final String SWAGGER_responses = "responses";
+ private static final String SWAGGER_schema = "schema";
+ private static final String SWAGGER_schemes = "schemes";
+ private static final String SWAGGER_summary = "summary";
+ private static final String SWAGGER_tags = "tags";
+ private static final String SWAGGER_termsOfService = "termsOfService";
+ private static final String SWAGGER_title = "title";
+ private static final String SWAGGER_true = "true";
+ private static final String SWAGGER_type = "type";
+ private static final String SWAGGER_uniqueItems = "uniqueItems";
+ private static final String SWAGGER_url = "url";
+ private static final String SWAGGER_version = "version";
+ private static final String SWAGGER_xml = "xml";
+ private static final String SWAGGER_$ref = "$ref";
+
+ // JSON-Schema extension property name constants (x-prefixed)
+ private static final String JSONSCHEMA_x_discriminator =
"x-discriminator";
+ private static final String JSONSCHEMA_x_example = "x-example";
+ private static final String JSONSCHEMA_x_externalDocs =
"x-externalDocs";
+ private static final String JSONSCHEMA_x_readOnly = "x-readOnly";
+ private static final String JSONSCHEMA_x_xml = "x-xml";
+
+ // Other constant values
+ private static final String CONST_200 = "200";
+ private static final String CONST_IGNORE = "IGNORE";
+ private static final String CONST_value = "_value";
+
private static Set<Integer> getCodes(List<StatusCode> la, Integer def) {
var codes = new TreeSet<Integer>();
for (var a : la) {
@@ -158,18 +230,18 @@ public class BasicSwaggerProviderSession {
for (var rr : restAnnotations) {
- var sInfo = omSwagger.getMap("info", true);
+ var sInfo = omSwagger.getMap(SWAGGER_info, true);
sInfo
- .appendIf(ne, "title",
+ .appendIf(ne, SWAGGER_title,
firstNonEmpty(
- sInfo.getString("title"),
+ sInfo.getString(SWAGGER_title),
resolve(rr.title())
)
)
- .appendIf(ne, "description",
+ .appendIf(ne, SWAGGER_description,
firstNonEmpty(
- sInfo.getString("description"),
+
sInfo.getString(SWAGGER_description),
resolve(rr.description())
)
);
@@ -179,59 +251,59 @@ public class BasicSwaggerProviderSession {
omSwagger.append(parseMap(r.value(), "@Swagger(value)
on class {0}", c));
if (! SwaggerAnnotation.empty(r)) {
- var info = omSwagger.getMap("info", true);
+ var info = omSwagger.getMap(SWAGGER_info, true);
info
- .appendIf(ne, "title",
resolve(r.title()))
- .appendIf(ne, "description",
resolve(r.description()))
- .appendIf(ne, "version",
resolve(r.version()))
- .appendIf(ne, "termsOfService",
resolve(r.termsOfService()))
- .appendIf(nem, "contact",
+ .appendIf(ne, SWAGGER_title,
resolve(r.title()))
+ .appendIf(ne, SWAGGER_description,
resolve(r.description()))
+ .appendIf(ne, SWAGGER_version,
resolve(r.version()))
+ .appendIf(ne, SWAGGER_termsOfService,
resolve(r.termsOfService()))
+ .appendIf(nem, SWAGGER_contact,
merge(
- info.getMap("contact"),
+
info.getMap(SWAGGER_contact),
toMap(r.contact(),
"@Swagger(contact) on class {0}", c)
)
)
- .appendIf(nem, "license",
+ .appendIf(nem, SWAGGER_license,
merge(
- info.getMap("license"),
+
info.getMap(SWAGGER_license),
toMap(r.license(),
"@Swagger(license) on class {0}", c)
)
);
}
omSwagger
- .appendIf(nem, "externalDocs",
+ .appendIf(nem, SWAGGER_externalDocs,
merge(
-
omSwagger.getMap("externalDocs"),
+
omSwagger.getMap(SWAGGER_externalDocs),
toMap(r.externalDocs(),
"@Swagger(externalDocs) on class {0}", c)
)
)
- .appendIf(nec, "tags",
+ .appendIf(nec, SWAGGER_tags,
merge(
- omSwagger.getList("tags"),
+ omSwagger.getList(SWAGGER_tags),
toList(r.tags(),
"@Swagger(tags) on class {0}", c)
)
);
}
- omSwagger.appendIf(nem, "externalDocs",
parseMap(mb.findFirstString("externalDocs"), "Messages/externalDocs on class
{0}", c));
+ omSwagger.appendIf(nem, SWAGGER_externalDocs,
parseMap(mb.findFirstString("externalDocs"), "Messages/externalDocs on class
{0}", c));
- var info = omSwagger.getMap("info", true);
+ var info = omSwagger.getMap(SWAGGER_info, true);
info
- .appendIf(ne, "title",
resolve(mb.findFirstString("title")))
- .appendIf(ne, "description",
resolve(mb.findFirstString("description")))
- .appendIf(ne, "version",
resolve(mb.findFirstString("version")))
- .appendIf(ne, "termsOfService",
resolve(mb.findFirstString("termsOfService")))
- .appendIf(nem, "contact",
parseMap(mb.findFirstString("contact"), "Messages/contact on class {0}", c))
- .appendIf(nem, "license",
parseMap(mb.findFirstString("license"), "Messages/license on class {0}", c));
+ .appendIf(ne, SWAGGER_title,
resolve(mb.findFirstString("title")))
+ .appendIf(ne, SWAGGER_description,
resolve(mb.findFirstString("description")))
+ .appendIf(ne, SWAGGER_version,
resolve(mb.findFirstString("version")))
+ .appendIf(ne, SWAGGER_termsOfService,
resolve(mb.findFirstString("termsOfService")))
+ .appendIf(nem, SWAGGER_contact,
parseMap(mb.findFirstString("contact"), "Messages/contact on class {0}", c))
+ .appendIf(nem, SWAGGER_license,
parseMap(mb.findFirstString("license"), "Messages/license on class {0}", c));
if (info.isEmpty())
- omSwagger.remove("info");
+ omSwagger.remove(SWAGGER_info);
- var produces = omSwagger.getList("produces", true);
- var consumes = omSwagger.getList("consumes", true);
+ var produces = omSwagger.getList(SWAGGER_produces, true);
+ var consumes = omSwagger.getList(SWAGGER_consumes, true);
if (consumes.isEmpty())
consumes.addAll(context.getConsumes());
@@ -239,9 +311,9 @@ public class BasicSwaggerProviderSession {
produces.addAll(context.getProduces());
Map<String,JsonMap> tagMap = map();
- if (omSwagger.containsKey("tags")) {
- for (var om :
omSwagger.getList("tags").elements(JsonMap.class)) {
- String name = om.getString("name");
+ if (omSwagger.containsKey(SWAGGER_tags)) {
+ for (var om :
omSwagger.getList(SWAGGER_tags).elements(JsonMap.class)) {
+ String name = om.getString(SWAGGER_name);
if (name == null)
throw new SwaggerException(null, "Tag
definition found without name in swagger JSON.");
tagMap.put(name, om);
@@ -251,7 +323,7 @@ public class BasicSwaggerProviderSession {
var s = mb.findFirstString("tags");
if (nn(s)) {
for (var m : parseListOrCdl(s, "Messages/tags on class
{0}", c).elements(JsonMap.class)) {
- var name = m.getString("name");
+ var name = m.getString(SWAGGER_name);
if (name == null)
throw new SwaggerException(null, "Tag
definition found without name in resource bundle on class {0}", c);
if (tagMap.containsKey(name))
@@ -262,7 +334,7 @@ public class BasicSwaggerProviderSession {
}
// Load our existing bean definitions into our session.
- var definitions = omSwagger.getMap("definitions", true);
+ var definitions = omSwagger.getMap(SWAGGER_definitions, true);
for (var defId : definitions.keySet())
js.addBeanDef(defId, new
JsonMap(definitions.getMap(defId)));
@@ -285,94 +357,94 @@ public class BasicSwaggerProviderSession {
var ms = _ms.orElseGet(() ->
OpSwaggerAnnotation.create().build());
op.append(parseMap(ms.value(), "@OpSwagger(value) on
class {0} method {1}", c, m));
- op.appendIf(ne, "operationId",
+ op.appendIf(ne, SWAGGER_operationId,
firstNonEmpty(
resolve(ms.operationId()),
- op.getString("operationId"),
+ op.getString(SWAGGER_operationId),
mn
)
);
var _summary = Value.<String>empty();
al.forEach(ai -> ai.getValue(String.class,
"summary").filter(NOT_EMPTY).ifPresent(_summary::set));
- op.appendIf(ne, "summary",
+ op.appendIf(ne, SWAGGER_summary,
firstNonEmpty(
resolve(ms.summary()),
resolve(mb.findFirstString(mn +
".summary")),
- op.getString("summary"),
+ op.getString(SWAGGER_summary),
resolve(_summary.orElse(null))
)
);
var _description = Value.<String[]>empty();
al.forEach(ai -> ai.getValue(String[].class,
"description").filter(x -> x.length > 0).ifPresent(_description::set));
- op.appendIf(ne, "description",
+ op.appendIf(ne, SWAGGER_description,
firstNonEmpty(
resolve(ms.description()),
resolve(mb.findFirstString(mn +
".description")),
- op.getString("description"),
+ op.getString(SWAGGER_description),
resolve(_description.orElse(new
String[0]))
)
);
- op.appendIf(ne, "deprecated",
+ op.appendIf(ne, SWAGGER_deprecated,
firstNonEmpty(
resolve(ms.deprecated()),
- (nn(m.getAnnotation(Deprecated.class))
||
nn(ClassInfo.of(m.getDeclaringClass()).getAnnotations(Deprecated.class).findFirst().map(AnnotationInfo::inner).orElse(null)))
? "true" : null
+ (nn(m.getAnnotation(Deprecated.class))
||
nn(ClassInfo.of(m.getDeclaringClass()).getAnnotations(Deprecated.class).findFirst().map(AnnotationInfo::inner).orElse(null)))
? SWAGGER_true : null
)
);
- op.appendIf(nec, "tags",
+ op.appendIf(nec, SWAGGER_tags,
merge(
parseListOrCdl(mb.findFirstString(mn +
".tags"), "Messages/tags on class {0} method {1}", c, m),
parseListOrCdl(ms.tags(),
"@OpSwagger(tags) on class {0} method {1}", c, m)
)
);
- op.appendIf(nec, "schemes",
+ op.appendIf(nec, SWAGGER_schemes,
merge(
parseListOrCdl(mb.findFirstString(mn +
".schemes"), "Messages/schemes on class {0} method {1}", c, m),
parseListOrCdl(ms.schemes(),
"@OpSwagger(schemes) on class {0} method {1}", c, m)
)
);
- op.appendIf(nec, "consumes",
+ op.appendIf(nec, SWAGGER_consumes,
firstNonEmpty(
parseListOrCdl(mb.findFirstString(mn +
".consumes"), "Messages/consumes on class {0} method {1}", c, m),
parseListOrCdl(ms.consumes(),
"@OpSwagger(consumes) on class {0} method {1}", c, m)
)
);
- op.appendIf(nec, "produces",
+ op.appendIf(nec, SWAGGER_produces,
firstNonEmpty(
parseListOrCdl(mb.findFirstString(mn +
".produces"), "Messages/produces on class {0} method {1}", c, m),
parseListOrCdl(ms.produces(),
"@OpSwagger(produces) on class {0} method {1}", c, m)
)
);
- op.appendIf(nec, "parameters",
+ op.appendIf(nec, SWAGGER_parameters,
merge(
parseList(mb.findFirstString(mn +
".parameters"), "Messages/parameters on class {0} method {1}", c, m),
parseList(ms.parameters(),
"@OpSwagger(parameters) on class {0} method {1}", c, m)
)
);
- op.appendIf(nem, "responses",
+ op.appendIf(nem, SWAGGER_responses,
merge(
parseMap(mb.findFirstString(mn +
".responses"), "Messages/responses on class {0} method {1}", c, m),
parseMap(ms.responses(),
"@OpSwagger(responses) on class {0} method {1}", c, m)
)
);
- op.appendIf(nem, "externalDocs",
+ op.appendIf(nem, SWAGGER_externalDocs,
merge(
- op.getMap("externalDocs"),
+ op.getMap(SWAGGER_externalDocs),
parseMap(mb.findFirstString(mn +
".externalDocs"), "Messages/externalDocs on class {0} method {1}", c, m),
toMap(ms.externalDocs(),
"@OpSwagger(externalDocs) on class {0} method {1}", c, m)
)
);
- if (op.containsKey("tags"))
- for (var tag :
op.getList("tags").elements(String.class))
+ if (op.containsKey(SWAGGER_tags))
+ for (var tag :
op.getList(SWAGGER_tags).elements(String.class))
if (! tagMap.containsKey(tag))
- tagMap.put(tag,
JsonMap.of("name", tag));
+ tagMap.put(tag,
JsonMap.of(SWAGGER_name, tag));
var paramMap = new JsonMap();
- if (op.containsKey("parameters"))
- for (var param :
op.getList("parameters").elements(JsonMap.class))
- paramMap.put(param.getString("in") +
'.' + ("body".equals(param.getString("in")) ? "body" :
param.getString("name")), param);
+ if (op.containsKey(SWAGGER_parameters))
+ for (var param :
op.getList(SWAGGER_parameters).elements(JsonMap.class))
+
paramMap.put(param.getString(SWAGGER_in) + '.' +
(SWAGGER_body.equals(param.getString(SWAGGER_in)) ? SWAGGER_body :
param.getString(SWAGGER_name)), param);
// Finally, look for parameters defined on method.
for (var mpi : mi.getParameters()) {
@@ -381,54 +453,54 @@ public class BasicSwaggerProviderSession {
var type = pt.innerType();
if (ap.has(Content.class, mpi)) {
- var param = paramMap.getMap(BODY +
".body", true).append("in", BODY);
- var schema =
getSchema(param.getMap("schema"), type, bs);
+ var param = paramMap.getMap(BODY +
".body", true).append(SWAGGER_in, BODY);
+ var schema =
getSchema(param.getMap(SWAGGER_schema), type, bs);
rstream(ap.find(Schema.class,
mpi)).forEach(x -> merge(schema, x.inner()));
rstream(ap.find(Content.class,
mpi)).forEach(x -> merge(schema, x.inner().schema()));
pushupSchemaFields(BODY, param, schema);
- param.appendIf(nem, "schema", schema);
- param.putIfAbsent("required", true);
+ param.appendIf(nem, SWAGGER_schema,
schema);
+ param.putIfAbsent(SWAGGER_required,
SWAGGER_true);
addBodyExamples(sm, param, false, type,
locale);
} else if (ap.has(Query.class, mpi)) {
var name =
QueryAnnotation.findName(mpi).orElse(null);
- var param = paramMap.getMap(QUERY + "."
+ name, true).append("name", name).append("in", QUERY);
+ var param = paramMap.getMap(QUERY + "."
+ name, true).append(SWAGGER_name, name).append(SWAGGER_in, QUERY);
rstream(ap.find(Schema.class,
mpi)).forEach(x -> merge(param, x.inner()));
rstream(ap.find(Query.class,
mpi)).forEach(x -> merge(param, x.inner().schema()));
- pushupSchemaFields(QUERY, param,
getSchema(param.getMap("schema"), type, bs));
+ pushupSchemaFields(QUERY, param,
getSchema(param.getMap(SWAGGER_schema), type, bs));
addParamExample(sm, param, QUERY, type);
} else if (ap.has(FormData.class, mpi)) {
var name =
FormDataAnnotation.findName(mpi).orElse(null);
- var param = paramMap.getMap(FORM_DATA +
"." + name, true).append("name", name).append("in", FORM_DATA);
+ var param = paramMap.getMap(FORM_DATA +
"." + name, true).append(SWAGGER_name, name).append(SWAGGER_in, FORM_DATA);
rstream(ap.find(Schema.class,
mpi)).forEach(x -> merge(param, x.inner()));
rstream(ap.find(FormData.class,
mpi)).forEach(x -> merge(param, x.inner().schema()));
- pushupSchemaFields(FORM_DATA, param,
getSchema(param.getMap("schema"), type, bs));
+ pushupSchemaFields(FORM_DATA, param,
getSchema(param.getMap(SWAGGER_schema), type, bs));
addParamExample(sm, param, FORM_DATA,
type);
} else if (ap.has(Header.class, mpi)) {
var name =
HeaderAnnotation.findName(mpi).orElse(null);
- var param = paramMap.getMap(HEADER +
"." + name, true).append("name", name).append("in", HEADER);
+ var param = paramMap.getMap(HEADER +
"." + name, true).append(SWAGGER_name, name).append(SWAGGER_in, HEADER);
rstream(ap.find(Schema.class,
mpi)).forEach(x -> merge(param, x.inner()));
rstream(ap.find(Header.class,
mpi)).forEach(x -> merge(param, x.inner().schema()));
- pushupSchemaFields(HEADER, param,
getSchema(param.getMap("schema"), type, bs));
+ pushupSchemaFields(HEADER, param,
getSchema(param.getMap(SWAGGER_schema), type, bs));
addParamExample(sm, param, HEADER,
type);
} else if (ap.has(Path.class, mpi)) {
var name =
PathAnnotation.findName(mpi).orElse(null);
- var param = paramMap.getMap(PATH + "."
+ name, true).append("name", name).append("in", PATH);
+ var param = paramMap.getMap(PATH + "."
+ name, true).append(SWAGGER_name, name).append(SWAGGER_in, PATH);
rstream(ap.find(Schema.class,
mpi)).forEach(x -> merge(param, x.inner()));
rstream(ap.find(Path.class,
mpi)).forEach(x -> merge(param, x.inner().schema()));
- pushupSchemaFields(PATH, param,
getSchema(param.getMap("schema"), type, bs));
+ pushupSchemaFields(PATH, param,
getSchema(param.getMap(SWAGGER_schema), type, bs));
addParamExample(sm, param, PATH, type);
- param.putIfAbsent("required", true);
+ param.putIfAbsent(SWAGGER_required,
SWAGGER_true);
}
}
if (! paramMap.isEmpty())
- op.put("parameters", paramMap.values());
+ op.put(SWAGGER_parameters, paramMap.values());
- var responses = op.getMap("responses", true);
+ var responses = op.getMap(SWAGGER_responses, true);
for (var eci : mi.getExceptionTypes()) {
if (eci.hasAnnotation(Response.class)) {
@@ -439,10 +511,10 @@ public class BasicSwaggerProviderSession {
for (var code : codes) {
var om =
responses.getMap(String.valueOf(code), true);
merge(om, a);
- var schema =
getSchema(om.getMap("schema"), m.getGenericReturnType(), bs);
+ var schema =
getSchema(om.getMap(SWAGGER_schema), m.getGenericReturnType(), bs);
rstream(ap.find(Schema.class, eci)).forEach(x -> merge(schema, x.inner()));
pushupSchemaFields(RESPONSE, om, schema);
- om.appendIf(nem,
"schema", schema);
+ om.appendIf(nem,
SWAGGER_schema, schema);
}
}
var methods = eci.getAllMethods();
@@ -454,10 +526,10 @@ public class BasicSwaggerProviderSession {
if (nn(a) && ! isMulti(a)) {
var ha = a.name();
for (var code : codes) {
- var header =
responses.getMap(String.valueOf(code), true).getMap("headers", true).getMap(ha,
true);
+ var header =
responses.getMap(String.valueOf(code), true).getMap(SWAGGER_headers,
true).getMap(ha, true);
rstream(ap.find(Schema.class, ecmi)).forEach(x -> merge(header, x.inner()));
rstream(ap.find(Schema.class, ecmi.getReturnType().unwrap(Value.class,
Optional.class))).forEach(x -> merge(header, x.inner()));
-
pushupSchemaFields(RESPONSE_HEADER, header, getSchema(header.getMap("schema"),
ecmi.getReturnType().unwrap(Value.class, Optional.class).innerType(), bs));
+
pushupSchemaFields(RESPONSE_HEADER, header,
getSchema(header.getMap(SWAGGER_schema),
ecmi.getReturnType().unwrap(Value.class, Optional.class).innerType(), bs));
}
}
}
@@ -472,10 +544,10 @@ public class BasicSwaggerProviderSession {
for (var code : codes) {
var om =
responses.getMap(String.valueOf(code), true);
merge(om, a);
- var schema =
getSchema(om.getMap("schema"), m.getGenericReturnType(), bs);
+ var schema =
getSchema(om.getMap(SWAGGER_schema), m.getGenericReturnType(), bs);
rstream(ap.find(Schema.class,
mi)).forEach(x -> merge(schema, x.inner()));
pushupSchemaFields(RESPONSE,
om, schema);
- om.appendIf(nem, "schema",
schema);
+ om.appendIf(nem,
SWAGGER_schema, schema);
addBodyExamples(sm, om, true,
m.getGenericReturnType(), locale);
}
}
@@ -488,7 +560,7 @@ public class BasicSwaggerProviderSession {
var ha = a.name();
if (! isMulti(a)) {
for (var code :
codes) {
- var
header = responses.getMap(String.valueOf(code), true).getMap("headers",
true).getMap(ha, true);
+ var
header = responses.getMap(String.valueOf(code), true).getMap(SWAGGER_headers,
true).getMap(ha, true);
rstream(ap.find(Schema.class, ecmi)).forEach(x -> merge(header, x.inner()));
rstream(ap.find(Schema.class, ecmi.getReturnType().unwrap(Value.class,
Optional.class))).forEach(x -> merge(header, x.inner()));
merge(header, a.schema());
@@ -499,12 +571,12 @@ public class BasicSwaggerProviderSession {
}
}
} else if (m.getGenericReturnType() != void.class) {
- var om = responses.getMap("200", true);
+ var om = responses.getMap(CONST_200, true);
var pt2 =
ClassInfo.of(m.getGenericReturnType());
- var schema = getSchema(om.getMap("schema"),
m.getGenericReturnType(), bs);
+ var schema =
getSchema(om.getMap(SWAGGER_schema), m.getGenericReturnType(), bs);
rstream(ap.find(Schema.class, pt2)).forEach(x
-> merge(schema, x.inner()));
pushupSchemaFields(RESPONSE, om, schema);
- om.appendIf(nem, "schema", schema);
+ om.appendIf(nem, SWAGGER_schema, schema);
addBodyExamples(sm, om, true,
m.getGenericReturnType(), locale);
}
@@ -522,7 +594,7 @@ public class BasicSwaggerProviderSession {
for (var a : la) {
if (! isMulti(a)) {
for (var code : codes) {
- var header =
responses.getMap(String.valueOf(code), true).getMap("headers",
true).getMap(name, true);
+ var header =
responses.getMap(String.valueOf(code), true).getMap(SWAGGER_headers,
true).getMap(name, true);
rstream(ap.find(Schema.class, mpi)).forEach(x -> merge(header, x.inner()));
merge(header,
a.schema());
pushupSchemaFields(RESPONSE_HEADER, header, getSchema(header, type, bs));
@@ -539,11 +611,11 @@ public class BasicSwaggerProviderSession {
for (var code : codes) {
var om =
responses.getMap(String.valueOf(code), true);
merge(om, a);
- var schema =
getSchema(om.getMap("schema"), type, bs);
+ var schema =
getSchema(om.getMap(SWAGGER_schema), type, bs);
rstream(ap.find(Schema.class, mpi)).forEach(x -> merge(schema, x.inner()));
la.forEach(x ->
merge(schema, x.schema()));
pushupSchemaFields(RESPONSE, om, schema);
- om.appendIf(nem,
"schema", schema);
+ om.appendIf(nem,
SWAGGER_schema, schema);
}
}
}
@@ -554,24 +626,24 @@ public class BasicSwaggerProviderSession {
var key = e.getKey();
var val = responses.getMap(key);
if (isDecimal(key))
- val.appendIfAbsentIf(ne, "description",
RestUtils.getHttpResponseText(Integer.parseInt(key)));
+ val.appendIfAbsentIf(ne,
SWAGGER_description, RestUtils.getHttpResponseText(Integer.parseInt(key)));
}
if (responses.isEmpty())
- op.remove("responses");
+ op.remove(SWAGGER_responses);
else
- op.put("responses", new TreeMap<>(responses));
+ op.put(SWAGGER_responses, new
TreeMap<>(responses));
- if (! op.containsKey("consumes")) {
+ if (! op.containsKey(SWAGGER_consumes)) {
var mConsumes = sm.getSupportedContentTypes();
if (! mConsumes.equals(consumes))
- op.put("consumes", mConsumes);
+ op.put(SWAGGER_consumes, mConsumes);
}
- if (! op.containsKey("produces")) {
+ if (! op.containsKey(SWAGGER_produces)) {
var mProduces = sm.getSupportedAcceptTypes();
if (! mProduces.equals(produces))
- op.put("produces", mProduces);
+ op.put(SWAGGER_produces, mProduces);
}
}
@@ -580,15 +652,15 @@ public class BasicSwaggerProviderSession {
definitions.put(e.getKey(),
fixSwaggerExtensions(e.getValue()));
if (definitions.isEmpty())
- omSwagger.remove("definitions");
+ omSwagger.remove(SWAGGER_definitions);
if (! tagMap.isEmpty())
- omSwagger.put("tags", tagMap.values());
+ omSwagger.put(SWAGGER_tags, tagMap.values());
if (consumes.isEmpty())
- omSwagger.remove("consumes");
+ omSwagger.remove(SWAGGER_consumes);
if (produces.isEmpty())
- omSwagger.remove("produces");
+ omSwagger.remove(SWAGGER_produces);
try {
var swaggerJson =
Json5Serializer.DEFAULT_READABLE.toString(omSwagger);
@@ -602,12 +674,12 @@ public class BasicSwaggerProviderSession {
@SuppressWarnings("java:S3776")
private void addBodyExamples(RestOpContext sm, JsonMap piri, boolean
response, Type type, Locale locale) throws Exception {
- var sex = piri.getString("example");
+ var sex = piri.getString(SWAGGER_example);
if (sex == null) {
- var schema = resolveRef(piri.getMap("schema"));
+ var schema = resolveRef(piri.getMap(SWAGGER_schema));
if (nn(schema))
- sex = schema.getString("example",
schema.getString("example"));
+ sex = schema.getString(SWAGGER_example,
schema.getString(SWAGGER_example));
}
if (isEmpty(sex))
@@ -623,7 +695,7 @@ public class BasicSwaggerProviderSession {
}
}
- var examplesKey = "examples"; // Parameters don't have an
examples attribute.
+ var examplesKey = SWAGGER_examples; // Parameters don't have
an examples attribute.
var examples = piri.getMap(examplesKey);
if (examples == null)
@@ -659,16 +731,16 @@ public class BasicSwaggerProviderSession {
private static void addParamExample(RestOpContext sm, JsonMap piri,
RestPartType in, Type type) throws Exception {
- var s = piri.getString("example");
+ var s = piri.getString(SWAGGER_example);
if (isEmpty(s))
return;
- var examples = piri.getMap("examples");
+ var examples = piri.getMap(SWAGGER_examples);
if (examples == null)
examples = new JsonMap();
- var paramName = piri.getString("name");
+ var paramName = piri.getString(SWAGGER_name);
if (in == QUERY)
s = "?" + urlEncodeLax(paramName) + "=" +
urlEncodeLax(s);
@@ -679,10 +751,10 @@ public class BasicSwaggerProviderSession {
else if (in == PATH)
s = sm.getPathPattern().replace("{" + paramName + "}",
urlEncodeLax(s));
- examples.put("example", s);
+ examples.put(SWAGGER_example, s);
if (! examples.isEmpty())
- piri.put("examples", examples);
+ piri.put(SWAGGER_examples, examples);
}
@SafeVarargs
@@ -700,17 +772,17 @@ public class BasicSwaggerProviderSession {
Predicate<Object> nn = Utils::nn;
// @formatter:off
om
- .appendIf(nn, "discriminator",
om.remove("x-discriminator"))
- .appendIf(nn, "readOnly", om.remove("x-readOnly"))
- .appendIf(nn, "xml", om.remove("x-xml"))
- .appendIf(nn, "externalDocs",
om.remove("x-externalDocs"))
- .appendIf(nn, "example", om.remove("x-example"));
+ .appendIf(nn, SWAGGER_discriminator,
om.remove(JSONSCHEMA_x_discriminator))
+ .appendIf(nn, SWAGGER_readOnly,
om.remove(JSONSCHEMA_x_readOnly))
+ .appendIf(nn, SWAGGER_xml, om.remove(JSONSCHEMA_x_xml))
+ .appendIf(nn, SWAGGER_externalDocs,
om.remove(JSONSCHEMA_x_externalDocs))
+ .appendIf(nn, SWAGGER_example,
om.remove(JSONSCHEMA_x_example));
// @formatter:on
return nullIfEmpty(om);
}
private static JsonMap getOperation(JsonMap om, String path, String
httpMethod) {
- om = (JsonMap) om.computeIfAbsent("paths", k -> new JsonMap());
+ om = (JsonMap) om.computeIfAbsent(SWAGGER_paths, k -> new
JsonMap());
om = (JsonMap) om.computeIfAbsent(path, k -> new JsonMap());
om.computeIfAbsent(httpMethod, k -> new JsonMap());
return (JsonMap) om.get(httpMethod);
@@ -725,10 +797,10 @@ public class BasicSwaggerProviderSession {
var cm = bs.getClassMeta(type);
- if (schema.is("ignore", false))
+ if (schema.is(SWAGGER_ignore, false))
return null;
- if (schema.containsKey("type") || schema.containsKey("$ref"))
+ if (schema.containsKey(SWAGGER_type) ||
schema.containsKey(SWAGGER_$ref))
return schema;
var om = fixSwaggerExtensions(schema.append(js.getSchema(cm)));
@@ -771,8 +843,8 @@ public class BasicSwaggerProviderSession {
Predicate<String> ne = Utils::ne;
// @formatter:off
return om
- .appendIf(ne, "description", resolve(a.description()))
- .appendIf(ne, "url", a.url())
+ .appendIf(ne, SWAGGER_description,
resolve(a.description()))
+ .appendIf(ne, SWAGGER_url, a.url())
;
// @formatter:on
}
@@ -801,24 +873,24 @@ public class BasicSwaggerProviderSession {
Predicate<Long> nm1 = Utils::nm1;
// @formatter:off
return om
- .appendFirst(ne, "collectionFormat",
a.collectionFormat(), a.cf())
- .appendIf(ne, "default", joinnl(a.default_(), a.df()))
- .appendFirst(nec, "enum", toSet(a.enum_()),
toSet(a.e()))
- .appendFirst(ne, "format", a.format(), a.f())
- .appendIf(nf, "exclusiveMaximum", a.exclusiveMaximum()
|| a.emax())
- .appendIf(nf, "exclusiveMinimum", a.exclusiveMinimum()
|| a.emin())
- .appendIf(nem, "items", merge(om.getMap("items"),
a.items()))
- .appendFirst(ne, "maximum", a.maximum(), a.max())
- .appendFirst(nm1, "maxItems", a.maxItems(), a.maxi())
- .appendFirst(nm1, "maxLength", a.maxLength(), a.maxl())
- .appendFirst(ne, "minimum", a.minimum(), a.min())
- .appendFirst(nm1, "minItems", a.minItems(), a.mini())
- .appendFirst(nm1, "minLength", a.minLength(), a.minl())
- .appendFirst(ne, "multipleOf", a.multipleOf(), a.mo())
- .appendFirst(ne, "pattern", a.pattern(), a.p())
- .appendIf(nf, "uniqueItems", a.uniqueItems() || a.ui())
- .appendFirst(ne, "type", a.type(), a.t())
- .appendIf(ne, "$ref", a.$ref())
+ .appendFirst(ne, SWAGGER_collectionFormat,
a.collectionFormat(), a.cf())
+ .appendIf(ne, SWAGGER_default, joinnl(a.default_(),
a.df()))
+ .appendFirst(nec, SWAGGER_enum, toSet(a.enum_()),
toSet(a.e()))
+ .appendFirst(ne, SWAGGER_format, a.format(), a.f())
+ .appendIf(nf, SWAGGER_exclusiveMaximum,
a.exclusiveMaximum() || a.emax())
+ .appendIf(nf, SWAGGER_exclusiveMinimum,
a.exclusiveMinimum() || a.emin())
+ .appendIf(nem, SWAGGER_items,
merge(om.getMap(SWAGGER_items), a.items()))
+ .appendFirst(ne, SWAGGER_maximum, a.maximum(), a.max())
+ .appendFirst(nm1, SWAGGER_maxItems, a.maxItems(),
a.maxi())
+ .appendFirst(nm1, SWAGGER_maxLength, a.maxLength(),
a.maxl())
+ .appendFirst(ne, SWAGGER_minimum, a.minimum(), a.min())
+ .appendFirst(nm1, SWAGGER_minItems, a.minItems(),
a.mini())
+ .appendFirst(nm1, SWAGGER_minLength, a.minLength(),
a.minl())
+ .appendFirst(ne, SWAGGER_multipleOf, a.multipleOf(),
a.mo())
+ .appendFirst(ne, SWAGGER_pattern, a.pattern(), a.p())
+ .appendIf(nf, SWAGGER_uniqueItems, a.uniqueItems() ||
a.ui())
+ .appendFirst(ne, SWAGGER_type, a.type(), a.t())
+ .appendIf(ne, SWAGGER_$ref, a.$ref())
;
// @formatter:on
}
@@ -832,9 +904,9 @@ public class BasicSwaggerProviderSession {
merge(om, a.schema());
// @formatter:off
return om
- .appendIf(nem, "examples", parseMap(a.examples()))
- .appendIf(nem, "headers", merge(om.getMap("headers"),
a.headers()))
- .appendIf(nem, "schema", merge(om.getMap("schema"),
a.schema()))
+ .appendIf(nem, SWAGGER_examples, parseMap(a.examples()))
+ .appendIf(nem, SWAGGER_headers,
merge(om.getMap(SWAGGER_headers), a.headers()))
+ .appendIf(nem, SWAGGER_schema,
merge(om.getMap(SWAGGER_schema), a.schema()))
;
// @formatter:on
}
@@ -852,37 +924,37 @@ public class BasicSwaggerProviderSession {
Predicate<Long> nm1 = Utils::nm1;
// @formatter:off
return om
- .appendIf(nem, "additionalProperties",
toJsonMap(a.additionalProperties()))
- .appendIf(ne, "allOf", joinnl(a.allOf()))
- .appendFirst(ne, "collectionFormat",
a.collectionFormat(), a.cf())
- .appendIf(ne, "default", joinnl(a.default_(),
a.df()))
- .appendIf(ne, "discriminator",
a.discriminator())
- .appendIf(ne, "description",
resolve(a.description(), a.d()))
- .appendFirst(nec, "enum", toSet(a.enum_()),
toSet(a.e()))
- .appendIf(nf, "exclusiveMaximum",
a.exclusiveMaximum() || a.emax())
- .appendIf(nf, "exclusiveMinimum",
a.exclusiveMinimum() || a.emin())
- .appendIf(nem, "externalDocs",
merge(om.getMap("externalDocs"), a.externalDocs()))
- .appendFirst(ne, "format", a.format(), a.f())
- .appendIf(ne, "ignore", a.ignore() ? "true" :
null)
- .appendIf(nem, "items",
merge(om.getMap("items"), a.items()))
- .appendFirst(ne, "maximum", a.maximum(),
a.max())
- .appendFirst(nm1, "maxItems", a.maxItems(),
a.maxi())
- .appendFirst(nm1, "maxLength", a.maxLength(),
a.maxl())
- .appendFirst(nm1, "maxProperties",
a.maxProperties(), a.maxp())
- .appendFirst(ne, "minimum", a.minimum(),
a.min())
- .appendFirst(nm1, "minItems", a.minItems(),
a.mini())
- .appendFirst(nm1, "minLength", a.minLength(),
a.minl())
- .appendFirst(nm1, "minProperties",
a.minProperties(), a.minp())
- .appendFirst(ne, "multipleOf", a.multipleOf(),
a.mo())
- .appendFirst(ne, "pattern", a.pattern(), a.p())
- .appendIf(nem, "properties",
toJsonMap(a.properties()))
- .appendIf(nf, "readOnly", a.readOnly() ||
a.ro())
- .appendIf(nf, "required", a.required() || a.r())
- .appendIf(ne, "title", a.title())
- .appendFirst(ne, "type", a.type(), a.t())
- .appendIf(nf, "uniqueItems", a.uniqueItems() ||
a.ui())
- .appendIf(ne, "xml", joinnl(a.xml()))
- .appendIf(ne, "$ref", a.$ref())
+ .appendIf(nem, SWAGGER_additionalProperties,
toJsonMap(a.additionalProperties()))
+ .appendIf(ne, SWAGGER_allOf, joinnl(a.allOf()))
+ .appendFirst(ne, SWAGGER_collectionFormat,
a.collectionFormat(), a.cf())
+ .appendIf(ne, SWAGGER_default,
joinnl(a.default_(), a.df()))
+ .appendIf(ne, SWAGGER_discriminator,
a.discriminator())
+ .appendIf(ne, SWAGGER_description,
resolve(a.description(), a.d()))
+ .appendFirst(nec, SWAGGER_enum,
toSet(a.enum_()), toSet(a.e()))
+ .appendIf(nf, SWAGGER_exclusiveMaximum,
a.exclusiveMaximum() || a.emax())
+ .appendIf(nf, SWAGGER_exclusiveMinimum,
a.exclusiveMinimum() || a.emin())
+ .appendIf(nem, SWAGGER_externalDocs,
merge(om.getMap(SWAGGER_externalDocs), a.externalDocs()))
+ .appendFirst(ne, SWAGGER_format, a.format(),
a.f())
+ .appendIf(ne, SWAGGER_ignore, a.ignore() ?
SWAGGER_true : null)
+ .appendIf(nem, SWAGGER_items,
merge(om.getMap(SWAGGER_items), a.items()))
+ .appendFirst(ne, SWAGGER_maximum, a.maximum(),
a.max())
+ .appendFirst(nm1, SWAGGER_maxItems,
a.maxItems(), a.maxi())
+ .appendFirst(nm1, SWAGGER_maxLength,
a.maxLength(), a.maxl())
+ .appendFirst(nm1, SWAGGER_maxProperties,
a.maxProperties(), a.maxp())
+ .appendFirst(ne, SWAGGER_minimum, a.minimum(),
a.min())
+ .appendFirst(nm1, SWAGGER_minItems,
a.minItems(), a.mini())
+ .appendFirst(nm1, SWAGGER_minLength,
a.minLength(), a.minl())
+ .appendFirst(nm1, SWAGGER_minProperties,
a.minProperties(), a.minp())
+ .appendFirst(ne, SWAGGER_multipleOf,
a.multipleOf(), a.mo())
+ .appendFirst(ne, SWAGGER_pattern, a.pattern(),
a.p())
+ .appendIf(nem, SWAGGER_properties,
toJsonMap(a.properties()))
+ .appendIf(nf, SWAGGER_readOnly, a.readOnly() ||
a.ro())
+ .appendIf(nf, SWAGGER_required, a.required() ||
a.r())
+ .appendIf(ne, SWAGGER_title, a.title())
+ .appendFirst(ne, SWAGGER_type, a.type(), a.t())
+ .appendIf(nf, SWAGGER_uniqueItems,
a.uniqueItems() || a.ui())
+ .appendIf(ne, SWAGGER_xml, joinnl(a.xml()))
+ .appendIf(ne, SWAGGER_$ref, a.$ref())
;
// @formatter:on
} catch (ParseException e) {
@@ -901,24 +973,24 @@ public class BasicSwaggerProviderSession {
Predicate<Long> nm1 = Utils::nm1;
// @formatter:off
return om
- .appendFirst(ne, "collectionFormat",
a.collectionFormat(), a.cf())
- .appendIf(ne, "default", joinnl(a.default_(), a.df()))
- .appendFirst(nec, "enum", toSet(a.enum_()),
toSet(a.e()))
- .appendIf(nf, "exclusiveMaximum", a.exclusiveMaximum()
|| a.emax())
- .appendIf(nf, "exclusiveMinimum", a.exclusiveMinimum()
|| a.emin())
- .appendFirst(ne, "format", a.format(), a.f())
- .appendIf(nem, "items", toJsonMap(a.items()))
- .appendFirst(ne, "maximum", a.maximum(), a.max())
- .appendFirst(nm1, "maxItems", a.maxItems(), a.maxi())
- .appendFirst(nm1, "maxLength", a.maxLength(), a.maxl())
- .appendFirst(ne, "minimum", a.minimum(), a.min())
- .appendFirst(nm1, "minItems", a.minItems(), a.mini())
- .appendFirst(nm1, "minLength", a.minLength(), a.minl())
- .appendFirst(ne, "multipleOf", a.multipleOf(), a.mo())
- .appendFirst(ne, "pattern", a.pattern(), a.p())
- .appendFirst(ne, "type", a.type(), a.t())
- .appendIf(nf, "uniqueItems", a.uniqueItems() || a.ui())
- .appendIf(ne, "$ref", a.$ref())
+ .appendFirst(ne, SWAGGER_collectionFormat,
a.collectionFormat(), a.cf())
+ .appendIf(ne, SWAGGER_default, joinnl(a.default_(),
a.df()))
+ .appendFirst(nec, SWAGGER_enum, toSet(a.enum_()),
toSet(a.e()))
+ .appendIf(nf, SWAGGER_exclusiveMaximum,
a.exclusiveMaximum() || a.emax())
+ .appendIf(nf, SWAGGER_exclusiveMinimum,
a.exclusiveMinimum() || a.emin())
+ .appendFirst(ne, SWAGGER_format, a.format(), a.f())
+ .appendIf(nem, SWAGGER_items, toJsonMap(a.items()))
+ .appendFirst(ne, SWAGGER_maximum, a.maximum(), a.max())
+ .appendFirst(nm1, SWAGGER_maxItems, a.maxItems(),
a.maxi())
+ .appendFirst(nm1, SWAGGER_maxLength, a.maxLength(),
a.maxl())
+ .appendFirst(ne, SWAGGER_minimum, a.minimum(), a.min())
+ .appendFirst(nm1, SWAGGER_minItems, a.minItems(),
a.mini())
+ .appendFirst(nm1, SWAGGER_minLength, a.minLength(),
a.minl())
+ .appendFirst(ne, SWAGGER_multipleOf, a.multipleOf(),
a.mo())
+ .appendFirst(ne, SWAGGER_pattern, a.pattern(), a.p())
+ .appendFirst(ne, SWAGGER_type, a.type(), a.t())
+ .appendIf(nf, SWAGGER_uniqueItems, a.uniqueItems() ||
a.ui())
+ .appendIf(ne, SWAGGER_$ref, a.$ref())
;
// @formatter:on
}
@@ -962,8 +1034,8 @@ public class BasicSwaggerProviderSession {
if (o2.isEmpty())
return null;
o2 = resolve(o2);
- if ("IGNORE".equalsIgnoreCase(o2))
- return JsonMap.of("ignore", true);
+ if (CONST_IGNORE.equalsIgnoreCase(o2))
+ return JsonMap.of(SWAGGER_ignore, true);
if (! isProbablyJsonObject(o2, true))
o2 = "{" + o2 + "}";
return JsonMap.ofJson(o2);
@@ -997,32 +1069,32 @@ public class BasicSwaggerProviderSession {
if (nn(schema) && ! schema.isEmpty()) {
if (type == BODY || type == RESPONSE) {
param
- .appendIf(ne, "description",
schema.remove("description"));
+ .appendIf(ne, SWAGGER_description,
schema.remove(SWAGGER_description));
} else {
param
- .appendIfAbsentIf(ne,
"collectionFormat", schema.remove("collectionFormat"))
- .appendIfAbsentIf(ne, "default",
schema.remove("default"))
- .appendIfAbsentIf(ne, "description",
schema.remove("description"))
- .appendIfAbsentIf(ne, "enum",
schema.remove("enum"))
- .appendIfAbsentIf(ne, "example",
schema.remove("example"))
- .appendIfAbsentIf(ne,
"exclusiveMaximum", schema.remove("exclusiveMaximum"))
- .appendIfAbsentIf(ne,
"exclusiveMinimum", schema.remove("exclusiveMinimum"))
- .appendIfAbsentIf(ne, "format",
schema.remove("format"))
- .appendIfAbsentIf(ne, "items",
schema.remove("items"))
- .appendIfAbsentIf(ne, "maximum",
schema.remove("maximum"))
- .appendIfAbsentIf(ne, "maxItems",
schema.remove("maxItems"))
- .appendIfAbsentIf(ne, "maxLength",
schema.remove("maxLength"))
- .appendIfAbsentIf(ne, "minimum",
schema.remove("minimum"))
- .appendIfAbsentIf(ne, "minItems",
schema.remove("minItems"))
- .appendIfAbsentIf(ne, "minLength",
schema.remove("minLength"))
- .appendIfAbsentIf(ne, "multipleOf",
schema.remove("multipleOf"))
- .appendIfAbsentIf(ne, "pattern",
schema.remove("pattern"))
- .appendIfAbsentIf(ne, "required",
schema.remove("required"))
- .appendIfAbsentIf(ne, "type",
schema.remove("type"))
- .appendIfAbsentIf(ne, "uniqueItems",
schema.remove("uniqueItems"));
-
- if ("object".equals(param.getString("type")) &&
! schema.isEmpty())
- param.put("schema", schema);
+ .appendIfAbsentIf(ne,
SWAGGER_collectionFormat, schema.remove(SWAGGER_collectionFormat))
+ .appendIfAbsentIf(ne, SWAGGER_default,
schema.remove(SWAGGER_default))
+ .appendIfAbsentIf(ne,
SWAGGER_description, schema.remove(SWAGGER_description))
+ .appendIfAbsentIf(ne, SWAGGER_enum,
schema.remove(SWAGGER_enum))
+ .appendIfAbsentIf(ne, SWAGGER_example,
schema.remove(SWAGGER_example))
+ .appendIfAbsentIf(ne,
SWAGGER_exclusiveMaximum, schema.remove(SWAGGER_exclusiveMaximum))
+ .appendIfAbsentIf(ne,
SWAGGER_exclusiveMinimum, schema.remove(SWAGGER_exclusiveMinimum))
+ .appendIfAbsentIf(ne, SWAGGER_format,
schema.remove(SWAGGER_format))
+ .appendIfAbsentIf(ne, SWAGGER_items,
schema.remove(SWAGGER_items))
+ .appendIfAbsentIf(ne, SWAGGER_maximum,
schema.remove(SWAGGER_maximum))
+ .appendIfAbsentIf(ne, SWAGGER_maxItems,
schema.remove(SWAGGER_maxItems))
+ .appendIfAbsentIf(ne,
SWAGGER_maxLength, schema.remove(SWAGGER_maxLength))
+ .appendIfAbsentIf(ne, SWAGGER_minimum,
schema.remove(SWAGGER_minimum))
+ .appendIfAbsentIf(ne, SWAGGER_minItems,
schema.remove(SWAGGER_minItems))
+ .appendIfAbsentIf(ne,
SWAGGER_minLength, schema.remove(SWAGGER_minLength))
+ .appendIfAbsentIf(ne,
SWAGGER_multipleOf, schema.remove(SWAGGER_multipleOf))
+ .appendIfAbsentIf(ne, SWAGGER_pattern,
schema.remove(SWAGGER_pattern))
+ .appendIfAbsentIf(ne, SWAGGER_required,
schema.remove(SWAGGER_required))
+ .appendIfAbsentIf(ne, SWAGGER_type,
schema.remove(SWAGGER_type))
+ .appendIfAbsentIf(ne,
SWAGGER_uniqueItems, schema.remove(SWAGGER_uniqueItems));
+
+ if
(SWAGGER_object.equals(param.getString(SWAGGER_type)) && ! schema.isEmpty())
+ param.put(SWAGGER_schema, schema);
}
}
@@ -1047,9 +1119,9 @@ public class BasicSwaggerProviderSession {
private JsonMap resolve(JsonMap om) throws ParseException {
JsonMap om2 = null;
- if (om.containsKey("_value")) {
+ if (om.containsKey(CONST_value)) {
om = om.modifiable();
- om2 = parseMap(om.remove("_value"));
+ om2 = parseMap(om.remove(CONST_value));
} else {
om2 = new JsonMap();
}
@@ -1084,8 +1156,8 @@ public class BasicSwaggerProviderSession {
private JsonMap resolveRef(JsonMap m) {
if (m == null)
return null;
- if (m.containsKey("$ref") && nn(js.getBeanDefs())) {
- var ref = m.getString("$ref");
+ if (m.containsKey(SWAGGER_$ref) && nn(js.getBeanDefs())) {
+ var ref = m.getString(SWAGGER_$ref);
if (ref.startsWith("#/definitions/"))
return js.getBeanDefs().get(ref.substring(14));
}
@@ -1119,9 +1191,9 @@ public class BasicSwaggerProviderSession {
Predicate<String> ne = Utils::ne;
// @formatter:off
var om = JsonMap.create()
- .appendIf(ne, "name", resolve(a.name()))
- .appendIf(ne, "url", resolve(a.url()))
- .appendIf(ne, "email", resolve(a.email()));
+ .appendIf(ne, SWAGGER_name, resolve(a.name()))
+ .appendIf(ne, SWAGGER_url, resolve(a.url()))
+ .appendIf(ne, SWAGGER_email, resolve(a.email()));
// @formatter:on
return nullIfEmpty(om);
}
@@ -1132,8 +1204,8 @@ public class BasicSwaggerProviderSession {
Predicate<String> ne = Utils::ne;
// @formatter:off
var om = JsonMap.create()
- .appendIf(ne, "description",
resolve(joinnl(a.description())))
- .appendIf(ne, "url", resolve(a.url()));
+ .appendIf(ne, SWAGGER_description,
resolve(joinnl(a.description())))
+ .appendIf(ne, SWAGGER_url, resolve(a.url()));
// @formatter:on
return nullIfEmpty(om);
}
@@ -1144,8 +1216,8 @@ public class BasicSwaggerProviderSession {
Predicate<String> ne = Utils::ne;
// @formatter:off
var om = JsonMap.create()
- .appendIf(ne, "name", resolve(a.name()))
- .appendIf(ne, "url", resolve(a.url()));
+ .appendIf(ne, SWAGGER_name, resolve(a.name()))
+ .appendIf(ne, SWAGGER_url, resolve(a.url()));
// @formatter:on
return nullIfEmpty(om);
}
@@ -1156,9 +1228,9 @@ public class BasicSwaggerProviderSession {
Predicate<Map<?,?>> nem = Utils::ne;
// @formatter:off
om
- .appendIf(ne, "name", resolve(a.name()))
- .appendIf(ne, "description",
resolve(joinnl(a.description())))
- .appendIf(nem, "externalDocs",
merge(om.getMap("externalDocs"), toMap(a.externalDocs(), location,
locationArgs)));
+ .appendIf(ne, SWAGGER_name, resolve(a.name()))
+ .appendIf(ne, SWAGGER_description,
resolve(joinnl(a.description())))
+ .appendIf(nem, SWAGGER_externalDocs,
merge(om.getMap(SWAGGER_externalDocs), toMap(a.externalDocs(), location,
locationArgs)));
// @formatter:on
return nullIfEmpty(om);
}