Skip to content

Commit d063e9b

Browse files
committed
NPE in DataRestResponseService.findSearchReturnType. Fixes #1004
1 parent 6dd01aa commit d063e9b

File tree

8 files changed

+725
-1
lines changed

8 files changed

+725
-1
lines changed

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/core/DataRestResponseService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ private Type findSearchReturnType(HandlerMethod handlerMethod, MethodResourceMap
168168
if (methodResourceMapping.isPagingResource()) {
169169
returnType = ResolvableType.forClassWithGenerics(PagedModel.class, domainType).getType();
170170
}
171-
else if (Iterable.class.isAssignableFrom(ResolvableType.forType(returnRepoType).getRawClass())) {
171+
else if (ResolvableType.forType(returnRepoType).getRawClass() != null
172+
&& Iterable.class.isAssignableFrom(ResolvableType.forType(returnRepoType).getRawClass())) {
172173
returnType = ResolvableType.forClassWithGenerics(CollectionModel.class, domainType).getType();
173174
}
174175
else if (!ClassUtils.isPrimitiveOrWrapper(domainType)) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package test.org.springdoc.api.app20;
2+
3+
import java.util.Objects;
4+
5+
import javax.persistence.Column;
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.GenerationType;
9+
import javax.persistence.Id;
10+
import javax.persistence.SequenceGenerator;
11+
import javax.persistence.Table;
12+
13+
import org.hibernate.annotations.NaturalId;
14+
15+
@Entity
16+
@Table(name = "bank")
17+
public class Bank implements EntityDefinition {
18+
19+
@Id
20+
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "bnk_seq")
21+
@SequenceGenerator(name = "bnk_seq", sequenceName = "bnk_seq", allocationSize = 1)
22+
private Long id;
23+
24+
@Column(unique = true)
25+
@NaturalId
26+
private String code;
27+
28+
@Column(unique = true, nullable = false)
29+
private String name;
30+
31+
public Long getId() {
32+
return this.id;
33+
}
34+
35+
public String getCode() {
36+
return this.code;
37+
}
38+
39+
private void setCode(String code) {
40+
this.code = code;
41+
}
42+
43+
public String getName() {
44+
return this.name;
45+
}
46+
47+
public void setName(String name) {
48+
this.name = name;
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hash(getCode());
54+
}
55+
56+
@Override
57+
public boolean equals(Object o) {
58+
if (this == o) {
59+
return true;
60+
}
61+
if (!(o instanceof Bank)) {
62+
return false;
63+
}
64+
Bank bank = (Bank) o;
65+
return Objects.equals(getCode(), bank.getCode());
66+
}
67+
68+
@Override
69+
public String toString() {
70+
return "Bank{" +
71+
"id=" + id +
72+
", code='" + code + '\'' +
73+
", name='" + name + '\'' +
74+
'}';
75+
}
76+
77+
@Override
78+
public String getKey() {
79+
return code;
80+
}
81+
82+
@Override
83+
public String getDescription() {
84+
return name;
85+
}
86+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.app20;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
5+
import org.springframework.stereotype.Repository;
6+
7+
@Repository
8+
@RepositoryRestResource(path = "banks")
9+
public interface BankRepository extends JpaRepository<Bank, Long>, CodeLookupRepository<Bank, String> {
10+
// moved to CodeLookupRepository
11+
//Bank findOneByCode(String code);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.app20;
2+
3+
import org.springframework.data.repository.NoRepositoryBean;
4+
import org.springframework.data.repository.query.Param;
5+
6+
@NoRepositoryBean
7+
public interface CodeLookupRepository<EntityT, KeyT> {
8+
EntityT findOneByCode(@Param("code") KeyT code);
9+
10+
Long countByCode(KeyT code);
11+
}
12+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package test.org.springdoc.api.app20;
2+
3+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
4+
import io.swagger.v3.oas.annotations.info.Info;
5+
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
9+
@SpringBootApplication
10+
@OpenAPIDefinition(
11+
info = @Info(
12+
title = "Core API"
13+
)
14+
)
15+
public class DemoApplication {
16+
17+
public static void main(String[] args) {
18+
SpringApplication.run(DemoApplication.class, args);
19+
}
20+
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.app20;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
5+
public interface EntityDefinition {
6+
7+
@JsonIgnore
8+
String getKey();
9+
10+
@JsonIgnore
11+
String getDescription();
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2020 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.app20;
24+
25+
import test.org.springdoc.api.AbstractSpringDocTest;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
29+
public class SpringDocApp20Test extends AbstractSpringDocTest {
30+
31+
@SpringBootApplication
32+
static class SpringDocTestApp {}
33+
}

0 commit comments

Comments
 (0)