Skip to content

Commit a5d15bf

Browse files
author
bnasslahsen
committed
project review
1 parent 3662e62 commit a5d15bf

25 files changed

+867
-238
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import io.swagger.v3.core.converter.ModelConverters;
2424
import io.swagger.v3.core.util.Json;
25-
import org.springdoc.core.hal.CollectionModelContentConverter;
25+
import org.springdoc.core.converters.CollectionModelContentConverter;
2626

2727
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
2828
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
@@ -40,7 +40,7 @@ private void init(){
4040
if(repositoryRestConfiguration.useHalAsDefaultJsonMediaType()) {
4141
Json.mapper().registerModule(new Jackson2HalModule());
4242
ModelConverters.getInstance()
43-
.addConverter(new CollectionModelContentConverter());
43+
.addConverter(CollectionModelContentConverter.getConverter());
4444
}
4545
}
4646
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.swagger.v3.oas.models.media.StringSchema;
3030
import org.springdoc.core.converters.Pageable;
3131
import org.springdoc.core.customizers.OpenApiCustomiser;
32-
import org.springdoc.core.hal.RepresentationModelLinksOASMixin;
32+
import org.springdoc.core.converters.RepresentationModelLinksOASMixin;
3333

3434
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3535
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

springdoc-openapi-data-rest/src/main/java/org/springdoc/core/hal/CollectionModelContentConverter.java renamed to springdoc-openapi-data-rest/src/main/java/org/springdoc/core/converters/CollectionModelContentConverter.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
package org.springdoc.core.hal;
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 org.springdoc.core.converters;
20+
21+
import java.util.Collection;
22+
import java.util.Iterator;
223

324
import com.fasterxml.jackson.core.JsonGenerator;
425
import com.fasterxml.jackson.databind.SerializerProvider;
@@ -11,16 +32,22 @@
1132
import io.swagger.v3.oas.models.media.Schema;
1233
import io.swagger.v3.oas.models.media.StringSchema;
1334

14-
import java.util.Collection;
15-
import java.util.Iterator;
16-
1735
/**
1836
* Override resolved schema as there is a custom serializer that converts the data to a map before serializing it.
1937
*
2038
* @see org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalResourcesSerializer
2139
* @see org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalResourcesSerializer#serialize(Collection, JsonGenerator, SerializerProvider)
2240
*/
2341
public class CollectionModelContentConverter implements ModelConverter {
42+
43+
private static final CollectionModelContentConverter collectionModelContentConverter = new CollectionModelContentConverter();
44+
45+
private CollectionModelContentConverter() { }
46+
47+
public static CollectionModelContentConverter getConverter() {
48+
return collectionModelContentConverter;
49+
}
50+
2451
@Override
2552
public Schema<?> resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
2653
if (chain.hasNext() && type != null && type.getType() instanceof CollectionType
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 org.springdoc.core.converters;
20+
21+
import io.swagger.v3.oas.annotations.media.Schema;
22+
23+
import org.springframework.hateoas.Links;
24+
import org.springframework.hateoas.mediatype.hal.RepresentationModelMixin;
25+
26+
public abstract class RepresentationModelLinksOASMixin extends RepresentationModelMixin {
27+
@Override
28+
@Schema(ref = "#/components/schemas/Links")
29+
public abstract Links getLinks();
30+
}

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/AbstractSpringDocTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
import java.nio.file.Path;
2424
import java.nio.file.Paths;
2525

26+
import io.swagger.v3.core.converter.ModelConverters;
2627
import nonapi.io.github.classgraph.utils.FileUtils;
28+
import org.junit.jupiter.api.AfterAll;
2729
import org.junit.jupiter.api.Test;
2830
import org.slf4j.Logger;
2931
import org.slf4j.LoggerFactory;
3032
import org.springdoc.core.Constants;
33+
import org.springdoc.core.converters.CollectionModelContentConverter;
3134

3235
import org.springframework.beans.factory.annotation.Autowired;
3336
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -77,4 +80,10 @@ public void testApp() throws Exception {
7780
String expected = new String(fileBytes);
7881
assertEquals(expected, result, true);
7982
}
83+
84+
@AfterAll
85+
public static void afterClass() {
86+
ModelConverters.getInstance().removeConverter(CollectionModelContentConverter.getConverter());
87+
System.clearProperty("spring.hateoas.use-hal-as-default-json-media-type");
88+
}
8089
}

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app2/DatabaseLoader.java renamed to springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app1/DatabaseLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* * limitations under the License.
1616
*
1717
*/
18-
package test.org.springdoc.api.app2;
18+
package test.org.springdoc.api.app1;
1919

2020
import org.springframework.boot.CommandLineRunner;
2121
import org.springframework.context.annotation.Bean;

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app2/Employee.java renamed to springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app1/Employee.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* * limitations under the License.
1616
*
1717
*/
18-
package test.org.springdoc.api.app2;
18+
package test.org.springdoc.api.app1;
1919

2020
import javax.persistence.Entity;
2121
import javax.persistence.GeneratedValue;

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app2/EmployeeController.java renamed to springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app1/EmployeeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* * limitations under the License.
1616
*
1717
*/
18-
package test.org.springdoc.api.app2;
18+
package test.org.springdoc.api.app1;
1919

2020
import java.net.URI;
2121
import java.net.URISyntaxException;

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app2/EmployeeRepository.java renamed to springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app1/EmployeeRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* * limitations under the License.
1616
*
1717
*/
18-
package test.org.springdoc.api.app2;
18+
package test.org.springdoc.api.app1;
1919

2020
import org.springframework.data.repository.CrudRepository;
2121

0 commit comments

Comments
 (0)