Skip to content

Commit bbc1a69

Browse files
committed
Merge branch 'master' into 1.0.x
Conflicts: build.gradle gradle.properties
2 parents 8de992c + fadf7a1 commit bbc1a69

File tree

22 files changed

+360
-40
lines changed

22 files changed

+360
-40
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
an [OpenAPI][openapi] interface only & model java code generator for [Spring Boot][springboot].
99

1010

11-
# openapi-processor documentation
11+
# documentation
1212

1313
See [here][oap-docs].
1414

1515

1616
[badge-license]: https://img.shields.io/badge/License-Apache%202.0-blue.svg?labelColor=313A42
17-
[badge-ci]: https://github.com/hauner/openapi-processor-json/workflows/ci/badge.svg
18-
[oap-license]: https://github.com/hauner/openapi-processor-spring/blob/master/LICENSE
19-
[workflow-ci]: https://github.com/hauner/openapi-processor-json/actions?query=workflow%3Aci
20-
[oap-docs]: https://hauner.github.com/openapi-processor/spring/current/index.html
17+
[badge-ci]: https://github.com/openapi-processor/openapi-processor-spring/workflows/ci/badge.svg
18+
[oap-license]: https://github.com/openapi-processor/openapi-processor-spring/blob/master/LICENSE
19+
[workflow-ci]: https://github.com/openapi-processor/openapi-processor-spring/actions?query=workflow%3Aci
20+
[oap-docs]: https://docs.openapiprocessor.io/spring
2121
[openapi]: https://www.openapis.org/
2222
[springboot]: https://spring.io/projects/spring-boot

build.gradle

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ repositories {
5555
}
5656
}
5757

