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

Commit

Permalink
feat: document deprecated properties in schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jun 1, 2018
1 parent 1d06370 commit 4c235fc
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 30 deletions.
4 changes: 4 additions & 0 deletions src/document/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export const documentProperties = (
: Object.keys(properties)
const isRequired = name => requiredProperties.indexOf(name) !== -1
const typeText = type => (Array.isArray(type) ? type.join(' or ') : type)
const deprecatedMessage = (value: JsonProperty) =>
value.deprecated ? `**deprecated** ${value.deprecated}` : emptyMark

return Object.keys(properties)
.sort()
Expand All @@ -119,6 +121,7 @@ export const documentProperties = (
format: formatToMarkdown(schemas, formats)(value),
enum: enumToMarkdown(value.enum),
description: value.description ? value.description : emptyMark,
deprecated: deprecatedMessage(value),
}
})
}
Expand All @@ -144,6 +147,7 @@ export const documentSchema = (
'format',
'enum',
'description',
'deprecated',
]
const usedHeaders = findUsedColumns(headers, rows)
const table: object[] = [
Expand Down
35 changes: 34 additions & 1 deletion test/document-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,39 @@ test('document deprecated schema', t => {
},
}
const result = json2md(documentObjectSchema(schema))
// console.log(result)
t.snapshot(result)
})

test('document deprecated schema property', t => {
t.plan(1)
const jsonSchema: JsonSchema = {
title: 'testSchema',
type: 'object',
additionalProperties: true,
description: 'This is a test schema',
properties: {
id: {
type: 'string',
},
name: {
type: 'string',
enum: ['joe', 'mary'],
deprecated: 'use property "fullName" instead',
},
},
}
const schema: ObjectSchema = {
version: {
major: 1,
minor: 2,
patch: 3,
},
schema: jsonSchema,
example: {
id: 'abc',
name: 'joe',
},
}
const result = json2md(documentObjectSchema(schema))
t.snapshot(result)
})
90 changes: 61 additions & 29 deletions test/snapshots/document-test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@ The actual snapshot is saved in `document-test.ts.snap`.

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

## document deprecated schema

> Snapshot 1
`### testSchema@1.2.3␊
This is a test schema␊
**deprecated** no longer in use␊
name | type | enum␊
--- | --- | ---␊
`id` | string | ␊
`name` | string | `"joe", "mary"`␊
Example:␊
```json␊
{␊
"id": "abc",␊
"name": "joe"␊
}␊
```␊


## JSON schema object to Markdown

> Snapshot 1
Expand All @@ -55,6 +27,7 @@ Generated by [AVA](https://ava.li).
],
rows: [
{
deprecated: '',
description: '',
enum: '',
format: '',
Expand All @@ -63,6 +36,7 @@ Generated by [AVA](https://ava.li).
type: 'string',
},
{
deprecated: '',
description: '',
enum: '',
format: '',
Expand Down Expand Up @@ -127,12 +101,69 @@ Generated by [AVA](https://ava.li).
my-foo | `/^foo$/`␊
`

## document deprecated schema

> Snapshot 1
`### testSchema@1.2.3␊
This is a test schema␊
**deprecated** no longer in use␊
name | type | enum␊
--- | --- | ---␊
`id` | string | ␊
`name` | string | `"joe", "mary"`␊
Example:␊
```json␊
{␊
"id": "abc",␊
"name": "joe"␊
}␊
```␊
`

## document deprecated schema property

> Snapshot 1
`### testSchema@1.2.3␊
This is a test schema␊
name | type | enum | deprecated␊
--- | --- | --- | ---␊
`id` | string | | ␊
`name` | string | `"joe", "mary"` | **deprecated** use property "fullName" instead␊
This schema allows additional properties.␊
Example:␊
```json␊
{␊
"id": "abc",␊
"name": "joe"␊
}␊
```␊
`

## document properties

> Snapshot 1
[
{
deprecated: '',
description: 'Can only be choice a or b',
enum: '`"A", "B"`',
format: '',
Expand All @@ -141,6 +172,7 @@ Generated by [AVA](https://ava.li).
type: 'string',
},
{
deprecated: '',
description: 'Property foo',
enum: '',
format: '',
Expand Down Expand Up @@ -308,4 +340,4 @@ Generated by [AVA](https://ava.li).
- inner level 1␊
- inner level 2␊
`
`
Binary file modified test/snapshots/document-test.ts.snap
Binary file not shown.

0 comments on commit 4c235fc

Please sign in to comment.