fix snippet tab completion

This commit is contained in:
Julian Krings 2025-06-27 12:20:25 +02:00
parent 5d28563b7c
commit 0ae1334a57
No known key found for this signature in database
GPG Key ID: 208C6E08C3B718D2

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,35 +539,36 @@ 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());
}
if (k.getType().isAnnotationPresent(Snippet.class)) { private JSONObject buildSnippet(JSONObject prop, Class<?> type) {
JSONObject anyOf = new JSONObject(); Snippet snippet = type.getDeclaredAnnotation(Snippet.class);
JSONArray arr = new JSONArray(); if (snippet == null) return prop;
JSONObject str = new JSONObject();
str.put("type", "string");
String key = "enum-snippet-" + k.getType().getDeclaredAnnotation(Snippet.class).value();
str.put("$ref", "#/definitions/" + key);
if (!definitions.containsKey(key)) { JSONObject anyOf = new JSONObject();
JSONObject j = new JSONObject(); JSONArray arr = new JSONArray();
JSONArray snl = new JSONArray(); JSONObject str = new JSONObject();
data.getPossibleSnippets(k.getType().getDeclaredAnnotation(Snippet.class).value()).forEach(snl::put); str.put("type", "string");
j.put("enum", snl); String key = "enum-snippet-" + snippet.value();
definitions.put(key, j); str.put("$ref", "#/definitions/" + key);
}
arr.put(prop); if (!definitions.containsKey(key)) {
arr.put(str); JSONObject j = new JSONObject();
prop.put("description", d.toString("\n")); JSONArray snl = new JSONArray();
str.put("description", d.toString("\n")); data.getPossibleSnippets(snippet.value()).forEach(snl::put);
anyOf.put("anyOf", arr); j.put("enum", snl);
anyOf.put("description", d.toString("\n")); definitions.put(key, j);
anyOf.put("!required", k.isAnnotationPresent(Required.class));
return anyOf;
} }
return prop; arr.put(prop);
arr.put(str);
str.put("description", prop.getString("description"));
anyOf.put("anyOf", arr);
anyOf.put("description", prop.getString("description"));
anyOf.put("!required", type.isAnnotationPresent(Required.class));
return anyOf;
} }
@NotNull @NotNull