Skip to content

Commit fd7a417

Browse files
committed
update to api changes in core
1 parent df3ebed commit fd7a417

File tree

4 files changed

+35
-39
lines changed

4 files changed

+35
-39
lines changed

src/main/kotlin/io/openapiprocessor/spring/processor/SpringProcessor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import io.openapiprocessor.core.writer.SourceFormatter
1313
import io.openapiprocessor.core.writer.java.*
1414
import io.openapiprocessor.spring.Versions
1515
import io.openapiprocessor.spring.writer.java.*
16-
import io.openapiprocessor.spring.writer.java.MappingAnnotationWriter
16+
import io.openapiprocessor.spring.writer.java.MappingAnnotationFactory
1717
import io.openapiprocessor.spring.writer.java.ParameterAnnotationWriter
1818
import io.openapiprocessor.spring.writer.java.StatusAnnotationWriter
1919
import io.openapiprocessor.test.api.OpenApiProcessorTest
@@ -54,7 +54,7 @@ class SpringProcessor : OpenApiProcessorTest {
5454
val generatedWriter = GeneratedWriterImpl(generatedInfo, options)
5555
val validationWriter = ValidationWriter(options, generatedWriter)
5656
val beanValidations = BeanValidationFactory(options)
57-
val javaDocWriter = JavaDocWriter(identifier)
57+
val javaDocWriter = JavaDocFactory(identifier)
5858
val formatter = getFormatter(options)
5959

6060
val writer = ApiWriter(
@@ -68,7 +68,7 @@ class SpringProcessor : OpenApiProcessorTest {
6868
options,
6969
identifier,
7070
StatusAnnotationWriter(annotations),
71-
MappingAnnotationWriter(annotations),
71+
MappingAnnotationFactory(annotations),
7272
ParameterAnnotationWriter(annotations),
7373
beanValidations,
7474
javaDocWriter

src/main/kotlin/io/openapiprocessor/spring/writer/java/MappingAnnotationWriter.kt renamed to src/main/kotlin/io/openapiprocessor/spring/writer/java/MappingAnnotationFactory.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ package io.openapiprocessor.spring.writer.java
88
import io.openapiprocessor.core.model.Endpoint
99
import io.openapiprocessor.core.model.EndpointResponse
1010
import io.openapiprocessor.spring.processor.SpringFrameworkAnnotations
11-
import java.io.Writer
12-
import io.openapiprocessor.core.writer.java.MappingAnnotationWriter as CoreMappingAnnotationWriter
11+
import io.openapiprocessor.core.writer.java.MappingAnnotationFactory as CoreMappingAnnotationFactory
1312

1413
/**
15-
* spring mapping annotation writer
14+
* spring mapping annotation factory
1615
*/
17-
class MappingAnnotationWriter(private val annotations: SpringFrameworkAnnotations): CoreMappingAnnotationWriter {
16+
class MappingAnnotationFactory(private val annotations: SpringFrameworkAnnotations): CoreMappingAnnotationFactory {
1817

19-
override fun write(target: Writer, endpoint: Endpoint, endpointResponse: EndpointResponse) {
20-
target.write(createAnnotation(endpoint, endpointResponse))
18+
override fun create(endpoint: Endpoint, endpointResponse: EndpointResponse): List<String> {
19+
return listOf(createAnnotation(endpoint, endpointResponse))
2120
}
2221

2322
private fun createAnnotation(endpoint: Endpoint, endpointResponse: EndpointResponse): String {

src/test/groovy/io/openapiprocessor/spring/writer/java/MappingAnnotationWriterSpec.groovy renamed to src/test/groovy/io/openapiprocessor/spring/writer/java/MappingAnnotationFactorySpec.groovy

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@ import io.openapiprocessor.core.model.datatypes.StringDataType
1515
import io.openapiprocessor.spring.processor.SpringFrameworkAnnotations
1616
import spock.lang.Specification
1717

18-
class MappingAnnotationWriterSpec extends Specification {
18+
class MappingAnnotationFactorySpec extends Specification {
1919

20-
def writer = new MappingAnnotationWriter(new SpringFrameworkAnnotations())
21-
def target = new StringWriter()
20+
def factory = new MappingAnnotationFactory(new SpringFrameworkAnnotations())
2221

2322
void "writes http method specific mapping annotation" () {
24-
def endpoint = createEndpoint (path: path, method: httpMethod, responses: [
23+
def endpoint = endpoint (path: path, method: httpMethod, responses: [
2524
'204' : [new EmptyResponse ()]
2625
])
2726

2827
when:
29-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
28+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
3029

3130
then:
32-
target.toString () == expected
31+
annotations.first() == expected
3332

3433
where:
3534
httpMethod | path | expected
@@ -44,17 +43,17 @@ class MappingAnnotationWriterSpec extends Specification {
4443
}
4544

4645
void "writes 'consumes' parameter with body content type" () {
47-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
46+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
4847
'204' : [new EmptyResponse()]
4948
], requestBodies: [
5049
new RequestBody('body', contentType, new StringDataType (), false, false, null)
5150
])
5251

5352
when:
54-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
53+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
5554

5655
then:
57-
target.toString () == expected
56+
annotations.first() == expected
5857

5958
where:
6059
contentType | expected
@@ -63,15 +62,15 @@ class MappingAnnotationWriterSpec extends Specification {
6362
}
6463

6564
void "writes 'produces' parameter with response content type" () {
66-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
65+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
6766
'200' : [new Response (contentType, new StringDataType (), null)]
6867
])
6968

7069
when:
71-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
70+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
7271

7372
then:
74-
target.toString () == expected
73+
annotations.first() == expected
7574

7675
where:
7776
contentType | expected
@@ -80,7 +79,7 @@ class MappingAnnotationWriterSpec extends Specification {
8079
}
8180

8281
void "writes 'consumes' & 'produces' parameters" () {
83-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
82+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
8483
'200' : [
8584
new Response (responseContentType, new StringDataType (), null)
8685
]
@@ -90,18 +89,18 @@ class MappingAnnotationWriterSpec extends Specification {
9089
])
9190

9291
when:
93-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
92+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
9493

9594
then:
96-
target.toString () == expected
95+
annotations.first() == expected
9796

9897
where:
9998
requestContentType | responseContentType | expected
10099
'foo/in' | 'foo/out' | """@GetMapping(path = "/foo", consumes = {"foo/in"}, produces = {"foo/out"})"""
101100
}
102101

103102
void "writes mapping annotation with multiple result content types" () {
104-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
103+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
105104
'200' : [
106105
new Response ('application/json', new StringDataType (), null)
107106
],
@@ -111,14 +110,14 @@ class MappingAnnotationWriterSpec extends Specification {
111110
])
112111

113112
when:
114-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
113+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
115114

116115
then:
117-
target.toString () == """@GetMapping(path = "${endpoint.path}", produces = {"${endpoint.responses.'200'.first ().contentType}", "${endpoint.responses.'default'.first ().contentType}"})"""
116+
annotations.first() == """@GetMapping(path = "${endpoint.path}", produces = {"${endpoint.responses.'200'.first ().contentType}", "${endpoint.responses.'default'.first ().contentType}"})"""
118117
}
119118

120119
void "writes unique 'consumes' parameter" () {
121-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
120+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
122121
'204' : [new EmptyResponse ()]
123122
], requestBodies: [
124123
new RequestBody('body', 'foo/in', new StringDataType (), false, false,
@@ -130,14 +129,14 @@ class MappingAnnotationWriterSpec extends Specification {
130129
])
131130

132131
when:
133-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
132+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
134133

135134
then:
136-
target.toString ().contains ('consumes = {"foo/in"}')
135+
annotations.first ().contains ('consumes = {"foo/in"}')
137136
}
138137

139138
void "writes unique 'produces' parameters" () {
140-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
139+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
141140
'200' : [
142141
new Response ('foo/out', new StringDataType (), null)
143142
],
@@ -153,14 +152,13 @@ class MappingAnnotationWriterSpec extends Specification {
153152
])
154153

155154
when:
156-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
155+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
157156

158157
then:
159-
target.toString ().contains ('produces = {"foo/out"}')
158+
annotations.first ().contains ('produces = {"foo/out"}')
160159
}
161160

162-
@Deprecated
163-
private Endpoint createEndpoint (Map properties) {
161+
private Endpoint endpoint(Map properties) {
164162
return new Endpoint(
165163
properties.path as String ?: '',
166164
properties.method as HttpMethod ?: HttpMethod.GET,
@@ -172,5 +170,4 @@ class MappingAnnotationWriterSpec extends Specification {
172170
new Documentation(null, properties.description as String),
173171
)
174172
}
175-
176173
}

src/test/groovy/io/openapiprocessor/spring/writer/java/MethodWriterSpec.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import io.openapiprocessor.core.model.Documentation
2020
import io.openapiprocessor.core.model.datatypes.DataTypeName
2121
import io.openapiprocessor.core.model.datatypes.GenericDataType
2222
import io.openapiprocessor.core.model.datatypes.MappedDataType
23-
import io.openapiprocessor.core.writer.java.JavaDocWriter
23+
import io.openapiprocessor.core.writer.java.JavaDocFactory
2424
import io.openapiprocessor.core.writer.java.JavaIdentifier
2525
import io.openapiprocessor.spring.model.parameters.QueryParameter
2626
import io.openapiprocessor.spring.processor.SpringFrameworkAnnotations
@@ -40,10 +40,10 @@ class MethodWriterSpec extends Specification {
4040
apiOptions,
4141
identifier,
4242
new StatusAnnotationWriter(new SpringFrameworkAnnotations()),
43-
new MappingAnnotationWriter(new SpringFrameworkAnnotations()),
43+
new MappingAnnotationFactory(new SpringFrameworkAnnotations()),
4444
new ParameterAnnotationWriter(new SpringFrameworkAnnotations()),
4545
new BeanValidationFactory (apiOptions),
46-
new JavaDocWriter(identifier))
46+
new JavaDocFactory(identifier))
4747
def target = new StringWriter ()
4848

4949
@Deprecated

0 commit comments

Comments
 (0)