Skip to content

Commit 857dce0

Browse files
committed
extend logging documentation
1 parent 54cfa09 commit 857dce0

5 files changed

Lines changed: 158 additions & 20 deletions

File tree

docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
** xref:mapping/extension.adoc[Extension Mapping]
2828
** xref:mapping/null.adoc[Null Mapping]
2929
** xref:mapping/package-name.adoc[package-name Mapping]
30+
** xref:mapping/logging.adoc[log Mapping lookup]
3031
* xref:gradle.adoc[Gradle Integration]
3132
* xref:links.adoc[Links]
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
= log mapping lookup
2+
3+
It is possible to let a processor log all the mapping lookups. It *may* be useful to understand why a mapping does not work.
4+
5+
If a mapping doesn't work the first step is to check if the processor is applying it or if it ignores it. The mapping logging will report which mappings were selected for an OpenAPI type.
6+
7+
If the processor doesn't select the mapping there may be something wrong with the mapping. Maybe a typo.
8+
9+
In case the processor uses the mapping, but it still doesn't behave as expected it may be a bug.
10+
11+
To control the logging there are two new xref:processor/configuration.adoc#_logging[logging options].
12+
13+
[source,yaml]
14+
----
15+
openapi-processor-mapping: v10
16+
options:
17+
package-name: io.openapiprocessor.generated
18+
19+
map:
20+
# ...
21+
22+
logging:
23+
mapping: true # <1>
24+
mapping-target: stdout #<2>
25+
----
26+
27+
<1> apart from enabling logging of the mapping lookups in the `mapping.yaml` you may want to set the `mapping-target`.
28+
29+
<2> If set to `logger` the mapping lookup gets logged at `info` level to link:https://www.slf4j.org/[slf4j]. If set to `stdout` the mapping lookup gets written directly to `stdout` without slf4j.
30+
31+
Enabling the logging will produce many blocks similar to:
32+
33+
----
34+
looking for any type mapping of name: 'foo2' path: GET '/fooA' type: 'array' A
35+
+ global
36+
- parameters (type)
37+
- name: foo2 => java.util.List<java.lang.String>
38+
- name: bar => io.openapiprocessor.Bar1
39+
- name: param @ io.openapiprocessor.ParamAnnotation
40+
- type: Bar @ io.openapiprocessor.ParamAnnotation
41+
+ parameters (name)
42+
+ name: foo2 => java.util.List<java.lang.String>
43+
- name: bar => io.openapiprocessor.Bar1
44+
- name: param @ io.openapiprocessor.ParamAnnotation
45+
- type: Bar @ io.openapiprocessor.ParamAnnotation
46+
----
47+
48+
It always starts with a `looking for ..` followed by what it is looking for and the OpenAPI name or type to find, related to which path and its type. Then it lists all mappings checked with their location in the mapping file.
49+
50+
In this case it looks for *any* mapping of `foo2`. *any* means that it is looking for any mapping, by testing all mappings by priority. More specific mappings have a higher priority and win.
51+
52+
It did not find a mapping by its type (`array` in this case), but it found a name mapping for `foo2`, indicated by the `+` sign. The mappings that do not match get marked with a `-` sign.
53+
54+
Here is a snippet from the OpenAPI yaml that is processed here. We have an endpoint `fooA` with a query parameter `foo2` of type `array`.
55+
56+
[source,yaml]
57+
----
58+
/fooA:
59+
get:
60+
summary: foo A summary.
61+
description: foo A endpoint
62+
tags: [foo]
63+
parameters:
64+
- in: query
65+
name: foo1
66+
# ...
67+
- in: query
68+
name: foo2
69+
description: parameter foo2
70+
schema:
71+
type: array
72+
items:
73+
type: string
74+
- in: query
75+
name: bar
76+
# ...
77+
responses:
78+
'200':
79+
# ...
80+
----
81+
82+
The example is a small part of the link:https://github.com/openapi-processor/openapi-processor-base/tree/main/openapi-processor-core/src/testInt/resources/tests/map-many[`map many`] integration test.
83+
84+
85+
== maven
86+
87+
Maven can handle both mapping targets. If the `mapping-target` is set to `logger` it is necessary to enable the mapping logger `io.openapiprocessor.core.converter.mapping` to see any output.
88+
89+
For example by running `maven` with:
90+
91+
----
92+
./mvnw compile -Dorg.slf4j.simpleLogger.log.io.openapiprocessor.core.converter.mapping=info
93+
----
94+
95+
If the `mapping-target` is `stdout` the processor output will be written without the usual log level prefix.
96+
97+
98+
=== summary
99+
100+
to enable logging with maven use:
101+
102+
[source,yaml]
103+
----
104+
openapi-processor-mapping: v10
105+
options:
106+
package-name: ...
107+
108+
map:
109+
# ...
110+
111+
logging:
112+
mapping: true
113+
mapping-target: stdout
114+
----
115+
116+
to get the simple output, or
117+
118+
[source,yaml]
119+
----
120+
openapi-processor-mapping: v10
121+
options:
122+
package-name: ...
123+
124+
map:
125+
# ...
126+
127+
logging:
128+
mapping: true
129+
----
130+
131+
to get the log level based output. Remember to enable the logger in this case as described above.
132+
133+
== gradle
134+
135+
Gradle requires the `mapping-target` to be `stdout`. Gradle can only globally enable log levels which is very noisy. The best option to log the mapping lookups is simply to write them to `stdout`.
136+
137+
=== summary
138+
139+
to enable logging with gradle use:
140+
141+
[source,yaml]
142+
----
143+
openapi-processor-mapping: v10
144+
options:
145+
package-name: ...
146+
147+
map:
148+
# ...
149+
150+
logging:
151+
mapping: true
152+
mapping-target: stdout
153+
----

