@cleverbrush/server-openapi 0.0.0-beta-20260415061209 → 0.0.0-beta-20260415084919

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +23 -0
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -157,6 +157,29 @@ registry.entries(); // IterableIterator<[name, SchemaBuilder]>
157
157
  registry.isEmpty; // boolean
158
158
  ```
159
159
 
160
+ ## Discriminated Unions
161
+
162
+ When a request body, response, or parameter schema is a **discriminated union** — all branches are objects sharing a required property with unique literal values — the generated spec automatically includes the OpenAPI `discriminator` keyword alongside `anyOf`.
163
+
164
+ If the union branches use `.schemaName()` and are extracted as `$ref` components, the `discriminator` also includes a `mapping` from each literal value to its `$ref` path:
165
+
166
+ ```ts
167
+ const Cat = object({ type: string('cat'), name: string() }).schemaName('Cat');
168
+ const Dog = object({ type: string('dog'), breed: string() }).schemaName('Dog');
169
+ const PetBody = union(Cat).or(Dog);
170
+
171
+ const CreatePet = endpoint.post('/api/pets').body(PetBody);
172
+
173
+ // Generated spec:
174
+ // requestBody.content['application/json'].schema:
175
+ // {
176
+ // anyOf: [{ $ref: '#/components/schemas/Cat' }, { $ref: '#/components/schemas/Dog' }],
177
+ // discriminator: { propertyName: 'type', mapping: { cat: '#/components/schemas/Cat', dog: '#/components/schemas/Dog' } }
178
+ // }
179
+ ```
180
+
181
+ Code generators like openapi-generator and orval use the `discriminator` to produce proper tagged union types.
182
+
160
183
  ## Authentication & Security Schemes
161
184
 
162
185
  Pass the server's `AuthenticationConfig` to automatically generate `securitySchemes` and per-operation `security` arrays:
package/package.json CHANGED
@@ -5,10 +5,10 @@
5
5
  "email": "andrew_zol@cleverbrush.com"
6
6
  },
7
7
  "peerDependencies": {
8
- "@cleverbrush/server": "0.0.0-beta-20260415061209",
9
- "@cleverbrush/schema": "0.0.0-beta-20260415061209",
10
- "@cleverbrush/schema-json": "0.0.0-beta-20260415061209",
11
- "@cleverbrush/auth": "0.0.0-beta-20260415061209"
8
+ "@cleverbrush/server": "0.0.0-beta-20260415084919",
9
+ "@cleverbrush/schema": "0.0.0-beta-20260415084919",
10
+ "@cleverbrush/schema-json": "0.0.0-beta-20260415084919",
11
+ "@cleverbrush/auth": "0.0.0-beta-20260415084919"
12
12
  },
13
13
  "description": "OpenAPI 3.1 spec generation for @cleverbrush/server — automatic endpoint documentation",
14
14
  "files": [
@@ -45,5 +45,5 @@
45
45
  },
46
46
  "type": "module",
47
47
  "types": "./dist/index.d.ts",
48
- "version": "0.0.0-beta-20260415061209"
48
+ "version": "0.0.0-beta-20260415084919"
49
49
  }