Skip to content

Commit 940f8e5

Browse files
committed
Added tests for #1773
1 parent 6f103bb commit 940f8e5

File tree

9 files changed

+1775
-0
lines changed

9 files changed

+1775
-0
lines changed

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/utils/SpringDocDataRestUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ private void updateResponseSchemaEmbedded(Components components, EntityInfo enti
288288
String newKey = itemsSchema.get$ref() + RESPONSE;
289289
createNewResponseSchema(key, components);
290290
itemsSchema.set$ref(newKey);
291+
updateResponseSchema(key,components.getSchemas().get(key+RESPONSE), components);
291292
}
292293
}
293294
else if (itemsSchema instanceof ComposedSchema) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
24+
package test.org.springdoc.api.app34;
25+
26+
import java.util.Date;
27+
28+
import javax.persistence.Entity;
29+
import javax.persistence.GeneratedValue;
30+
import javax.persistence.GenerationType;
31+
import javax.persistence.Id;
32+
import javax.persistence.ManyToOne;
33+
import javax.persistence.Temporal;
34+
import javax.persistence.TemporalType;
35+
36+
@Entity
37+
public class Account {
38+
39+
@Id
40+
@GeneratedValue(strategy = GenerationType.AUTO) private Long id;
41+
42+
@ManyToOne
43+
private Customer customer;
44+
45+
@Temporal(TemporalType.DATE) private Date expiryDate;
46+
47+
public Long getId() {
48+
return id;
49+
}
50+
51+
public Customer getCustomer() {
52+
return customer;
53+
}
54+
55+
public Date getExpiryDate() {
56+
return expiryDate;
57+
}
58+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
24+
package test.org.springdoc.api.app34;
25+
26+
27+
import java.util.List;
28+
29+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
30+
import io.swagger.v3.oas.annotations.tags.Tag;
31+
32+
import org.springframework.data.repository.CrudRepository;
33+
import org.springframework.data.repository.query.Param;
34+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
35+
36+
/**
37+
* Repository to manage {@link Account} instances.
38+
*
39+
*/
40+
@RepositoryRestResource
41+
@Tag(name = "The account Repository")
42+
@SecurityRequirement(name = "bearer")
43+
public interface AccountRepository extends CrudRepository<Account, Long> {
44+
45+
/**
46+
* Returns all accounts belonging to the given {@link Customer}.
47+
*
48+
* @param customer
49+
* @return
50+
*/
51+
List<Account> findByCustomer(@Param("customer") Customer customer);
52+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package test.org.springdoc.api.app34;
2+
3+
4+
import java.util.Collection;
5+
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.GenerationType;
9+
import javax.persistence.Id;
10+
import javax.persistence.OneToMany;
11+
12+
/**
13+
* @author Oliver Gierke
14+
*/
15+
@Entity
16+
public class Customer {
17+
18+
@Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id;
19+
20+
private String firstname;
21+
private String lastname;
22+
23+
public Long getId() {
24+
return id;
25+
}
26+
27+
public String getFirstname() {
28+
return firstname;
29+
}
30+
31+
public String getLastname() {
32+
return lastname;
33+
}
34+
35+
@OneToMany(mappedBy = "customer")
36+
private Collection<Account> accounts;
37+
38+
public Collection<Account> getAccounts() {
39+
return accounts;
40+
}
41+
42+
public void setAccounts(Collection<Account> accounts) {
43+
this.accounts = accounts;
44+
}
45+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
24+
package test.org.springdoc.api.app34;
25+
26+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
27+
import io.swagger.v3.oas.annotations.tags.Tag;
28+
29+
import org.springframework.data.domain.Page;
30+
import org.springframework.data.domain.Pageable;
31+
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
32+
import org.springframework.data.repository.CrudRepository;
33+
import org.springframework.data.repository.query.Param;
34+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
35+
import org.springframework.data.rest.core.annotation.RestResource;
36+
37+
/**
38+
* Repository to manage {@link Customer} instances.
39+
*
40+
* @author Oliver Gierke
41+
*/
42+
@RepositoryRestResource
43+
@Tag(name = "The customer Repository")
44+
public interface CustomerRepository extends CrudRepository<Customer, Long>, JpaSpecificationExecutor<Customer> {
45+
46+
/**
47+
* Returns a page of {@link Customer}s with the given lastname.
48+
*
49+
* @param lastname
50+
* @param pageable
51+
* @return
52+
*/
53+
@SecurityRequirement(name = "bearer")
54+
Page<Customer> findByLastname(@Param("lastname") String lastname, Pageable pageable);
55+
56+
@Override
57+
@RestResource(exported = false)
58+
void deleteById(Long id);
59+
60+
@Override
61+
@RestResource(exported = false)
62+
void delete(Customer entity);
63+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app34;
20+
21+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
22+
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
23+
import io.swagger.v3.oas.annotations.info.Info;
24+
import io.swagger.v3.oas.annotations.info.License;
25+
import io.swagger.v3.oas.annotations.security.SecurityScheme;
26+
27+
@OpenAPIDefinition(info = @Info(title = "My App", description = "Some long and useful description", version = "v1", license = @License(name = "Apache 2.0", url = "https://www.apache.org/licenses/LICENSE-2.0")))
28+
@SecurityScheme(name = "bearer", type = SecuritySchemeType.HTTP, scheme = "bearer", bearerFormat = "JWT")
29+
public class OpenApiConfig {
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
24+
package test.org.springdoc.api.app34;
25+
26+
import test.org.springdoc.api.AbstractSpringDocTest;
27+
28+
import org.springframework.boot.autoconfigure.SpringBootApplication;
29+
30+
public class SpringDocApp34Test extends AbstractSpringDocTest {
31+
32+
@SpringBootApplication
33+
static class SpringDocTestApp {}
34+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test.org.springdoc.api.app34;
2+
3+
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
6+
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
7+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
8+
9+
@Configuration
10+
public class SpringRestConfiguration implements RepositoryRestConfigurer {
11+
@Override
12+
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
13+
config.exposeIdsFor(Account.class, Customer.class);
14+
}
15+
}

0 commit comments

Comments
 (0)