docs/modules/ROOT/pages/mapping/structure.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The mapping file needs the following key on the top-level. Best place is the fir
1515
1616
[source,yaml]
1717
----
18-
openapi-processor-mapping: v9
18+
openapi-processor-mapping: v10
1919
----
2020
====
2121

docs/modules/ROOT/pages/processor/configuration.adoc

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,13 @@ options:
383383

384384
== logging:
385385

386-
This section contains keys to log the mapping lookup. It may be useful to locate mappings that should be used, but are not.
386+
This section contains keys for logging mapping lookups. It may be useful to locate mappings that should be used, but are not.
387387

388388
=== mapping:
389389

390390
**optional** (boolean, `true` or `false`, default is `false`)
391391

392-
enables logging of the mapping lookup.
392+
enables mapping lookups logging.
393393

394394
=== mapping-target:
395395

@@ -399,22 +399,6 @@ with this option it is possible to control the logging target.
399399

400400
If set to `logger` the mapping lookup gets logged at `info` level to link:https://www.slf4j.org/[slf4j]. If set to `stdout` the mapping lookup gets written directly to `stdout` without slf4j.
401401

402-
==== maven
403-
404-
apart from enabling logging of the mapping lookups in the `mapping.yaml` it is necessary to enable the mapping logger with `io.openapiprocessor.core.converter.mapping` to see any output.
405-
406-
For example by running `maven` with:
407-
408-
----
409-
./mvnw -Dorg.slf4j.simpleLogger.log.io.openapiprocessor.core.converter.mapping=info compile -f pom.xml
410-
----
411-
412-
==== gradle
413-
414-
apart from enabling logging of the mapping lookups in the `mapping.yaml` it is necessary to set `mapping-target` to `stdout`.
415-
416-
gradle can only globally enable log levels which is very noisy. The best option to log the mapping lookups is simply write them to stdout.
417-
418402
== compatibility:
419403

420404
This section contains keys to disable breaking changes.

docs/modules/ROOT/partials/links.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
:badge-central: https://img.shields.io/maven-central/v/io.openapiprocessor/openapi-processor-spring?label=Maven%20Central
1717
:oapc-inttests: https://github.com/openapi-processor/openapi-processor-core/tree/master/src/testInt/resources/tests
1818
:json-schema: https://github.com/openapi-processor/openapi-processor-core/blob/master/src/main/resources/mapping/v2/mapping.yaml.json
19-
:json-schema-site: https://openapiprocessor.io/schemas/mapping/mapping-v3.json
19+
:json-schema-site: https://openapiprocessor.io/schemas/mapping/mapping-v10.json
2020

2121
//
2222
// other external links

0 commit comments

Comments
 (0)