Skip to content

Commit 36c6b88

Browse files
authored
Merge pull request #107 from openapi-processor/micronaut
resolves #99
2 parents 791cc31 + cdab126 commit 36c6b88

293 files changed

Lines changed: 1983 additions & 18221 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ java {
2020

2121

2222
ext {
23-
processorApiVersion = '1.0.0.M4'
23+
processorApiVersion = '1.1.0.M1'
24+
jacksonVersion = '2.11.0'
2425

2526
bintrayUser = project.hasProperty ('BINTRAY_USER') ? BINTRAY_USER : 'n/a'
2627
bintrayKey = project.hasProperty ('BINTRAY_KEY') ? BINTRAY_KEY : 'n/a'
@@ -34,7 +35,7 @@ repositories {
3435
url "https://oss.sonatype.org/content/repositories/snapshots"
3536
}
3637
maven {
37-
url "https://dl.bintray.com/hauner/openapi-processor"
38+
setUrl("https://dl.bintray.com/openapi-processor/primary")
3839
}
3940
}
4041

@@ -64,33 +65,41 @@ compileKotlin {
6465
}
6566

6667
dependencies {
67-
implementation 'org.codehaus.groovy:groovy:2.5.10'
68-
implementation 'org.codehaus.groovy:groovy-nio:2.5.10'
69-
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
70-
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.10.2'
71-
72-
implementation ('io.swagger.parser.v3:swagger-parser:2.0.19') {
73-
exclude group: 'io.swagger.parser.v3', module: 'swagger-parser-v2-converter'
74-
exclude group: 'io.swagger.core.v3', module: 'swagger-annotations'
68+
components.all(JacksonPlatformRule)
69+
components.all(KotlinPlatformRule)
70+
71+
compileOnly "io.openapiprocessor:openapi-processor-api:$processorApiVersion"
72+
implementation 'io.openapiprocessor:openapi-processor-core:1.0.0.M1'
73+
74+
implementation 'org.codehaus.groovy:groovy:2.5.12'
75+
implementation 'org.slf4j:slf4j-api:1.7.30'
76+
77+
testImplementation ("io.openapiprocessor:openapi-processor-api:$processorApiVersion")
78+
79+
testImplementation ('io.openapiprocessor:openapi-processor-test:1.0.0.M1') {
80+
exclude group: 'com.google.guava'
7581
}
76-
implementation 'org.openapi4j:openapi-parser:0.9'
77-
implementation 'com.google.googlejavaformat:google-java-format:1.7'
78-
compileOnly "com.github.hauner.openapi:openapi-processor-api:$processorApiVersion"
7982

80-
testImplementation 'com.google.jimfs:jimfs:1.1'
83+
testImplementation "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
84+
testImplementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
85+
86+
testImplementation("com.google.jimfs:jimfs:1.1") {
87+
exclude group: 'com.google.guava'
88+
}
89+
8190
testImplementation ('org.spockframework:spock-core:2.0-M2-groovy-2.5') {
82-
exclude group: 'org.codehaus.groovy'
91+
exclude group: 'org.codehaus.groovy' // avoid unused groovy packages
8392
}
8493
testImplementation ('org.spockframework:spock-junit4:2.0-M2-groovy-2.5') {
85-
exclude group: 'org.codehaus.groovy'
94+
exclude group: 'org.codehaus.groovy' // avoid unused groovy packages
8695
}
87-
testImplementation 'net.bytebuddy:byte-buddy:1.10.9'
96+
testImplementation 'net.bytebuddy:byte-buddy:1.10.11'
8897
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
8998

90-
testIntImplementation "com.github.hauner.openapi:openapi-processor-api:$processorApiVersion"
91-
testIntImplementation 'io.github.java-diff-utils:java-diff-utils:4.5'
92-
// testIntRuntimeOnly 'org.slf4j:slf4j-simple:1.7.30'
93-
// testIntRuntimeOnly 'org.slf4j:slf4j-nop:1.6.1'
99+
constraints {
100+
testImplementation ('org.junit.platform:junit-platform-engine:1.6.2')
101+
testImplementation ('junit:junit:4.13')
102+
}
94103
}
95104

96105
tasks.withType(Test) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import org.gradle.api.artifacts.ComponentMetadataRule
2+
import org.gradle.api.artifacts.ComponentMetadataContext
3+
4+
class JacksonPlatformRule implements ComponentMetadataRule {
5+
void execute (ComponentMetadataContext ctx) {
6+
ctx.details.with {
7+
if (id.group.startsWith ("com.fasterxml.jackson")) {
8+
belongsTo ("com.fasterxml.jackson:jackson-bom:${id.version}", false)
9+
}
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import org.gradle.api.artifacts.ComponentMetadataContext
2+
import org.gradle.api.artifacts.ComponentMetadataRule
3+
4+
class KotlinPlatformRule implements ComponentMetadataRule {
5+
void execute (ComponentMetadataContext ctx) {
6+
ctx.details.with {
7+
if (id.group.startsWith ("org.jetbrains.kotlin")) {
8+
belongsTo ("org.jetbrains.kotlin:kotlin-platform:${id.version}")
9+
}
10+
}
11+
}
12+
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

src/main/groovy/com/github/hauner/openapi/spring/model/parameters/MultipartParameter.groovy renamed to src/main/groovy/com/github/hauner/openapi/micronaut/model/parameters/QueryParameter.groovy

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,27 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.github.hauner.openapi.spring.model.parameters
17+
package com.github.hauner.openapi.micronaut.model.parameters
18+
19+
import com.github.hauner.openapi.core.model.datatypes.ObjectDataType
20+
import com.github.hauner.openapi.core.model.parameters.ParameterBase
1821

1922
/**
20-
* OpenAPI multipart request body is passed as {@code @RequestParam}
23+
* OpenAPI query parameter.
2124
*
2225
* @author Martin Hauner
2326
*/
24-
class MultipartParameter extends Parameter {
25-
26-
String getAnnotationName () {
27-
"RequestParam"
28-
}
27+
class QueryParameter extends ParameterBase {
2928

29+
/**
30+
* controls if a parameter should have a {@code @QueryValue} annotation.
31+
*/
3032
boolean withAnnotation () {
31-
true
32-
}
33+
// Pojo's should NOT be annotated
34+
if (dataType instanceof ObjectDataType) {
35+
return false
36+
}
3337

34-
boolean withParameters () {
3538
true
3639
}
3740

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2020 the original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.hauner.openapi.micronaut.processor
18+
19+
import com.github.hauner.openapi.core.framework.FrameworkBase
20+
import com.github.hauner.openapi.core.model.datatypes.DataType
21+
import com.github.hauner.openapi.core.model.parameters.Parameter
22+
import com.github.hauner.openapi.micronaut.model.parameters.QueryParameter
23+
import com.github.hauner.openapi.core.parser.Parameter as ParserParameter
24+
25+
/**
26+
* Micronaut model factory.
27+
*
28+
* @author Martin Hauner
29+
*/
30+
class MicronautFramework extends FrameworkBase {
31+
32+
@Override
33+
Parameter createQueryParameter (ParserParameter parameter, DataType dataType) {
34+
new QueryParameter (
35+
name: parameter.name,
36+
required: parameter.required,
37+
dataType: dataType)
38+
}
39+
40+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2020 the original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.hauner.openapi.micronaut.processor
18+
19+
import com.github.hauner.openapi.core.framework.FrameworkAnnotation
20+
import com.github.hauner.openapi.core.framework.FrameworkAnnotations
21+
import com.github.hauner.openapi.core.model.HttpMethod
22+
import com.github.hauner.openapi.core.model.RequestBody
23+
import com.github.hauner.openapi.core.model.parameters.CookieParameter
24+
import com.github.hauner.openapi.core.model.parameters.HeaderParameter
25+
import com.github.hauner.openapi.core.model.parameters.MultipartParameter
26+
import com.github.hauner.openapi.core.model.parameters.Parameter
27+
import com.github.hauner.openapi.core.model.parameters.PathParameter
28+
import com.github.hauner.openapi.micronaut.model.parameters.QueryParameter
29+
import groovy.util.logging.Slf4j
30+
31+
/**
32+
* provides Micronaut annotation details.
33+
*
34+
* @author Martin Hauner
35+
*/
36+
@Slf4j
37+
class MicronautFrameworkAnnotations implements FrameworkAnnotations {
38+
private static ANNOTATION_PKG = 'io.micronaut.http.annotation'
39+
40+
def MAPPING_ANNOTATIONS = [
41+
(HttpMethod.DELETE) : new FrameworkAnnotation (name: 'Delete', pkg: ANNOTATION_PKG),
42+
(HttpMethod.GET) : new FrameworkAnnotation (name: 'Get', pkg: ANNOTATION_PKG),
43+
(HttpMethod.HEAD) : new FrameworkAnnotation (name: 'Head', pkg: ANNOTATION_PKG),
44+
(HttpMethod.OPTIONS): new FrameworkAnnotation (name: 'Options', pkg: ANNOTATION_PKG),
45+
(HttpMethod.PATCH) : new FrameworkAnnotation (name: 'Patch', pkg: ANNOTATION_PKG),
46+
(HttpMethod.POST) : new FrameworkAnnotation (name: 'Post', pkg: ANNOTATION_PKG),
47+
(HttpMethod.PUT) : new FrameworkAnnotation (name: 'Put', pkg: ANNOTATION_PKG),
48+
(HttpMethod.TRACE) : new FrameworkAnnotation (name: 'Trace', pkg: ANNOTATION_PKG)
49+
]
50+
51+
def PARAMETER_ANNOTATIONS = [
52+
query : new FrameworkAnnotation (name: 'QueryValue', pkg: ANNOTATION_PKG),
53+
header : new FrameworkAnnotation (name: 'Header', pkg: ANNOTATION_PKG),
54+
cookie : new FrameworkAnnotation (name: 'CookieValue', pkg: ANNOTATION_PKG),
55+
path : new FrameworkAnnotation (name: 'PathVariable', pkg: ANNOTATION_PKG),
56+
multipart: new FrameworkAnnotation (name: 'Part', pkg: ANNOTATION_PKG),
57+
body : new FrameworkAnnotation(name: 'Body', pkg: ANNOTATION_PKG)
58+
]
59+
60+
def UNKNOWN_ANNOTATION = new FrameworkAnnotation(name: 'Unknown', pkg: 'fix.me')
61+
62+
@Override
63+
FrameworkAnnotation getAnnotation (HttpMethod httpMethod) {
64+
MAPPING_ANNOTATIONS[httpMethod]
65+
}
66+
67+
@Override
68+
FrameworkAnnotation getAnnotation (Parameter parameter) {
69+
switch (parameter) {
70+
case {it instanceof QueryParameter}:
71+
return PARAMETER_ANNOTATIONS.'query'
72+
case {it instanceof HeaderParameter}:
73+
return PARAMETER_ANNOTATIONS.header
74+
case {it instanceof CookieParameter}:
75+
return PARAMETER_ANNOTATIONS.cookie
76+
case {it instanceof PathParameter}:
77+
return PARAMETER_ANNOTATIONS.path
78+
case {it instanceof MultipartParameter}:
79+
return PARAMETER_ANNOTATIONS.multipart
80+
case {it instanceof RequestBody}:
81+
return PARAMETER_ANNOTATIONS.body
82+
default:
83+
log.error ("unknown parameter type: ${parameter.class.name}")
84+
return UNKNOWN_ANNOTATION
85+
}
86+
}
87+
88+
}

0 commit comments

Comments
 (0)