Skip to content

Commit c7d8d63

Browse files
committed
update to api changes in core
1 parent 38d057f commit c7d8d63

3 files changed

Lines changed: 42 additions & 50 deletions

File tree

src/main/kotlin/io/openapiprocessor/micronaut/processor/MicronautProcessor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import io.openapiprocessor.core.writer.SourceFormatter
1414
import io.openapiprocessor.core.writer.java.*
1515
import io.openapiprocessor.micronaut.Versions
1616
import io.openapiprocessor.micronaut.writer.java.BeanValidations
17-
import io.openapiprocessor.micronaut.writer.java.MappingAnnotationWriter
17+
import io.openapiprocessor.micronaut.writer.java.MappingAnnotationFactory
1818
import io.openapiprocessor.micronaut.writer.java.ParameterAnnotationWriter
1919
import io.openapiprocessor.micronaut.writer.java.StatusAnnotationWriter
2020
import io.openapiprocessor.test.api.OpenApiProcessorTest
@@ -55,7 +55,7 @@ class MicronautProcessor : OpenApiProcessorTest {
5555
val generatedWriter = GeneratedWriterImpl(generatedInfo, options)
5656
val validationWriter = ValidationWriter(options, generatedWriter)
5757
val beanValidations = BeanValidations(options)
58-
val javaDocWriter = JavaDocWriter(identifier)
58+
val javaDocWriter = JavaDocFactory(identifier)
5959
val formatter = getFormatter(options)
6060

6161
val writer = ApiWriter(
@@ -69,7 +69,7 @@ class MicronautProcessor : OpenApiProcessorTest {
6969
options,
7070
identifier,
7171
StatusAnnotationWriter(annotations),
72-
MappingAnnotationWriter(),
72+
MappingAnnotationFactory(annotations),
7373
ParameterAnnotationWriter(annotations),
7474
beanValidations,
7575
javaDocWriter

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
/*
2-
* Copyright © 2020 https://github.com/openapi-processor/openapi-processor-micronaut
2+
* Copyright 2020 https://github.com/openapi-processor/openapi-processor-micronaut
33
* PDX-License-Identifier: Apache-2.0
44
*/
55

66
package io.openapiprocessor.micronaut.writer.java
77

8-
import io.openapiprocessor.core.writer.java.MappingAnnotationWriter as CoreMappingAnnotationWriter
98
import io.openapiprocessor.core.model.Endpoint
109
import io.openapiprocessor.core.model.EndpointResponse
11-
import io.openapiprocessor.core.support.capitalizeFirstChar
12-
import java.io.Writer
10+
import io.openapiprocessor.micronaut.processor.MicronautFrameworkAnnotations
11+
import io.openapiprocessor.core.writer.java.MappingAnnotationFactory as CoreMappingAnnotationFactory
1312

1413
/**
15-
* micronaut mapping annotation writer
14+
* micronaut mapping annotation factory
1615
*/
17-
class MappingAnnotationWriter: CoreMappingAnnotationWriter {
16+
class MappingAnnotationFactory(private val annotations: MicronautFrameworkAnnotations): 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 {
24-
var mapping = getMappingAnnotation(endpoint)
23+
val annotation = annotations.getAnnotation(endpoint.method)
24+
25+
var mapping = annotation.annotationName
2526
mapping += "("
2627
mapping += "uri = " + quote(endpoint.path)
2728

@@ -51,13 +52,7 @@ class MappingAnnotationWriter: CoreMappingAnnotationWriter {
5152
return mapping
5253
}
5354

54-
55-
private fun getMappingAnnotation(endpoint: Endpoint): String {
56-
return "@${endpoint.method.method.capitalizeFirstChar()}"
57-
}
58-
5955
private fun quote(content: String): String {
6056
return '"' + content + '"'
6157
}
62-
6358
}

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

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2020 https://github.com/openapi-processor/openapi-processor-micronaut
2+
* Copyright 2020 https://github.com/openapi-processor/openapi-processor-micronaut
33
* PDX-License-Identifier: Apache-2.0
44
*/
55

@@ -13,23 +13,22 @@ import io.openapiprocessor.core.model.RequestBody
1313
import io.openapiprocessor.core.model.Response
1414
import io.openapiprocessor.core.model.datatypes.StringDataType
1515
import io.openapiprocessor.core.model.parameters.MultipartParameter
16-
import spock.lang.Ignore
16+
import io.openapiprocessor.micronaut.processor.MicronautFrameworkAnnotations
1717
import spock.lang.Specification
1818

19-
class MappingAnnotationWriterSpec extends Specification {
20-
def writer = new MappingAnnotationWriter()
21-
def target = new StringWriter()
19+
class MappingAnnotationFactorySpec extends Specification {
20+
def factory = new MappingAnnotationFactory(new MicronautFrameworkAnnotations())
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,18 +43,18 @@ 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,
5150
null)
5251
])
5352

5453
when:
55-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
54+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
5655

5756
then:
58-
target.toString () == expected
57+
annotations.first() == expected
5958

6059
where:
6160
contentType | expected
@@ -64,17 +63,17 @@ class MappingAnnotationWriterSpec extends Specification {
6463
}
6564

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

7372
when:
74-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
73+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
7574

7675
then:
77-
target.toString () == expected
76+
annotations.first() == expected
7877

7978
where:
8079
contentType | expected
@@ -83,7 +82,7 @@ class MappingAnnotationWriterSpec extends Specification {
8382
}
8483

8584
void "writes 'consumes' & 'produces' parameters" () {
86-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
85+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
8786
'200' : [
8887
new Response (responseContentType, new StringDataType (), null)
8988
]
@@ -93,18 +92,18 @@ class MappingAnnotationWriterSpec extends Specification {
9392
])
9493

9594
when:
96-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
95+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
9796

9897
then:
99-
target.toString () == expected
98+
annotations.first() == expected
10099

101100
where:
102101
requestContentType | responseContentType | expected
103102
'foo/in' | 'foo/out' | """@Get(uri = "/foo", consumes = {"foo/in"}, produces = {"foo/out"})"""
104103
}
105104

106105
void "writes mapping annotation with multiple result content types" () {
107-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
106+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
108107
'200' : [
109108
new Response ('application/json', new StringDataType (), null)
110109
],
@@ -114,15 +113,14 @@ class MappingAnnotationWriterSpec extends Specification {
114113
])
115114

116115
when:
117-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
116+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
118117

119118
then:
120-
target.toString () == """@Get(uri = "${endpoint.path}", produces = {"${endpoint.responses.'200'.first ().contentType}", "${endpoint.responses.'default'.first ().contentType}"})"""
119+
annotations.first() == """@Get(uri = "${endpoint.path}", produces = {"${endpoint.responses.'200'.first ().contentType}", "${endpoint.responses.'default'.first ().contentType}"})"""
121120
}
122121

123-
@Ignore // todo
124122
void "writes 'consumes' of multipart/form-data" () {
125-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET,
123+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET,
126124
parameters: [
127125
new MultipartParameter ('mp1', new StringDataType(), false, false, null),
128126
new MultipartParameter ('mp2', new StringDataType(), false, false, null)
@@ -133,14 +131,14 @@ class MappingAnnotationWriterSpec extends Specification {
133131
)
134132

135133
when:
136-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
134+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
137135

138136
then:
139-
target.toString () == """@Get(uri = "${endpoint.path}", consumes = {"multipart/form-data"})"""
137+
annotations.first() == """@Get(uri = "${endpoint.path}", consumes = {"multipart/form-data"})"""
140138
}
141139

142140
void "writes unique 'consumes' parameter" () {
143-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
141+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
144142
'204' : [new EmptyResponse ()]
145143
], requestBodies: [
146144
new RequestBody('body', 'foo/in', new StringDataType (), false, false,
@@ -152,14 +150,14 @@ class MappingAnnotationWriterSpec extends Specification {
152150
])
153151

154152
when:
155-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
153+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
156154

157155
then:
158-
target.toString ().contains ('consumes = {"foo/in"}')
156+
annotations.first().contains ('consumes = {"foo/in"}')
159157
}
160158

161159
void "writes unique 'produces' parameters" () {
162-
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
160+
def endpoint = endpoint (path: '/foo', method: HttpMethod.GET, responses: [
163161
'200' : [
164162
new Response ('foo/out', new StringDataType (), null)
165163
],
@@ -175,14 +173,13 @@ class MappingAnnotationWriterSpec extends Specification {
175173
])
176174

177175
when:
178-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
176+
def annotations = factory.create (endpoint, endpoint.endpointResponses.first ())
179177

180178
then:
181-
target.toString ().contains ('produces = {"foo/out"}')
179+
annotations.first().contains ('produces = {"foo/out"}')
182180
}
183181

184-
@Deprecated
185-
private Endpoint createEndpoint (Map properties) {
182+
private Endpoint endpoint(Map properties) {
186183
return new Endpoint(
187184
properties.path as String ?: '',
188185
properties.method as HttpMethod ?: HttpMethod.GET,

0 commit comments

Comments
 (0)