-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Schema a discriminated union (#296)
* Make Schema a discriminated union This leverages the type system to better describe the API's requirements for schemas. For example, rather than saying that any schema might have an optional `items` property, we're able to express that `items` is required on array schemas and forbidden on all others. More info on discriminated unions: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions * Update docs.
- Loading branch information
Showing
69 changed files
with
892 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@google/generative-ai": minor | ||
--- | ||
|
||
The schema types are now more specific, using a [discriminated union](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions) based on the 'type' field to more accurately define which fields are allowed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ArraySchema](./generative-ai.arrayschema.md) > [items](./generative-ai.arrayschema.items.md) | ||
|
||
## ArraySchema.items property | ||
|
||
A schema describing the entries in the array. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
items: Schema; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ArraySchema](./generative-ai.arrayschema.md) > [maxItems](./generative-ai.arrayschema.maxitems.md) | ||
|
||
## ArraySchema.maxItems property | ||
|
||
The maximum number of items in the array. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
maxItems?: number; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ArraySchema](./generative-ai.arrayschema.md) | ||
|
||
## ArraySchema interface | ||
|
||
Describes an array, an ordered list of values. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
export interface ArraySchema extends BaseSchema | ||
``` | ||
**Extends:** BaseSchema | ||
## Properties | ||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [items](./generative-ai.arrayschema.items.md) | | [Schema](./generative-ai.schema.md) | A schema describing the entries in the array. | | ||
| [maxItems?](./generative-ai.arrayschema.maxitems.md) | | number | _(Optional)_ The maximum number of items in the array. | | ||
| [minItems?](./generative-ai.arrayschema.minitems.md) | | number | _(Optional)_ The minimum number of items in the array. | | ||
| [type](./generative-ai.arrayschema.type.md) | | typeof [SchemaType.ARRAY](./generative-ai.schematype.md) | | | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ArraySchema](./generative-ai.arrayschema.md) > [minItems](./generative-ai.arrayschema.minitems.md) | ||
|
||
## ArraySchema.minItems property | ||
|
||
The minimum number of items in the array. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
minItems?: number; | ||
``` |
8 changes: 3 additions & 5 deletions
8
...ference/main/generative-ai.schema.enum.md → ...ce/main/generative-ai.arrayschema.type.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [enum](./generative-ai.schema.enum.md) | ||
[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ArraySchema](./generative-ai.arrayschema.md) > [type](./generative-ai.arrayschema.type.md) | ||
|
||
## Schema.enum property | ||
|
||
Optional. The enum of the property. | ||
## ArraySchema.type property | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
enum?: string[]; | ||
type: typeof SchemaType.ARRAY; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [BooleanSchema](./generative-ai.booleanschema.md) | ||
|
||
## BooleanSchema interface | ||
|
||
Describes a boolean, either 'true' or 'false'. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
export interface BooleanSchema extends BaseSchema | ||
``` | ||
**Extends:** BaseSchema | ||
## Properties | ||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [type](./generative-ai.booleanschema.type.md) | | typeof [SchemaType.BOOLEAN](./generative-ai.schematype.md) | | | ||
Oops, something went wrong.