Skip to content

Commit

Permalink
fix: provide more context when group/plural are missing
Browse files Browse the repository at this point in the history
Fixes #4396
  • Loading branch information
metacosm committed Sep 6, 2022
1 parent 95d414f commit a57bde6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

#### Improvements
* Fix #4348: Introduce specific annotations for the generators
* Fix #4396: Provide more error context when @Group/@Version annotations are missing

#### Dependency Upgrade
* Fix #4383: bump snakeyaml from 1.30 to 1.31
Expand Down
Expand Up @@ -30,6 +30,6 @@
@Target({TYPE})
@Retention(RUNTIME)
public @interface Group {

String NAME = Group.class.getSimpleName();
String value();
}
Expand Up @@ -29,6 +29,7 @@
@Target({TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Version {
String NAME = Version.class.getSimpleName();

/**
* The name of this version.
Expand Down
Expand Up @@ -84,8 +84,7 @@ static String getApiVersion(Class<?> clazz) {
}
if (group != null || version != null) {
throw new IllegalArgumentException(
"You need to specify both @" + Group.class.getSimpleName() + " and @"
+ Version.class.getSimpleName() + " annotations if you specify either");
"You need to specify both @" + Group.NAME + " and @" + Version.NAME + " annotations if you specify either");
}
return null;
}
Expand Down Expand Up @@ -158,7 +157,13 @@ default String getSingular() {
}

static String getFullResourceName(Class<?> clazz) {
return getFullResourceName(getPlural(clazz), getGroup(clazz));
final String plural = getPlural(clazz);
final String group = getGroup(clazz);
if (plural == null || group == null) {
throw new IllegalArgumentException(
"Should provide non-null plural and/or group. Is " + clazz.getName() + " properly annotated with @" + Group.NAME + " and/or @" + Version.NAME + "?");
}
return getFullResourceName(plural, group);
}

static String getFullResourceName(String plural, String group) {
Expand All @@ -168,6 +173,7 @@ static String getFullResourceName(String plural, String group) {
}

@JsonIgnore
@SuppressWarnings("unused")
default String getFullResourceName() {
return getFullResourceName(getClass());
}
Expand Down

0 comments on commit a57bde6

Please sign in to comment.