Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
fix: document custom formats by name, not by key
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed May 2, 2018
1 parent d00d132 commit 52d10e0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/document/doc-formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const documentCustomFormats = (formats: CustomFormats) => {
]
const rows = Object.keys(formats).map(name => {
const format = formats[name]
const formatName = format.name
const r = format.detect.toString()
const escaped = escapedCode(r)
const dynamic = 'defaultValue' in format ? checkMark : emptyMark
Expand All @@ -33,7 +34,7 @@ export const documentCustomFormats = (formats: CustomFormats) => {
: emptyMark

return {
name,
name: formatName,
'regular expression': escaped,
dynamic,
default: defaultValue,
Expand Down
3 changes: 2 additions & 1 deletion test/document-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ test('JSON schema object to Markdown', t => {
test('custom formats', t => {
const formats: CustomFormats = {
foo: {
name: 'foo',
// should use name in the documentation
name: 'my-foo',
description: 'example custom format foo',
detect: /^foo$/,
},
Expand Down
72 changes: 36 additions & 36 deletions test/snapshots/document-test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@ The actual snapshot is saved in `document-test.ts.snap`.

Generated by [AVA](https://ava.li).

## document properties

> Snapshot 1
[
{
description: 'Can only be choice a or b',
enum: '`"A", "B"`',
format: '',
name: '`bar`',
required: '',
type: 'string',
},
{
description: 'Property foo',
enum: '',
format: '',
name: '`foo`',
required: '',
type: 'string',
},


## JSON schema object to Markdown

> Snapshot 1
Expand Down Expand Up @@ -70,6 +47,16 @@ Generated by [AVA](https://ava.li).
},
]

## JSON schema with enumeration to Markdown

> Snapshot 1
`name | type | enum␊
--- | --- | ---␊
`id` | string | ␊
`name` | string | `"joe", "mary"`␊
`

## custom formats

> Snapshot 1
Expand All @@ -92,7 +79,7 @@ Generated by [AVA](https://ava.li).
default: '',
dynamic: '',
example: '',
name: 'foo',
name: 'my-foo',
'regular expression': '`/^foo$/`',
},
],
Expand All @@ -109,9 +96,32 @@ Generated by [AVA](https://ava.li).
name | regular expression␊
--- | ---␊
foo | `/^foo$/`␊
my-foo | `/^foo$/`␊
`

## document properties

> Snapshot 1
[
{
description: 'Can only be choice a or b',
enum: '`"A", "B"`',
format: '',
name: '`bar`',
required: '',
type: 'string',
},
{
description: 'Property foo',
enum: '',
format: '',
name: '`foo`',
required: '',
type: 'string',
},
]

## documents just schemas

> Snapshot 1
Expand Down Expand Up @@ -212,14 +222,4 @@ Generated by [AVA](https://ava.li).
- inner level 1␊
- inner level 2␊


## JSON schema with enumeration to Markdown

> Snapshot 1
`name | type | enum␊
--- | --- | ---␊
`id` | string | ␊
`name` | string | `"joe", "mary"`␊
`
`
Binary file modified test/snapshots/document-test.ts.snap
Binary file not shown.

0 comments on commit 52d10e0

Please sign in to comment.