You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/gradle.adoc
+14-28Lines changed: 14 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,9 @@
1
1
= Gradle Plugin
2
2
include::partial$links.adoc[]
3
3
4
-
The xref:gradle::index.adoc[openapi-processor-gradle] is currently the only tool to run any of the
5
-
**openapi-processor**'s.
4
+
The xref:gradle::index.adoc[openapi-processor-gradle] gradle plugin can run any of the **openapi-processor**'s.
6
5
7
-
To use it in a gradle project the gradle file of the project requires a few additional instructions.
8
-
The following sections describe how to activate & configure **openapi-processor-spring** in a
9
-
`build.gradle` file.
6
+
To use it in a Gradle project, the Gradle file of the project requires a few additional instructions. The following sections describe how to activate & configure **openapi-processor-spring** in a `build.gradle` file.
10
7
11
8
12
9
== adding the plugin
@@ -41,33 +38,24 @@ openapiProcessor {
41
38
}
42
39
----
43
40
44
-
* `processor`: (**required**) the processor dependency. This works in the same way as adding a
45
-
dependency to a configuration in the gradle `dependencies` block. It is given here to avoid
46
-
un-wanted side effects on the build dependencies of the project.
41
+
* `processor`: (**required**) the processor dependency. This works in the same way as adding a dependency to a configuration in the gradle `dependencies` block. It is given here to avoid unwanted side effects on the build dependencies of the project.
47
42
48
-
* `apiPath`: (**required**) the path to the `openapi.yaml` file and the main input for the
49
-
processor. If set in the top-level block it will be used for all configured processors.
43
+
* `apiPath`: (**required**) the path to the `openapi.yaml` file and the main input for the processor. If set in the top-level block, it will be used for all configured processors.
50
44
51
-
* `targetDir`: (**required**) the output folder for generating interfaces & models. This is the
52
-
parent of the `packageName` folder tree. It is recommended to set this to a subfolder of gradle's
53
-
standard `build` directory, so it is cleared by the `clean` task and does not pollute the `sources`
45
+
* `targetDir`: (**required**) the output folder for generating interfaces and models. This is the parent of the `packageName` folder tree. It is recommended to set this to a subfolder of gradle's standard `build` directory, so it is cleared by the `clean` task and does not pollute the `sources`
54
46
directory.
55
47
+
56
-
See <<running processor-spring>> how to include the `targetDir` in compilation & packing.
48
+
See <<running processor-spring>> how to include the `targetDir` in compilation and packing.
57
49
58
-
* `mapping`: (**required**) provides the processor mapping options. This is a path
59
-
to yaml file. See xref:processor/configuration.adoc[Configuration] for a description of the mapping
60
-
yaml. This replaces the `typeMappings` option.
50
+
* `mapping`: (**required**) provides the processor mapping options. This is a path to the YAML file. See xref:processor/configuration.adoc[Configuration] for a description of the mapping YAML. This replaces the `typeMappings` option.
61
51
62
-
* `showWarnings`: (**optional**) `true` to show warnings from the open api parser or `false`
63
-
(default) to show no warnings (this option has currently no effect).
52
+
* `showWarnings`: (**optional**) `true` to show warnings from the open api parser or `false` (default) to show no warnings (this option has currently no effect).
64
53
65
-
* `parser`: (**optional**), sets the openapi parser used to read the OpenAPI description. Available values are `SWAGGER` (default), `OPENAPI4J` or `INTERNAL`.
** `OPENAPI4J`: link:{openapi4j}[openapi4j OpenAPI parser, window="_blank"], supports *OpenAPI 3.0.x*. It provides better validation than `SWAGGER`, unfortunately it is no longer maintained.
54
+
* `parser`: (**optional**), sets the openapi parser used to read the OpenAPI description. Available values are `SWAGGER`, `OPENAPI4J` or `INTERNAL` (default).
** `OPENAPI4J`: link:{openapi4j}[openapi4j OpenAPI parser, window="_blank"], supports *OpenAPI 3.0.x*. It provides better validation than `SWAGGER`, unfortunately it is no longer maintained and is deprecated.
58
+
*** the parser provides JSON schema validation.
71
59
72
60
== running processor-spring
73
61
@@ -89,14 +77,12 @@ sourceSets {
89
77
}
90
78
----
91
79
92
-
* and the `compileJava` task gets a dependency on `processSpring`, so it runs before compilation
93
-
(again, assuming a java project):
80
+
* and the `compileJava` task gets a dependency on `processSpring`, so it runs before compilation (again, assuming a java project):
94
81
+
95
82
[source,groovy]
96
83
----
97
84
// generate api before compiling
98
85
compileJava.dependsOn ('processSpring')
99
86
----
100
87
101
-
Adding automatic compilation in this way will also automatically include the generated files into the
102
-
`jar` build artifact.
88
+
Adding automatic compilation in this way will also automatically include the generated files into the `jar` build artifact.
*openapi-processor-spring* is an link:{openapi}[OpenAPI] interface & dto java code generator
18
-
for link:{springboot}[Spring Boot].
17
+
*openapi-processor-spring* is an link:{openapi}[OpenAPI] interface & dto java code generator for link:{springboot}[Spring Boot].
19
18
20
-
It supports an approach where you explicitly define and document your Service API (using OpenAPI)
21
-
with the Interface to the outside and its usage in mind before you implement it. You do not derive
22
-
the API later from the implementation and its implicit design. (of course, adapt as you go...)
19
+
It supports an approach where you explicitly define and document your Service API (using OpenAPI)with the Interface to the outside and its usage in mind before you implement it. You do not derive the API later from the implementation and its implicit design. (of course, adapt as you go...)
23
20
24
21
The advantages are:
25
22
26
-
* you have a single place to maintain the api which makes it easier to create a consistent api
27
-
and keep the overview.
28
-
* it is easy to document in plain text. You can use markdown in the OpenAPI `description`
29
-
properties.
23
+
* you have a single place to maintain the api which makes it easier to create a consistent api and keep the overview.
24
+
* it is easy to document in plain text. You can use Markdown in the OpenAPI `description` properties.
30
25
31
-
The processor generates java interfaces based on the endpoint description of the API and simple POJO classes or records for parameter or response schemas defined in the API. The processor adds all the required spring & jackson annotations to the interface and all that is left to *you* is the implementation of the generated interfaces in any way you like.
26
+
The processor generates java interfaces based on the endpoint description of the API and simple POJO classes or records for parameter or response schemas defined in the API. The processor adds all the required spring & jackson annotations to the interface, and all that is left to *you* is the implementation of the generated interfaces in any way you like.
32
27
33
-
The interfaces will help to keep the implementation in sync with the API. If anything relevant
34
-
changes in the API the interface changes and the compiler will warn that the interface is not
35
-
implemented correctly.
28
+
The interfaces will help to keep the implementation in sync with the API. If anything relevant changes in the API, the interface changes and the compiler will warn that the interface is not implemented correctly.
36
29
37
-
The target programming language is Java so the generated code is usable from most JVM languages.
30
+
The target programming language is Java. Therefore, the generated code is usable from most JVM languages.
38
31
39
32
See the xref:processor/index.adoc[processor intro] for a short example.
40
33
41
34
== Playground
42
35
43
-
openapi-processor has a link:{oap-playground}[playground, window="_blank"] application. You can try
44
-
out some samples, or your own yaml and view the code that the processor generates.
36
+
openapi-processor has a link:{oap-playground}[playground, window="_blank"] application. You can try out some samples or your own YAML and view the code that the processor generates.
45
37
46
38
== Features
47
39
48
40
- generates **only java interfaces and java dto classes** (get/set POJOs or records) for all defined endpoints and schemas to allow full control of the endpoint implementation. It does not generate any other file. See xref:processor/index.adoc[processor].
49
41
50
42
- **powerful type mappings with generic support** to map schemas defined in the openapi.yaml to existing java types.
51
43
+
52
-
For example to map the openapi `array` type to a different java collections or to map paging parameters and results to th Spring types like `Page<>` & `Pageable`.
44
+
For example, to map the openapi `array` type to a different java collection or to map paging parameters and results to th Spring types like `Page<>` & `Pageable`.
53
45
+
54
46
mappings can be defined globally, for a specific response, parameter or endpoint and or http method (of an endpoint). See xref:mapping/index.adoc[type mapping].
55
47
56
-
- Annotationbased **WebFlux support**. Actually there is *no* explicit WebFlux support, but the mapping allows defining a *single*, and a *multi* wrapper class. *single* wraps non-array like result types(e.g. `Mono<>`). *multi* replaces array like result types or parameters with the given multi mapping. For example, it will replace `List<String>` with `Flux<String>` if the multi mapping contains the fully qualified `Flux` type. +
48
+
- Annotation-based **WebFlux support**. Actually, there is *no* explicit WebFlux support, but the mapping allows defining a *single*, and a *multi* wrapper class. *single* wraps non-array like result types(e.g. `Mono<>`). *multi* replaces array like result types or parameters with the given multi mapping. For example, it will replace `List<String>` with `Flux<String>` if the multi mapping contains the fully qualified `Flux` type. +
57
49
//[.badge .badge-since]+since 1.0.0.M13+
58
50
59
51
- generates **human-readable code**.
@@ -73,7 +65,7 @@ correct code for an endpoint. That way the processor can still be used for all t
73
65
//[.badge .badge-since]+since 1.0.0.M11+
74
66
75
67
- the generated code does not use swagger annotations. There is no need to generate the
76
-
documentation from the code when the code originates from the documentation (i.e. an openapi.yaml).
68
+
documentation from the code when the code originates from the documentation (i.e., an openapi.yaml).
77
69
78
70
- *maven & gradle support* The plugin docs show how to run a processor and how to add the generated sources to the build.
79
71
@@ -92,11 +84,9 @@ artifact name is:
92
84
93
85
== Feedback
94
86
95
-
In case some feature is missing, or the generated code is not 100% what you would expect create an
96
-
link:{oaps-issues}[issue]. Preferably with a test case. Providing a test case will help
97
-
significantly :-)
87
+
In case some feature is missing, or the generated code is not 100% what you would expect, create an link:{oaps-issues}[issue]. Preferably with a test case. Providing a test case will help significantly. :-)
98
88
99
-
A _perfect_ test case is a single folder with two sub folders containing the source files, and the expected output files:
89
+
A _perfect_ test case is a single folder with two subfolders containing the source files and the expected output files:
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/mapping/basic.adoc
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,7 @@
1
1
= Basic (primitive) mappings
2
2
include::partial$links.adoc[]
3
3
4
-
The OpenAPI specification defines a couple of basic link:{openapi-spec-types}[data types]. The
5
-
basic data types are built-in into the processor. That means it will map the basic types
6
-
automatically to a corresponding java type. There is no explicit type mapping required.
4
+
The OpenAPI specification defines a couple of basic link:{openapi-spec-types}[data types]. The basic data types are built-in into the processor. That means it will map the basic types automatically to a corresponding java type. There is no explicit type mapping required.
7
5
8
6
The types with no default mapping can be mapped to a java type using the mapping configuration.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/mapping/endpoint.adoc
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,7 @@
2
2
include::partial$links.adoc[]
3
3
include::partial$vars.adoc[]
4
4
5
-
The global mapping variations are also available as explicit endpoint mappings. Instead of adding
6
-
the mapping in the global sections `map/types`, `map/parameters` and `map/responses` they can
7
-
be placed in the `map/paths` section as properties to an endpoint given by its path.
5
+
The global mapping variations are also available as explicit endpoint mappings. Instead of adding the mapping in the global sections `map/types`, `map/parameters` and `map/responses` they can be placed in the `map/paths` section as properties to an endpoint given by its path.
8
6
9
7
[source,yaml]
10
8
----
@@ -16,20 +14,20 @@ map:
16
14
# a path
17
15
/foo:
18
16
19
-
# pathspecific result wrapper
17
+
# path-specific result wrapper
20
18
result: {target type}
21
19
22
-
# pathspecific single wrapper
20
+
# path-specific single wrapper
23
21
single: {target type}
24
22
25
-
# pathspecific multi wrapper
23
+
# path-specific multi wrapper
26
24
multi: {target type}
27
25
28
-
# list of pathspecific mappings
26
+
# list of path-specific mappings
29
27
types:
30
28
- from: {source type} => {target type}
31
29
32
-
# list of pathspecific parameter mappings, mapped by parameter name
30
+
# list of path-specific parameter mappings, mapped by parameter name
33
31
parameters:
34
32
- name: {parameter name} => {target type}
35
33
@@ -39,7 +37,7 @@ map:
39
37
# add an extra annotation to parameters of type source type
40
38
- type: {source type} @ {annotation type}
41
39
42
-
# list of pathspecific content mappings, mapped by content type
40
+
# list of path-specific content mappings, mapped by content type
43
41
responses:
44
42
- content: {content type} => {target type}
45
43
@@ -48,30 +46,30 @@ map:
48
46
# excluding an endpoint
49
47
exclude: true
50
48
51
-
# pathspecific result wrapper
49
+
# path-specific result wrapper
52
50
result: {target type}
53
51
54
-
# pathspecific single wrapper
52
+
# path-specific single wrapper
55
53
single: {target type}
56
54
57
-
# pathspecific multi wrapper
55
+
# path-specific multi wrapper
58
56
multi: {target type}
59
57
60
-
# list of pathspecific mappings
58
+
# list of path-specific mappings
61
59
types:
62
60
- from: {source type} => {target type}
63
61
64
-
# list of pathspecific parameter mappings, mapped by parameter name
62
+
# list of path-specific parameter mappings, mapped by parameter name
65
63
parameters:
66
64
- name: {parameter name} => {target type}
67
65
68
-
# add a (usually technical) parameter that is not described in the OpenAPI
66
+
# add a (usually technical) parameter not described in the OpenAPI
69
67
- add: {parameter name} => {target type}
70
68
71
69
# add an extra annotation to parameters of type source type
72
70
- type: {source type} @ {annotation type}
73
71
74
-
# list of pathspecific content mappings, mapped by content type
72
+
# list of path-specific content mappings, mapped by content type
75
73
responses:
76
74
- content: {content type} => {target type}
77
75
----
@@ -81,7 +79,7 @@ have any effect on other endpoints.
81
79
82
80
== Endpoint mappings by http method
83
81
84
-
It is possible to add mappings that apply only to a specific http method. Motivation for this is limiting the mapping only to the place where it is needed. Http method mappings have priority over other mappings. In general, the most specific mapping is used.
82
+
It is possible to add mappings that apply only to a specific http method. The motivation for this is limiting the mapping only to the place where it is necessary. Http method mappings have priority over other mappings. In general, the most specific mapping is used.
85
83
86
84
Here are a few examples of possible http endpoint mappings:
0 commit comments