Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
[versions]
jackson = "2.16.1"
retrofit = "2.9.0"
victoolsJsonSchema = "4.38.0"
javaxValidation = "2.0.1.Final"

[libraries]
jacksonDatabind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
jacksonAnnotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" }
jacksonJsonSchema = { module = "com.kjetland:mbknor-jackson-jsonschema_2.12", version = "1.0.34" }
lombok = { module = "org.projectlombok:lombok", version = "1.18.30" }
junitBom = { module = "org.junit:junit-bom", version = "5.8.2" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofitJackson = { module = "com.squareup.retrofit2:converter-jackson", version.ref = "retrofit" }
retrofitRxJava2 = { module = "com.squareup.retrofit2:adapter-rxjava2", version.ref = "retrofit" }
retrofitMock = { module = "com.squareup.retrofit2:retrofit-mock", version.ref = "retrofit" }
jtokkit = { module = "com.knuddels:jtokkit", version = "1.1.0" }
victoolsJsonSchemaGenerator = { module = "com.github.victools:jsonschema-generator", version.ref = "victoolsJsonSchema" }
victoolsJsonSchemaJackson = { module = "com.github.victools:jsonschema-module-jackson", version.ref = "victoolsJsonSchema" }
javaxValidationApi = { module = "javax.validation:validation-api", version.ref = "javaxValidation" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 3 additions & 1 deletion service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ dependencies {
api libs.retrofit
implementation libs.retrofitRxJava2
implementation libs.retrofitJackson
implementation libs.jacksonJsonSchema
implementation libs.victoolsJsonSchemaGenerator
implementation libs.victoolsJsonSchemaJackson
implementation libs.javaxValidationApi

testImplementation(platform(libs.junitBom))
testImplementation 'org.junit.jupiter:junit-jupiter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.kjetland.jackson.jsonSchema.JsonSchemaConfig;
import com.kjetland.jackson.jsonSchema.JsonSchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.generator.SchemaVersion;
import com.github.victools.jsonschema.module.jackson.JacksonModule;
import com.github.victools.jsonschema.module.jackson.JacksonOption;

import java.io.IOException;

public class ChatFunctionParametersSerializer extends JsonSerializer<Class<?>> {

private final ObjectMapper mapper = new ObjectMapper();
private final JsonSchemaConfig config = JsonSchemaConfig.vanillaJsonSchemaDraft4();
private final JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(mapper, config);
private final SchemaGenerator schemaGenerator = new SchemaGenerator(
new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_7)
.with(new JacksonModule(JacksonOption.RESPECT_JSONPROPERTY_REQUIRED))
.build()
);

@Override
public void serialize(Class<?> value, JsonGenerator gen, SerializerProvider serializers)
Expand All @@ -23,7 +27,7 @@ public void serialize(Class<?> value, JsonGenerator gen, SerializerProvider seri
gen.writeNull();
} else {
try {
JsonNode schema = jsonSchemaGenerator.generateJsonSchema(value);
JsonNode schema = schemaGenerator.generateSchema(value);
gen.writeObject(schema);
} catch (Exception e) {
throw new RuntimeException("Failed to generate JSON Schema", e);
Expand Down
Loading