File tree Expand file tree Collapse file tree
api/src/main/java/run/halo/app/extension
main/java/run/halo/app/content/comment Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import io .swagger .v3 .oas .annotations .media .Schema ;
66import java .util .Objects ;
77import lombok .Data ;
8+ import org .jspecify .annotations .Nullable ;
89import org .springframework .lang .NonNull ;
910
1011@ Data
1112@ Schema (description = "Extension reference object. The name is mandatory" )
1213public class Ref {
1314
14- @ Schema (description = "Extension group" )
15+ @ Schema (description = "Extension group" , requiredMode = REQUIRED )
1516 private String group ;
1617
1718 @ Schema (description = "Extension version" )
19+ @ Nullable
1820 private String version ;
1921
20- @ Schema (description = "Extension kind" )
22+ @ Schema (description = "Extension kind" , requiredMode = REQUIRED )
2123 private String kind ;
2224
2325 @ Schema (requiredMode = REQUIRED , description = "Extension name. This field is mandatory" )
Original file line number Diff line number Diff line change 11package run .halo .app .content .comment ;
22
3+ import java .util .Objects ;
34import lombok .RequiredArgsConstructor ;
45import org .springframework .stereotype .Component ;
56import org .springframework .util .Assert ;
67import reactor .core .publisher .Mono ;
78import run .halo .app .core .extension .content .Post ;
8- import run .halo .app .extension .GroupVersionKind ;
99import run .halo .app .extension .ReactiveExtensionClient ;
1010import run .halo .app .extension .Ref ;
1111import run .halo .app .infra .ExternalLinkProcessor ;
@@ -41,8 +41,8 @@ public Mono<SubjectDisplay> getSubjectDisplay(String name) {
4141 @ Override
4242 public boolean supports (Ref ref ) {
4343 Assert .notNull (ref , "Subject ref must not be null." );
44- GroupVersionKind groupVersionKind =
45- new GroupVersionKind ( ref . getGroup (), ref . getVersion (), ref .getKind ());
46- return GroupVersionKind . fromExtension ( Post . class ). equals ( groupVersionKind );
44+ var gvk = Post . GVK ;
45+ return Objects . equals ( gvk . group (), ref .getGroup ())
46+ && Objects . equals ( gvk . kind (), ref . getKind () );
4747 }
4848}
Original file line number Diff line number Diff line change 11package run .halo .app .content .comment ;
22
3+ import java .util .Objects ;
34import lombok .RequiredArgsConstructor ;
45import org .springframework .stereotype .Component ;
56import org .springframework .util .Assert ;
67import reactor .core .publisher .Mono ;
78import run .halo .app .core .extension .content .SinglePage ;
8- import run .halo .app .extension .GroupVersionKind ;
99import run .halo .app .extension .ReactiveExtensionClient ;
1010import run .halo .app .extension .Ref ;
1111import run .halo .app .infra .ExternalLinkProcessor ;
@@ -42,8 +42,8 @@ public Mono<SubjectDisplay> getSubjectDisplay(String name) {
4242 @ Override
4343 public boolean supports (Ref ref ) {
4444 Assert .notNull (ref , "Subject ref must not be null." );
45- GroupVersionKind groupVersionKind =
46- new GroupVersionKind ( ref . getGroup (), ref . getVersion (), ref .getKind ());
47- return GroupVersionKind . fromExtension ( SinglePage . class ). equals ( groupVersionKind );
45+ var gvk = SinglePage . GVK ;
46+ return Objects . equals ( gvk . group (), ref .getGroup ())
47+ && Objects . equals ( gvk . kind (), ref . getKind () );
4848 }
4949}
Original file line number Diff line number Diff line change 11package run .halo .app .content .comment ;
22
33import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .junit .jupiter .api .Assertions .assertTrue ;
45import static org .mockito .ArgumentMatchers .any ;
56import static org .mockito .ArgumentMatchers .eq ;
67import static org .mockito .Mockito .when ;
1314import reactor .core .publisher .Mono ;
1415import reactor .test .StepVerifier ;
1516import run .halo .app .content .TestPost ;
17+ import run .halo .app .core .extension .content .Constant ;
1618import run .halo .app .core .extension .content .Post ;
1719import run .halo .app .extension .FakeExtension ;
1820import run .halo .app .extension .Metadata ;
@@ -64,4 +66,13 @@ void supports() {
6466 supports = postCommentSubject .supports (Ref .of (fakeExtension ));
6567 assertThat (supports ).isFalse ();
6668 }
69+
70+ @ Test
71+ void shouldSupportRefWithoutVersion () {
72+ var ref = new Ref ();
73+ ref .setName ("fake-post" );
74+ ref .setGroup (Constant .GROUP );
75+ ref .setKind (Post .KIND );
76+ assertTrue (postCommentSubject .supports (ref ));
77+ }
6778}
Original file line number Diff line number Diff line change 11package run .halo .app .content .comment ;
22
33import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .junit .jupiter .api .Assertions .assertTrue ;
45import static org .mockito .ArgumentMatchers .any ;
56import static org .mockito .ArgumentMatchers .eq ;
67import static org .mockito .Mockito .times ;
1415import org .mockito .junit .jupiter .MockitoExtension ;
1516import reactor .core .publisher .Mono ;
1617import reactor .test .StepVerifier ;
18+ import run .halo .app .core .extension .content .Constant ;
1719import run .halo .app .core .extension .content .SinglePage ;
1820import run .halo .app .extension .FakeExtension ;
1921import run .halo .app .extension .Metadata ;
@@ -72,4 +74,15 @@ void supports() {
7274 supports = singlePageCommentSubject .supports (Ref .of (fakeExtension ));
7375 assertThat (supports ).isFalse ();
7476 }
77+
78+
79+ @ Test
80+ void shouldSupportRefWithoutVersion () {
81+ var ref = new Ref ();
82+ ref .setName ("fake-post" );
83+ ref .setGroup (Constant .GROUP );
84+ ref .setKind (SinglePage .KIND );
85+ assertTrue (singlePageCommentSubject .supports (ref ));
86+ }
87+
7588}
You can’t perform that action at this time.
0 commit comments