Skip to content

Commit de02ea8

Browse files
authored
Add documentation about x-codegen (#1326)
1 parent 8cd0e4c commit de02ea8

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

docs/modules/ROOT/pages/server.adoc

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,90 @@ include::./includes/server-getting-started.adoc[leveloffset=+1, opts=optional]
2020
[[codegen-extensions]]
2121
== Codegen Extensions
2222

23-
Apicurio Codegen Extensions use https://swagger.io/docs/specification/v3_0/openapi-extensions/[OpenAPI specification extensions] to allow customization of the generated source code based on your API contract.
23+
Apicurio Codegen Extensions use https://spec.openapis.org/oas/v3.0.3.html#specification-extensions/[OpenAPI specification extensions] to allow customization of the generated source code based on your API contract.
24+
25+
=== `x-codegen`
26+
27+
The `x-codegen` extension can be defined at the root level of the OpenAPI document.
28+
29+
It is applied globally and allows you to customize the generated bean classes by:
30+
- Adding annotations to all generated beans.
31+
- Controlling date/time formatting.
32+
- Configuring the application context root.
33+
34+
=== `x-codegen.bean-annotations`
35+
36+
Adding annotations to generated bean classes:
37+
38+
[source,json]
39+
----
40+
{
41+
"x-codegen": {
42+
"bean-annotations": [
43+
"@lombok.ToString", // (1)
44+
{
45+
"annotation": "@lombok.EqualsAndHashCode", // (2)
46+
"excludeEnums": true
47+
}
48+
]
49+
}
50+
}
51+
----
52+
53+
1. Adds the `@lombok.ToString` annotation to all generated bean classes.
54+
2. Adds the `@lombok.EqualsAndHashCode` annotation to all generated bean classes, except for Java enums (when excludeEnums is set to `true`).
55+
56+
=== `x-codegen.contextRoot`
57+
58+
Additionally, you can configure the application context root using the `x-codegen.contextRoot` property.
59+
60+
This property defines a base path that will be automatically prefixed to all generated JAX-RS resource classes.
61+
62+
For example, if you set the context root to `/apis/studio/v1`, all generated resource paths will include this prefix.
63+
64+
[source,json]
65+
----
66+
{
67+
"x-codegen": {
68+
"contextRoot": "/apis/studio/v1",
69+
"bean-annotations": []
70+
}
71+
}
72+
----
73+
74+
Corresponding JAX-RS code:
75+
76+
[source,java]
77+
----
78+
@Path("/apis/studio/v1/users")
79+
public class UserResource {}
80+
----
81+
82+
[NOTE]
83+
84+
You can use the xref:x-codegen-contextRoot[x-codegen-contextRoot] property to apply a context root prefix to a specific JAX-RS resource instead of using the global one.
85+
86+
=== `x-codegen.suppress-date-time-formatting`
87+
88+
By default, Apicurio Codegen generates properties of type `string` with the format `date-time` as shown below:
89+
90+
[source,java]
91+
----
92+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
93+
@JsonProperty("shipDate")
94+
private Date shipDate;
95+
----
96+
97+
If you want to disable this behavior, you can use the `x-codegen.suppress-date-time-formatting` property to remove the `@JsonFormat` annotation from generated fields.
98+
99+
[source,json]
100+
----
101+
{
102+
"x-codegen": {
103+
"suppress-date-time-formatting": true
104+
}
105+
}
106+
----
24107

25108
The following extensions modify the behavior of the code generation in specific parts of the OpenAPI document.
26109

@@ -211,6 +294,7 @@ public Response deleteBeer(
211294
);
212295
----
213296

297+
[[x-codegen-contextRoot]]
214298
=== x-codegen-contextRoot
215299

216300
The `x-codegen-contextRoot` extension allows you to define a base path (context root) that is prepended to all generated endpoint paths.

0 commit comments

Comments
 (0)