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
docs(extensions): don't use <details> blocks in <table>
This is significantly hard to author, and makes it harder to read as
rendered Markdown, too, so let's expand these out.
We can retain the table view as a quick reference.
As well as the core OpenAPI support, we also support the following OpenAPI extensions, as denoted by the [OpenAPI Specification Extensions](https://spec.openapis.org/oas/v3.0.3#specification-extensions).
2254
2254
2255
+
The following extensions are supported:
2256
+
2255
2257
<table>
2256
2258
2257
2259
<tr>
@@ -2261,9 +2263,6 @@ Extension
2261
2263
<th>
2262
2264
Description
2263
2265
</th>
2264
-
<th>
2265
-
Example usage
2266
-
</th>
2267
2266
</tr>
2268
2267
2269
2268
<tr>
@@ -2276,8 +2275,122 @@ Example usage
2276
2275
<td>
2277
2276
Override the generated type definition (and optionally, add an import from another package)
2278
2277
</td>
2278
+
</tr>
2279
+
2280
+
<tr>
2279
2281
<td>
2280
-
<details>
2282
+
2283
+
`x-go-type-skip-optional-pointer`
2284
+
2285
+
</td>
2286
+
<td>
2287
+
Do not add a pointer type for optional fields in structs
2288
+
</td>
2289
+
</tr>
2290
+
2291
+
<tr>
2292
+
<td>
2293
+
2294
+
`x-go-name`
2295
+
2296
+
</td>
2297
+
<td>
2298
+
Override the generated name of a field or a type
2299
+
</td>
2300
+
</tr>
2301
+
2302
+
<tr>
2303
+
<td>
2304
+
2305
+
`x-go-type-name`
2306
+
2307
+
</td>
2308
+
<td>
2309
+
Override the generated name of a type
2310
+
</td>
2311
+
</tr>
2312
+
2313
+
<tr>
2314
+
<td>
2315
+
2316
+
`x-omitempty`
2317
+
2318
+
</td>
2319
+
<td>
2320
+
Force the presence of the JSON tag `omitempty` on a field
2321
+
</td>
2322
+
</tr>
2323
+
2324
+
<tr>
2325
+
<td>
2326
+
2327
+
`x-go-json-ignore`
2328
+
2329
+
</td>
2330
+
<td>
2331
+
When (un)marshaling JSON, ignore field(s)
2332
+
</td>
2333
+
</tr>
2334
+
2335
+
<tr>
2336
+
<td>
2337
+
2338
+
`x-oapi-codegen-extra-tags`
2339
+
2340
+
</td>
2341
+
<td>
2342
+
Generate arbitrary struct tags to fields
2343
+
</td>
2344
+
</tr>
2345
+
2346
+
<tr>
2347
+
<td>
2348
+
2349
+
`x-enum-varnames` / `x-enumNames`
2350
+
2351
+
</td>
2352
+
<td>
2353
+
Override generated variable names for enum constants
2354
+
</td>
2355
+
</tr>
2356
+
2357
+
<tr>
2358
+
<td>
2359
+
2360
+
`x-deprecated-reason`
2361
+
2362
+
</td>
2363
+
<td>
2364
+
Add a GoDoc deprecation warning to a type
2365
+
</td>
2366
+
</tr>
2367
+
2368
+
<tr>
2369
+
<td>
2370
+
2371
+
`x-order`
2372
+
2373
+
</td>
2374
+
<td>
2375
+
Explicitly order struct fields
2376
+
</td>
2377
+
</tr>
2378
+
2379
+
<tr>
2380
+
<td>
2381
+
2382
+
`x-oapi-codegen-only-honour-go-name`
2383
+
2384
+
</td>
2385
+
<td>
2386
+
Only honour the `x-go-name` when generating field names
2387
+
</td>
2388
+
</tr>
2389
+
2390
+
</table>
2391
+
2392
+
2393
+
### `x-go-type` / `x-go-type-import` - override the generated type definition (and optionally, add an import from another package)
2281
2394
2282
2395
Using the `x-go-type` (and optionally, `x-go-type-import` when you need to import another package) allows overriding the type that `oapi-codegen` determined the generated type should be.
2283
2396
@@ -2336,21 +2449,7 @@ type ClientWithExtension struct {
2336
2449
2337
2450
You can see this in more detail in [the example code](examples/extensions/xgotype/).
2338
2451
2339
-
</details>
2340
-
</td>
2341
-
</tr>
2342
-
2343
-
<tr>
2344
-
<td>
2345
-
2346
-
`x-go-type-skip-optional-pointer`
2347
-
2348
-
</td>
2349
-
<td>
2350
-
Do not add a pointer type for optional fields in structs
2351
-
</td>
2352
-
<td>
2353
-
<details>
2452
+
### `x-go-type-skip-optional-pointer` - do not add a pointer type for optional fields in structs
2354
2453
2355
2454
> [!TIP]
2356
2455
> If you prefer this behaviour, and prefer to not have to annotate your whole OpenAPI spec for this behaviour, you can use `output-options.prefer-skip-optional-pointer=true` to default this behaviour for all fields.
@@ -2405,21 +2504,7 @@ type ClientWithExtension struct {
2405
2504
2406
2505
You can see this in more detail in [the example code](examples/extensions/xgotypeskipoptionalpointer/).
2407
2506
2408
-
</details>
2409
-
</td>
2410
-
</tr>
2411
-
2412
-
<tr>
2413
-
<td>
2414
-
2415
-
`x-go-name`
2416
-
2417
-
</td>
2418
-
<td>
2419
-
Override the generated name of a field or a type
2420
-
</td>
2421
-
<td>
2422
-
<details>
2507
+
### `x-go-name` - override the generated name of a field or a type
2423
2508
2424
2509
By default, `oapi-codegen` will attempt to generate the name of fields and types in as best a way it can.
2425
2510
@@ -2476,21 +2561,7 @@ type ClientRenamedByExtension struct {
2476
2561
2477
2562
You can see this in more detail in [the example code](examples/extensions/xgoname/).
2478
2563
2479
-
</details>
2480
-
</td>
2481
-
</tr>
2482
-
2483
-
<tr>
2484
-
<td>
2485
-
2486
-
`x-go-type-name`
2487
-
2488
-
</td>
2489
-
<td>
2490
-
Override the generated name of a type
2491
-
</td>
2492
-
<td>
2493
-
<details>
2564
+
### `x-go-type-name` - Override the generated name of a type
2494
2565
2495
2566
> [!NOTE]
2496
2567
> Notice that this is subtly different to the `x-go-name`, which also applies to _fields_ within `struct`s.
@@ -2552,21 +2623,7 @@ type ClientRenamedByExtension struct {
2552
2623
2553
2624
You can see this in more detail in [the example code](examples/extensions/xgotypename/).
2554
2625
2555
-
</details>
2556
-
</td>
2557
-
</tr>
2558
-
2559
-
<tr>
2560
-
<td>
2561
-
2562
-
`x-omitempty`
2563
-
2564
-
</td>
2565
-
<td>
2566
-
Force the presence of the JSON tag `omitempty` on a field
2567
-
</td>
2568
-
<td>
2569
-
<details>
2626
+
### `x-omitempty` - force the presence of the JSON tag `omitempty` on a field
2570
2627
2571
2628
In a case that you may want to add the JSON struct tag `omitempty` to types that don't have one generated by default - for instance a required field - you can use the `x-omitempty` extension.
2572
2629
@@ -2621,21 +2678,7 @@ Notice that the `ComplexField` is still generated in full, but the type will the
2621
2678
2622
2679
You can see this in more detail in [the example code](examples/extensions/xgojsonignore/).
2623
2680
2624
-
</details>
2625
-
</td>
2626
-
</tr>
2627
-
2628
-
<tr>
2629
-
<td>
2630
-
2631
-
`x-go-json-ignore`
2632
-
2633
-
</td>
2634
-
<td>
2635
-
When (un)marshaling JSON, ignore field(s)
2636
-
</td>
2637
-
<td>
2638
-
<details>
2681
+
### `x-go-json-ignore` - when (un)marshaling JSON, ignore field(s)
2639
2682
2640
2683
By default, `oapi-codegen` will generate `json:"..."` struct tags for all fields in a struct, so JSON (un)marshaling works.
2641
2684
@@ -2709,21 +2752,7 @@ Notice that the `ComplexField` is still generated in full, but the type will the
2709
2752
2710
2753
You can see this in more detail in [the example code](examples/extensions/xgojsonignore/).
2711
2754
2712
-
</details>
2713
-
</td>
2714
-
</tr>
2715
-
2716
-
<tr>
2717
-
<td>
2718
-
2719
-
`x-oapi-codegen-extra-tags`
2720
-
2721
-
</td>
2722
-
<td>
2723
-
Generate arbitrary struct tags to fields
2724
-
</td>
2725
-
<td>
2726
-
<details>
2755
+
### `x-oapi-codegen-extra-tags` - generate arbitrary struct tags to fields
2727
2756
2728
2757
If you're making use of a field's struct tags to i.e. apply validation, decide whether something should be logged, etc, you can use `x-oapi-codegen-extra-tags` to set additional tags for your generated types.
2729
2758
@@ -2780,21 +2809,7 @@ type ClientWithExtension struct {
2780
2809
2781
2810
You can see this in more detail in [the example code](examples/extensions/xoapicodegenextratags/).
2782
2811
2783
-
</details>
2784
-
</td>
2785
-
</tr>
2786
-
2787
-
<tr>
2788
-
<td>
2789
-
2790
-
`x-enum-varnames` / `x-enumNames`
2791
-
2792
-
</td>
2793
-
<td>
2794
-
Override generated variable names for enum constants
When consuming an enum value from an external system, the name may not produce a nice variable name. Using the `x-enum-varnames` extension allows overriding the name of the generated variable names.
2800
2815
@@ -2863,21 +2878,7 @@ type ClientTypeWithVarNamesExtension string
2863
2878
2864
2879
You can see this in more detail in [the example code](examples/extensions/xenumnames/).
2865
2880
2866
-
</details>
2867
-
</td>
2868
-
</tr>
2869
-
2870
-
<tr>
2871
-
<td>
2872
-
2873
-
`x-deprecated-reason`
2874
-
2875
-
</td>
2876
-
<td>
2877
-
Add a GoDoc deprecation warning to a type
2878
-
</td>
2879
-
<td>
2880
-
<details>
2881
+
### `x-deprecated-reason` - add a GoDoc deprecation warning to a type
2881
2882
2882
2883
When an OpenAPI type is deprecated, a deprecation warning can be added in the GoDoc using `x-deprecated-reason`.
2883
2884
@@ -2935,21 +2936,7 @@ Notice that because we've not set `deprecated: true` to the `name` field, it doe
2935
2936
2936
2937
You can see this in more detail in [the example code](examples/extensions/xdeprecatedreason/).
2937
2938
2938
-
</details>
2939
-
</td>
2940
-
</tr>
2941
-
2942
-
<tr>
2943
-
<td>
2944
-
2945
-
`x-order`
2946
-
2947
-
</td>
2948
-
<td>
2949
-
Explicitly order struct fields
2950
-
</td>
2951
-
<td>
2952
-
<details>
2939
+
### `x-order` - explicitly order struct fields
2953
2940
2954
2941
Whether you like certain fields being ordered before others, or you want to perform more efficient packing of your structs, the `x-order` extension is here for you.
2955
2942
@@ -3006,21 +2993,8 @@ type ClientWithExtension struct {
3006
2993
3007
2994
You can see this in more detail in [the example code](examples/extensions/xorder/).
3008
2995
3009
-
</details>
3010
-
</td>
3011
-
</tr>
3012
-
3013
-
<tr>
3014
-
<td>
2996
+
### `x-oapi-codegen-only-honour-go-name` - only honour the `x-go-name` when generating field names
3015
2997
3016
-
`x-oapi-codegen-only-honour-go-name`
3017
-
3018
-
</td>
3019
-
<td>
3020
-
Only honour the `x-go-name` when generating field names
3021
-
</td>
3022
-
<td>
3023
-
<details>
3024
2998
3025
2999
> [!WARNING]
3026
3000
> Using this option may lead to cases where `oapi-codegen`'s rewriting of field names to prevent clashes with other types, or to prevent including characters that may not be valid Go field names.
@@ -3064,12 +3038,6 @@ type TypeWithUnexportedField struct {
3064
3038
3065
3039
You can see this in more detail in [the example code](examples/extensions/xoapicodegenonlyhonourgoname).
3066
3040
3067
-
</details>
3068
-
</td>
3069
-
</tr>
3070
-
3071
-
</table>
3072
-
3073
3041
## Request/response validation middleware
3074
3042
3075
3043
The generated code that `oapi-codegen` produces has some validation for some incoming data, such as checking for required headers, and when using the [strict server](#strict-server) you get some more validation around the correct usage of the response types.
0 commit comments