58+
sourceSets {
59+
main {
60+
java {
61+
srcDirs "${buildDir}/version"
62+
}
63+
}
64+
}
65+
66+
compileKotlin.dependsOn "generateVersion"
67+
68+
5869
test {
5970
useJUnitPlatform()
6071
}
@@ -85,14 +96,14 @@ dependencies {
8596
components.all(KotlinPlatformRule)
8697

8798
compileOnly "io.openapiprocessor:openapi-processor-api:$processorApiVersion"
88-
implementation 'io.openapiprocessor:openapi-processor-core:1.0.0'
99+
implementation 'io.openapiprocessor:openapi-processor-core:1.1.0'
89100

90-
implementation 'org.codehaus.groovy:groovy:2.5.12'
101+
implementation 'org.codehaus.groovy:groovy:2.5.13'
91102
implementation 'org.slf4j:slf4j-api:1.7.30'
92103

93104
testImplementation ("io.openapiprocessor:openapi-processor-api:$processorApiVersion")
94105

95-
testImplementation ('io.openapiprocessor:openapi-processor-test:1.0.0') {
106+
testImplementation ('io.openapiprocessor:openapi-processor-test:1.0.1') {
96107
exclude group: 'com.google.guava'
97108
}
98109

@@ -103,10 +114,10 @@ dependencies {
103114
exclude group: 'com.google.guava'
104115
}
105116

106-
testImplementation ('org.spockframework:spock-core:2.0-M2-groovy-2.5') {
117+
testImplementation ('org.spockframework:spock-core:2.0-M3-groovy-2.5') {
107118
exclude group: 'org.codehaus.groovy' // avoid unused groovy packages
108119
}
109-
testImplementation ('org.spockframework:spock-junit4:2.0-M2-groovy-2.5') {
120+
testImplementation ('org.spockframework:spock-junit4:2.0-M3-groovy-2.5') {
110121
exclude group: 'org.codehaus.groovy' // avoid unused groovy packages
111122
}
112123
testImplementation 'net.bytebuddy:byte-buddy:1.10.11'
@@ -156,4 +167,5 @@ dokka {
156167
outputDirectory = "$buildDir/docs/kotlin"
157168
}
158169

170+
apply plugin: VersionPlugin
159171
apply from: "${rootProject.rootDir}/gradle/publishing.gradle"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import org.gradle.api.Action
2+
import org.gradle.api.Plugin
3+
import org.gradle.api.Project
4+
5+
/**
6+
* provides a "generateVersion" task to a create a simple Version.java class:
7+
*
8+
* <pre>{@code
9+
* package io.openapiprocessor.spring;
10+
*
11+
* public class Version {
12+
* public static final String version = "${project.version}";
13+
* }
14+
* }</pre>
15+
*
16+
*
17+
* The io/openapiprocessor/spring/Version.java file is generated to:
18+
*
19+
* $(project.buildDir}/main/java
20+
*
21+
* Add it as a source directory to include it in compilation.
22+
*/
23+
class VersionPlugin implements Plugin<Project> {
24+
25+
void apply(Project project) {
26+
project.afterEvaluate (new Action<Project> () {
27+
28+
@Override
29+
void execute (Project prj) {
30+
prj.tasks.register ('generateVersion', VersionTask , new Action<VersionTask>() {
31+
32+
@Override
33+
void execute (VersionTask task) {
34+
task.targetDir = prj.buildDir
35+
task.version = prj.version
36+
}
37+
38+
})
39+
}
40+
41+
})
42+
}
43+
44+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import org.gradle.api.DefaultTask
2+
import org.gradle.api.tasks.Internal
3+
import org.gradle.api.tasks.OutputDirectory
4+
import org.gradle.api.tasks.TaskAction
5+
6+
import java.nio.file.Files
7+
import java.nio.file.Path
8+
import java.time.Instant
9+
10+
/**
11+
* simple task to create a Version class.
12+
*/
13+
class VersionTask extends DefaultTask {
14+
15+
/**
16+
* Target directory for the generated version class.
17+
*
18+
* Used by gradle for the up-to-date check.
19+
*/
20+
@OutputDirectory
21+
String targetDir
22+
23+
@Internal
24+
String version
25+
26+
/**
27+
* generate the version class.
28+
*/
29+
@TaskAction
30+
void generateVersion () {
31+
def path = Path.of (targetDir, "version", "io", "openapiprocessor", "spring")
32+
Files.createDirectories(path)
33+
34+
def target = path.resolve ("Version.java")
35+
36+
target.text = """\
37+
/*
38+
* DO NOT MODIFY - this file was auto generated by buildSrc/src/main/groovy/VersionPlugin.groovy
39+
*
40+
* ${Instant.now ().toString ()}
41+
*/
42+
43+
package io.openapiprocessor.spring;
44+
45+
public class Version {
46+
public static final String version = "${version}";
47+
}
48+
49+
"""
50+
}
51+
52+
}

docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
** xref:processor/parameter.adoc[Parameter]
88
** xref:processor/requestbody.adoc[Request Body]
99
** xref:processor/response.adoc[Responses]
10+
** xref:processor/deprecated.adoc[Deprecated]
1011
** xref:processor/identifier.adoc[Identifier]
1112
* xref:mapping/index.adoc[Type Mapping]
1213
** xref:mapping/structure.adoc[Type Mapping Structure]

docs/modules/ROOT/pages/index.adoc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ correct code for an endpoint. That way the processor can still be used for all t
8686

8787
- the generated code does not use swagger annotations. There is no need to generate the
8888
documentation from the code when the code originates from the documentation (i.e. an openapi.yaml).
89-
+
90-
NOTE: The generated source code has to be included in a project to compile it. This is easily done
91-
with the xref:gradle::index.adoc[openapi-processor-gradle] plugin. See xref:gradle.adoc[Using Gradle].
9289

93-
- gradle support via xref:gradle::index.adoc[openapi-processor-gradle] plugin (the plugin is
94-
currently the only option to run the processor).
90+
- *maven & gradle support* The plugin docs show how to run a processor and how to add the generated sources to the build.
91+
92+
** xref:maven::index.adoc[openapi-processor-maven] plugin.
93+
** xref:gradle::index.adoc[openapi-processor-gradle] plugin.
9594

9695
== Releases
9796

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
= Deprecated items
2+
3+
OpenAPI allows adding `deprecated: true` at several places. openapi-processor-spring translates them to Java's `@Deprecated` annotation.
4+
5+
6+
== deprecated endpoint
7+
8+
9+
[cols="2*",grid=row,frame=none]
10+
|===
11+
a|OpenAPI
12+
a|Java Code
13+
14+
a|[source,yaml]
15+
----
16+
/foo:
17+
get:
18+
deprecated: true # <1>
19+
----
20+
21+
a|[source,java]
22+
----
23+
@Deprecated // <2>
24+
@GetMapping("/foo")
25+
/*...*/ getFoo();
26+
----
27+
|===
28+
29+
<1> a deprecated endpoint
30+
<2> the generated endpoint method with a `@Deprecated` annotation
31+
32+
== deprecated parameter
33+
34+
35+
[cols="2*",grid=row,frame=none]
36+
|===
37+
a|OpenAPI
38+
a|Java Code
39+
40+
41+
a|[source,yaml]
42+
----
43+
/foo:
44+
get:
45+
parameters:
46+
- name: bar
47+
deprecated: true # <1>
48+
in: query
49+
schema:
50+
type: string
51+
----
52+
a|[source,java]
53+
----
54+
@GetMapping("/foo")
55+
/* ... */ getFoo(@Deprecated String bar); // <2>
56+
----
57+
|===
58+
59+
<1> a deprecated parameter
60+
<2> the generated endpoint method with a `@Deprecated` annotation on the `bar` parameter.
61+
62+
== deprecated schema
63+
64+
[cols="2*",grid=row,frame=none]
65+
|===
66+
a|OpenAPI
67+
a|Java Code
68+
69+
a|[source,yaml]
70+
----
71+
Bar:
72+
type: object
73+
deprecated: true # <1>
74+
properties:
75+
foobar:
76+
type: string
77+
78+
----
79+
80+
a|[source,java]
81+
----
82+
@Deprecated // <2>
83+
public class Bar {
84+
/* ... */
85+
}
86+
87+
----
88+
|===
89+
90+
<1> a deprecated schema
91+
<2> the generated model class with a `@Deprecated` annotation.
92+
93+
== deprecated schema property
94+
95+
[cols="2*",grid=row,frame=none]
96+
|===
97+
a|OpenAPI
98+
a|Java Code
99+
100+
a|[source,yaml]
101+
----
102+
Bar:
103+
type: object
104+
properties:
105+
foobar:
106+
deprecated: true # <1>
107+
type: string
108+
----
109+
110+
a|[source,java]
111+
----
112+
public class Bar {
113+
114+
@Deprecated // <2>
115+
@JsonProperty("foobar")
116+
private String foobar;
117+
118+
@Deprecated // <2>
119+
public String getFoobar() {
120+
return foobar;
121+
}
122+
123+
@Deprecated // <2>
124+
public void setFoobar(String foobar) {
125+
this.foobar = foobar;
126+
}
127+
128+
}
129+
130+
----
131+
|===
132+
133+
<1> a deprecated schema property
134+
<2> the generated model class with `@Deprecated` annotations at the property, getter and setter. (hmm, the annotated property may be a bit too much... )

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
projectVersion=1.0.0.M15
1+
projectVersion=1.0.0.M16-SNAPSHOT
22
projectGroupId=io.openapiprocessor
33

44
projectUrl=http://openapiprocessor.io

src/main/groovy/com/github/hauner/openapi/spring/writer/java/HeaderWriter.groovy

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package com.github.hauner.openapi.spring.writer.java
1818

1919
import com.github.hauner.openapi.core.writer.java.SimpleWriter
20+
import io.openapiprocessor.spring.Version
21+
22+
import java.time.Instant
2023

2124
/**
2225
* Writer for a simple header of the generated interfaces & classes.
@@ -27,8 +30,11 @@ class HeaderWriter implements SimpleWriter {
2730

2831
static String HEADER = """\
2932
/*
30-
* This class is auto generated by https://github.com/hauner/openapi-processor-spring.
31-
* DO NOT EDIT.
33+
* DO NOT MODIFY - this class was auto generated by openapi-processor-spring
34+
*
35+
* ${Version.version}
36+
* ${Instant.now().toString()}
37+
* https://docs.openapiprocessor.io/spring
3238
*/
3339
3440
"""

0 commit comments

Comments
 (0)