Skip to content

Schema Registry #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: 1.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
12d1020
new module
elifKurtay Jan 13, 2025
ac5c4c5
fix generated source directory
elifKurtay Jan 22, 2025
b100b1d
Merge remote-tracking branch 'fork/schema-registry' into schema-registry
elifKurtay Jan 22, 2025
29894eb
confluent definition files
elifKurtay Jan 23, 2025
fd88958
Merge branch 'micronaut-projects:1.4.x' into schema-registry
elifKurtay Feb 6, 2025
74074b3
Merge remote-tracking branch 'fork/schema-registry' into schema-registry
elifKurtay Feb 6, 2025
3694457
client service draft
elifKurtay Feb 6, 2025
41337bb
clean up interface
elifKurtay Feb 6, 2025
8a06409
configuration properties added
elifKurtay Feb 6, 2025
21a9daf
switch to declarative client
elifKurtay Feb 7, 2025
f4a284d
new responses and broken filter
elifKurtay Feb 7, 2025
5ebba70
Merge branch 'micronaut-projects:1.5.x' into schema-registry
elifKurtay Feb 10, 2025
9ee9d84
declarative with filter auth
elifKurtay Feb 10, 2025
cb80b92
GeneratedFromSchema annotation
elifKurtay Feb 11, 2025
320b399
Merge branch 'micronaut-projects:1.5.x' into schema-registry
elifKurtay Feb 11, 2025
b64b3b3
push local to registry
elifKurtay Feb 11, 2025
2e5a96d
Merge remote-tracking branch 'fork/schema-registry' into schema-registry
elifKurtay Feb 11, 2025
1ef41b2
re-org
elifKurtay Feb 11, 2025
a7af47c
controller tests
elifKurtay Feb 12, 2025
b43df6d
Merge branch 'micronaut-projects:1.5.x' into schema-registry
elifKurtay Feb 12, 2025
ae6a4f3
filter matcher
elifKurtay Feb 13, 2025
0d00ba0
filter matcher
elifKurtay Feb 13, 2025
6c89cd8
Merge remote-tracking branch 'fork/schema-registry' into schema-registry
elifKurtay Feb 13, 2025
bdeba15
Merge remote-tracking branch 'fork/schema-registry' into schema-registry
elifKurtay Feb 13, 2025
63db930
Merge remote-tracking branch 'fork/schema-registry' into schema-registry
elifKurtay Feb 13, 2025
5c7244c
basic auth and no auth clients
elifKurtay Feb 13, 2025
bea2d80
fix multiple clients
elifKurtay Feb 13, 2025
5c68e30
manager check and disable
elifKurtay Feb 17, 2025
d9791d5
Code review
elifKurtay Feb 20, 2025
35472b2
Minor changes
andriy-dmytruk Feb 21, 2025
ccf8bd7
remove confluent test
elifKurtay Mar 6, 2025
b7a2bad
Merge branch 'micronaut-projects:1.5.x' into schema-registry
elifKurtay Mar 7, 2025
8d3e675
small cr changes
elifKurtay Mar 12, 2025
0a9ed1b
Merge remote-tracking branch 'fork/schema-registry' into schema-registry
elifKurtay Mar 12, 2025
acfe5c9
manager test added
elifKurtay Mar 12, 2025
4ee51d3
add docs
elifKurtay Mar 13, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2017-2024 original authors
*
* Licensed 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
*
* https://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 io.micronaut.jsonschema;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* An annotation that signals that the object was generated from json schema.
*
* @since 1.5.0
* @author Elif Kurtay
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface GeneratedFromSchema {

/**
* The title of the JSON schema file used to generate the object.
*
* @return The fileName
*/
String fileName() default "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.micronaut.core.annotation.Internal;
import io.micronaut.inject.processing.ProcessingException;
import io.micronaut.inject.visitor.VisitorContext;
import io.micronaut.jsonschema.GeneratedFromSchema;
import io.micronaut.jsonschema.generator.aggregator.AnnotationsAggregator;
import io.micronaut.jsonschema.generator.loaders.FileLoader;
import io.micronaut.jsonschema.generator.utils.GeneratorContext;
Expand Down Expand Up @@ -303,7 +304,9 @@ private File generateFromSchema(Schema jsonSchema, Path outputPath, String packa
public EnumDef buildEnum(Schema jsonSchema, String builderClassName) {
EnumDef.EnumDefBuilder enumBuilder = EnumDef.builder(builderClassName)
.addModifiers(Modifier.PUBLIC)
.addAnnotation(ClassTypeDef.of(SERDEABLE_ANN));
.addAnnotation(ClassTypeDef.of(SERDEABLE_ANN))
.addAnnotation(getGeneratedFromSchemaAnn());

boolean isComplexEnum = false;
LinkedHashMap<ExpressionDef.Constant, ExpressionDef> cases = new LinkedHashMap<>();
LinkedHashMap<String, Object> enumValues = new LinkedHashMap<>();
Expand Down Expand Up @@ -378,7 +381,8 @@ public EnumDef buildEnum(Schema jsonSchema, String builderClassName) {
private RecordDef buildRecord(Schema jsonSchema, String builderClassName) {
RecordDef.RecordDefBuilder objectBuilder = RecordDef.builder(builderClassName)
.addModifiers(Modifier.PUBLIC)
.addAnnotation(ClassTypeDef.of(SERDEABLE_ANN));
.addAnnotation(ClassTypeDef.of(SERDEABLE_ANN))
.addAnnotation(getGeneratedFromSchemaAnn());

addFields(jsonSchema, objectBuilder);
return objectBuilder.build();
Expand All @@ -387,7 +391,8 @@ private RecordDef buildRecord(Schema jsonSchema, String builderClassName) {
private ClassDef buildClass(Schema jsonSchema, String builderClassName) {
ClassDef.ClassDefBuilder objectBuilder = ClassDef.builder(builderClassName)
.addModifiers(Modifier.PUBLIC)
.addAnnotation(ClassTypeDef.of(SERDEABLE_ANN));
.addAnnotation(ClassTypeDef.of(SERDEABLE_ANN))
.addAnnotation(getGeneratedFromSchemaAnn());

if (context.hasDefinition(inputFileName + "/superClass")) {
var superClass = context.getDefinitionType(inputFileName + "/superClass");
Expand Down Expand Up @@ -421,7 +426,8 @@ private ClassDef buildClass(Schema jsonSchema, String builderClassName) {
private InterfaceDef buildInterface(Schema jsonSchema, String builderClassName) {
InterfaceDef.InterfaceDefBuilder objectBuilder = InterfaceDef.builder(builderClassName)
.addModifiers(Modifier.PUBLIC)
.addAnnotation(ClassTypeDef.of(SERDEABLE_ANN));
.addAnnotation(ClassTypeDef.of(SERDEABLE_ANN))
.addAnnotation(getGeneratedFromSchemaAnn());
if (jsonSchema.hasDiscriminator()) {
// top level interface
addDiscriminatorAnnotations(jsonSchema, objectBuilder);
Expand Down Expand Up @@ -632,4 +638,8 @@ public static String getOutputPackageName() {
public static VisitorContext.Language getLanguage() {
return language;
}

private static AnnotationDef getGeneratedFromSchemaAnn() {
return AnnotationDef.builder(ClassTypeDef.of(GeneratedFromSchema.class)).addMember("fileName", inputFileName).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AbstractGeneratorSpec extends Specification {

TypeDeclaration generateType(String className, String jsonSchema) {
SourceGenerator generator = new SourceGenerator("java")
SourceGenerator.setInputFileName("test.schema.json")

Path outputPath = new File("output").toPath() // Define the base output path
String packageName = "com.example.project"; // Example package name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class SimpleGeneratorSpec extends AbstractGeneratorSpec {
then:
content == """
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public enum Status {

ACTIVE("active"),
Expand Down Expand Up @@ -118,6 +121,9 @@ class SimpleGeneratorSpec extends AbstractGeneratorSpec {
then:
content == """
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public record Llama(
@NotNull @Min(0) int age,
@NotNull @Size(min = 1) String name,
Expand Down Expand Up @@ -159,6 +165,9 @@ class SimpleGeneratorSpec extends AbstractGeneratorSpec {
then:
content == """
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public record Llama(
@Min(0) int age,
Llama name,
Expand Down Expand Up @@ -207,20 +216,32 @@ class SimpleGeneratorSpec extends AbstractGeneratorSpec {
then:
content == """
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public record Default(
@Min(0) int age,
Defaults defaults
) {
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public record Defaults(
Run run
) {
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public record Run(
Shell shell,
@JsonProperty("working-directory") @Pattern(regexp = "^[a-zA-Z]*") String workingDirectory
) {
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public enum Shell {

BASH("bash"),
Expand Down Expand Up @@ -296,6 +317,9 @@ class SimpleGeneratorSpec extends AbstractGeneratorSpec {
then:
content == """
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public class Llama2 {
/**
* The age
Expand Down Expand Up @@ -395,6 +419,9 @@ class SimpleGeneratorSpec extends AbstractGeneratorSpec {
then:
content == """
@Serdeable
@GeneratedFromSchema(
fileName = "test.schema.json"
)
public record Llama3(
@NotNull @Size(min = 1) String name,
@NotNull String foo,
Expand Down
50 changes: 50 additions & 0 deletions json-schema-registry/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import io.micronaut.build.internal.generator.BeanGeneratorTask

plugins {
id("io.micronaut.build.internal.json-schema-module")
id("io.micronaut.build.internal.test-suite-generator-java")
}

dependencies {
compileOnly(mn.micronaut.core.processor)

implementation(projects.micronautJsonSchemaAnnotations)
implementation(mn.micronaut.http)
implementation(mn.micronaut.http.client)
implementation(mn.micronaut.jackson.databind)
implementation(mnSerde.micronaut.serde.jackson)
implementation(mnValidation.validation)

annotationProcessor(mn.micronaut.http.validation)
annotationProcessor(mnSerde.micronaut.serde.processor)

testAnnotationProcessor(mn.micronaut.inject.java)
testImplementation(mn.micronaut.inject)
testImplementation(mn.micronaut.http.server.netty)
testImplementation(mnTest.micronaut.test.junit5)
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
}


tasks.test {
useJUnitPlatform()
}

def animalGenerator = tasks.register("generateAnimals", BeanGeneratorTask) {
language = "java"
classpath.from(configurations.beanGenerator)
jsonFile.convention(layout.projectDirectory.file("src/test/resources/animal.schema.json"))
outputDirectory.convention(layout.buildDirectory.dir("generated/jsonSchema"))
packageName.convention("io.micronaut.jsonschema.generator.animals")
}

tasks.named("generateAnimals") {
}

sourceSets {
test {
java.srcDir('src/test/java')
java.srcDir(animalGenerator.map(BeanGeneratorTask::getGeneratedSourcesDirectory))
}
}
Loading
Loading