Skip to content
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

feat: @RestResource annotation and source generation #97

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
micronaut = "4.4.9"
micronaut-docs = "2.0.0"
micronaut-test = "4.1.0"
micronaut-data = "4.7.0"
micronaut-sql = "5.6.0"
micronaut-serde = "2.9.0"
micronaut-security = "4.7.0"
micronaut-logging = "1.3.0"
managed-kotlinpoet = "1.16.0"
google-truth = "1.4.2"
google-compile-testing = "0.21.0"
Expand All @@ -12,7 +17,11 @@ ksp = '1.9.23-1.0.20'
[libraries]
# Core
micronaut-core = { module = 'io.micronaut:micronaut-core-bom', version.ref = 'micronaut' }

micronaut-serialization = { module = 'io.micronaut.serde:micronaut-serde-bom', version.ref = 'micronaut-serde' }
micronaut-data = { module = 'io.micronaut.data:micronaut-data-bom', version.ref = 'micronaut-data' }
micronaut-security = { module = 'io.micronaut.security:micronaut-security-bom', version.ref = 'micronaut-security' }
micronaut-sql = { module = 'io.micronaut.sql:micronaut-sql-bom', version.ref = 'micronaut-sql' }
micronaut-logging = { module = "io.micronaut.logging:micronaut-logging-bom", version.ref = "micronaut-logging" }
managed-kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "managed-kotlinpoet" }
managed-kotlinpoet-javapoet = { module = "com.squareup:kotlinpoet-javapoet", version.ref = "managed-kotlinpoet" }

Expand Down
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

configure<io.micronaut.build.MicronautBuildSettingsExtension> {
importMicronautCatalog()
importMicronautCatalog("micronaut-data")
importMicronautCatalog("micronaut-sql")
importMicronautCatalog("micronaut-serialization")
importMicronautCatalog("micronaut-security")
}

dependencyResolutionManagement {
Expand Down
3 changes: 3 additions & 0 deletions sourcegen-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
plugins {
id("io.micronaut.build.internal.sourcegen-module")
}
dependencies {
implementation(mnData.micronaut.data.model)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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.sourcegen.annotations;

import io.micronaut.data.repository.CrudRepository;
import io.micronaut.data.repository.GenericRepository;

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

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* The annotation to generate an interface implementing `with` copy method for records - `MyRecord withMyProperty(MyProperty)`.
*
* @author Denis Stepanov
* @since 1.0
*/
@Documented
@Retention(RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE})
public @interface RestResource {
/**
*
* @return The CRUD Repository for the resource.
*/
Class<? extends CrudRepository> repository();

/**
*
* @return The values supplied will be used to secure the resource controller.
*/
String[] rolesAllowed() default "isAuthenticated()";

/**
*
* @return The resource name. E.g. {@literal Book}
*/
String name() default "";

/**
*
* @return The base uri for the resource. e.g. {@literal books}
*/
String uri() default "";


/**
*
* @return Whether a resource /uri DELETE endpoint should be generated.
*/
boolean delete() default true;

/**
*
* @return Whether a resource /uri GET endpoint returning a JSON Array should be generated
*/
boolean list() default true;

/**
*
* @return Whether a resource /uri/{id} GET endpoint returning a JSON object should be generated
*/
boolean show() default true;

/**
*
* @return Whether a resource /uri PUT endpoint returning 200 OK should be generated
*/
boolean update() default true;

/**
*
* @return Whether a resource /uri POST endpoint returning 201 OK should be generated
*/
boolean save() default true;
}
3 changes: 2 additions & 1 deletion sourcegen-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ dependencies {
api(projects.sourcegenModel)
api(mn.micronaut.core.processor)
implementation(projects.sourcegenAnnotations)

implementation(mn.micronaut.http)
testImplementation(mnData.micronaut.data.jdbc)
testImplementation(mn.micronaut.inject.java.test)
testImplementation(projects.sourcegenGeneratorJava)
}
Loading
Loading