Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/dotprompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ schema:
title: string # string, number, and boolean types are defined like this
subtitle?: string # optional fields are marked with a `?`
draft?: boolean, true when in draft state
status?(enum, approval status): [PENDING, APPROVED]
date: string, the date of publication e.g. '2024-04-09' # descriptions follow a comma
tags(array, relevant tags for article): string # arrays are denoted via parentheses
authors(array):
Expand All @@ -89,6 +90,8 @@ interface Article {
subtitle?: string;
/** true when in draft state */
draft?: boolean;
/** approval status */
status?: 'PENDING' | 'APPROVED';
/** the date of publication e.g. '2024-04-09' */
date: string;
/** relevant tags for article */
Expand All @@ -107,7 +110,7 @@ interface Article {
```

Picoschema supports scalar types `string`, `integer`, `number`, and `boolean`. For
objects and arrays, they are denoted by a parenthetical after the field name.
objects, arrays, and enums they are denoted by a parenthetical after the field name.

Objects defined by Picoschema have all properties as required unless denoted optional
by `?`, and do not allow additional properties.
Expand Down
2 changes: 2 additions & 0 deletions js/dotprompt/src/picoschema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ function parsePico(obj: any, path: string[] = []): JSONSchema {
};
} else if (type === 'object') {
schema.properties[propertyName] = parsePico(obj[key], [...path, key]);
} else if (type === 'enum') {
schema.properties[propertyName] = { enum: obj[key] };
} else {
throw new Error(
"Picoschema: parenthetical types must be 'object' or 'array', got: " +
Expand Down
12 changes: 12 additions & 0 deletions js/dotprompt/tests/picoschema_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ describe('picoschema()', () => {
foo: {type: string}`,
want: { type: 'object', properties: { foo: { type: 'string' } } },
},
{
description: 'enum field',
yaml: `schema:
color?(enum, the enum): [RED, BLUE, GREEN]`,
want: {
type: 'object',
properties: {
color: { description: 'the enum', enum: ['RED', 'BLUE', 'GREEN'] },
},
additionalProperties: false,
},
},
];

for (const test of tests) {
Expand Down