9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-24 01:29:16 +00:00

fix snippet tab completion

This commit is contained in:
Julian Krings
2025-06-27 12:20:25 +02:00
parent 5d28563b7c
commit 0ae1334a57

View File

@@ -153,19 +153,7 @@ public class SchemaBuilder {
o.put("properties", properties); o.put("properties", properties);
if (c.isAnnotationPresent(Snippet.class)) { return buildSnippet(o, c);
JSONObject anyOf = new JSONObject();
JSONArray arr = new JSONArray();
JSONObject str = new JSONObject();
str.put("type", "string");
arr.put(o);
arr.put(str);
anyOf.put("anyOf", arr);
return anyOf;
}
return o;
} }
private JSONObject buildProperty(Field k, Class<?> cl) { private JSONObject buildProperty(Field k, Class<?> cl) {
@@ -515,6 +503,13 @@ public class SchemaBuilder {
d.add(getDescription(k.getType())); d.add(getDescription(k.getType()));
Snippet snippet = k.getType().getDeclaredAnnotation(Snippet.class); Snippet snippet = k.getType().getDeclaredAnnotation(Snippet.class);
if (snippet == null) {
ArrayType array = k.getType().getDeclaredAnnotation(ArrayType.class);
if (array != null) {
snippet = array.type().getDeclaredAnnotation(Snippet.class);
}
}
if (snippet != null) { if (snippet != null) {
String sm = snippet.value(); String sm = snippet.value();
d.add(" "); d.add(" ");
@@ -544,37 +539,38 @@ public class SchemaBuilder {
description.forEach((g) -> d.add(g.trim())); description.forEach((g) -> d.add(g.trim()));
prop.put("type", type); prop.put("type", type);
prop.put("description", d.toString("\n")); prop.put("description", d.toString("\n"));
return buildSnippet(prop, k.getType());
}
private JSONObject buildSnippet(JSONObject prop, Class<?> type) {
Snippet snippet = type.getDeclaredAnnotation(Snippet.class);
if (snippet == null) return prop;
if (k.getType().isAnnotationPresent(Snippet.class)) {
JSONObject anyOf = new JSONObject(); JSONObject anyOf = new JSONObject();
JSONArray arr = new JSONArray(); JSONArray arr = new JSONArray();
JSONObject str = new JSONObject(); JSONObject str = new JSONObject();
str.put("type", "string"); str.put("type", "string");
String key = "enum-snippet-" + k.getType().getDeclaredAnnotation(Snippet.class).value(); String key = "enum-snippet-" + snippet.value();
str.put("$ref", "#/definitions/" + key); str.put("$ref", "#/definitions/" + key);
if (!definitions.containsKey(key)) { if (!definitions.containsKey(key)) {
JSONObject j = new JSONObject(); JSONObject j = new JSONObject();
JSONArray snl = new JSONArray(); JSONArray snl = new JSONArray();
data.getPossibleSnippets(k.getType().getDeclaredAnnotation(Snippet.class).value()).forEach(snl::put); data.getPossibleSnippets(snippet.value()).forEach(snl::put);
j.put("enum", snl); j.put("enum", snl);
definitions.put(key, j); definitions.put(key, j);
} }
arr.put(prop); arr.put(prop);
arr.put(str); arr.put(str);
prop.put("description", d.toString("\n")); str.put("description", prop.getString("description"));
str.put("description", d.toString("\n"));
anyOf.put("anyOf", arr); anyOf.put("anyOf", arr);
anyOf.put("description", d.toString("\n")); anyOf.put("description", prop.getString("description"));
anyOf.put("!required", k.isAnnotationPresent(Required.class)); anyOf.put("!required", type.isAnnotationPresent(Required.class));
return anyOf; return anyOf;
} }
return prop;
}
@NotNull @NotNull
private String addEnumList(JSONObject prop, KList<String> description, ArrayType t, Object[] values, Function<Object, String> function) { private String addEnumList(JSONObject prop, KList<String> description, ArrayType t, Object[] values, Function<Object, String> function) {
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();