@@ -4,3 +4,100 @@ Typescript types for `kumahq/kuma`.
44
55** Please note: These types are not published to a registry and are used for
66` kumahq/kuma-gui ` only **
7+
8+ ## OpenAPI Overlays
9+
10+ Importantly we make some amends to the upstream Kuma OpenAPI spec to reflect
11+ reality, i.e. upstream kuma uses go protobufs which eventually create
12+ timestamps as date-like, whereas they actually come over in HTTP responses as
13+ strings, enums can be ` string | integer ` but come over in HTTP responses as
14+ strings.
15+
16+ Additionally we provide separate "request schemas" overlaid ontop of the
17+ upstream spec that copy the original response schemas and apply some amends to
18+ make the request objects more correct from an end user perspective for example:
19+
20+ - readOnly properties are removed
21+ - Certain "immutable" properties are marked as readOnly, for example changing a
22+ ` name ` property is essentially a create, therefore the ` name ` property should
23+ be included in these schemas but you shouldn't change it.
24+ - There are a few places where ` enums ` are "informal oneOf"s i.e. you select a
25+ certain type and then have certain properties depending on the ` type ` . We turn
26+ these into proper ` oneOf ` s/discriminated unions.
27+
28+ ## Contributing
29+
30+ Please see ` make help ` , but you probably just want ` make build ` .
31+
32+ ` make types/clean ` will re-clone the upstream schema and regenerate everything
33+ from scratch without cleaning your ` node_modules ` folder.
34+
35+ ### Overview
36+
37+ TL;DR the schemas can be rebuilt using ` make build ` .
38+
39+ Overlays are applied by "filesystem convention" using corresponding ` make `
40+ target that knows about the convention.
41+
42+ ` make build ` splits up the upstream kuma ` openapi.yaml ` into individual
43+ schemas/paths etc in ` ./generated ` .
44+
45+ It then uses these plus several files in ` ./src ` to generate a ` ./dist ` folder
46+ containing individual files for each resource/schema and paths etc.
47+
48+ Finally these are bundled up before a final ` ./openapi.overaly.tmpl.yaml ` is
49+ overlaid onto it producing the final ` ./openapi.yaml ` file from which a
50+ ` index.d.ts ` containing a full set of pure Typescript types is produced.
51+
52+ ### Overlay/source files
53+
54+ Overlay files should mirror the ` ./dist ` folder structure inside ` ./src ` . So if
55+ an overlay file exists in ` ./src/Resource.overlay.yaml ` it will build a
56+ resulting schema in ` ./dist/Resource.yaml ` .
57+
58+ Any non-overlay files in ` ./src ` will just be copied over into ` ./dist ` .
59+
60+ Any newly create schemas (as opposed to overlaid existing ones) will need
61+ adding/referencing in ` ./src/openapi.overlay.yaml `
62+
63+ ` ./dist ` ends up being a copy of ` ./generated ` with any files in ` ./src ` copied
64+ or overlaid on-top of it. The final overlay file in
65+ ` ./openapi.overlay.tmpl.yaml ` adds "global amends" plus adds versioning so we
66+ know what version of kuma the specification was generated from.
67+
68+ #### ` $ref ` s
69+
70+ Standard OpenAPI Overlays do not dereference ` $ref ` s at "overlay-time", i.e. if
71+ you add a ` $ref ` to an overlay it remains a ` $ref ` in the final OpenAPI schema
72+ file.
73+
74+ For "reasons" sometimes we need to dereference ` $ref ` 's at "overlay-time". This
75+ is done by using a non-standard ` !!oas-overlay/dereference ` YAML tag:
76+
77+ ``` yaml
78+ # DOES NOT dereference. This $ref will still be a ref in the resulting schema
79+ $ref : ' ./MeshAccessLogItem.yaml#/properties/spec'
80+
81+ # DOES dereference. This $ref will be deferenced at overlay-time and result in the actual YAML
82+ # structure ending up in the resulting schema
83+ $ref : !!oas-overlay/dereference '../../../generated/components/schemas/MeshAccessLogItem.yaml#/properties/spec'
84+ ` ` `
85+
86+ Note: "overlay-time" ` $ref`s that you wish to dereference should mostly use the
87+ ` generated` source code resolved from the location of the overlay file itself,
88+ whereas non-dereferenced `$ref`s will use the location of the resulting schema
89+ for resolving.
90+
91+
92+ # ### Filesystem Summary
93+
94+ - `./generated` : A full set of schemas split up from the upstream kuma OpenAPI
95+ spec.
96+ - `./src` : Source/overlay files. These are the only files you should be
97+ editing.
98+ - `./dist` : The resulting full set of overlaid schemas, similar to
99+ ` ./generated` but with `./src` applied/overlaid
100+ - `./src/openapi.overlay.yaml` : Acts as a file to include new components/paths.
101+ - `./openapi.overlay.yaml` : Applies "global" amends including version tagging.
102+ - `./openapi.yaml` : The final full OpenAPI spec
103+ - `./index.d.ts` : Types generated from `./openapi.yaml`
0 commit comments