Skip to content

Commit 0009532

Browse files
committed
feat(annotations): changed meaning of 'title' and 'description'
The textual descriptions is now entirely in the 'description' field The title field is a type name descriptor fix #13
1 parent e040baa commit 0009532

File tree

8 files changed

+104
-53
lines changed

8 files changed

+104
-53
lines changed

lib/__snapshots__/batch-convert.spec.ts.snap

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,31 @@ Object {
88
"additionalProperties": false,
99
"properties": Object {
1010
"bar": Object {
11+
"title": "Foo.bar",
1112
"type": "string",
1213
},
1314
"baz": Object {
1415
"anyOf": Array [
1516
Object {
17+
"title": "Foo.baz",
1618
"type": "number",
1719
},
1820
Object {
1921
"$ref": "#/definitions/Foo",
22+
"title": "Foo.baz",
2023
},
2124
],
22-
"description": "@see baz documentation at http://documentation.yada",
23-
"title": "A baz is a number of another Foo",
25+
"description": "A baz is a number of another Foo
26+
27+
@see baz documentation at http://documentation.yada",
28+
"title": "Foo.baz",
2429
},
2530
},
2631
"required": Array [
2732
"bar",
2833
"baz",
2934
],
35+
"title": "Foo",
3036
"type": "object",
3137
},
3238
"Foo2": Object {
@@ -36,12 +42,14 @@ Object {
3642
"items": Object {
3743
"type": "boolean",
3844
},
45+
"title": "Foo2.bak",
3946
"type": "array",
4047
},
4148
},
4249
"required": Array [
4350
"bak",
4451
],
52+
"title": "Foo2",
4553
"type": "object",
4654
},
4755
},
@@ -56,12 +64,14 @@ Object {
5664
"additionalProperties": false,
5765
"properties": Object {
5866
"name": Object {
67+
"title": "SubDirType.name",
5968
"type": "string",
6069
},
6170
},
6271
"required": Array [
6372
"name",
6473
],
74+
"title": "SubDirType",
6575
"type": "object",
6676
},
6777
},
@@ -76,25 +86,31 @@ Object {
7686
"additionalProperties": false,
7787
"properties": Object {
7888
"bar": Object {
89+
"title": "Foo.bar",
7990
"type": "string",
8091
},
8192
"baz": Object {
8293
"anyOf": Array [
8394
Object {
95+
"title": "Foo.baz",
8496
"type": "number",
8597
},
8698
Object {
8799
"$ref": "#/definitions/Foo",
100+
"title": "Foo.baz",
88101
},
89102
],
90-
"description": "@see baz documentation at http://documentation.yada",
91-
"title": "A baz is a number of another Foo",
103+
"description": "A baz is a number of another Foo
104+
105+
@see baz documentation at http://documentation.yada",
106+
"title": "Foo.baz",
92107
},
93108
},
94109
"required": Array [
95110
"bar",
96111
"baz",
97112
],
113+
"title": "Foo",
98114
"type": "object",
99115
},
100116
"Foo2": Object {
@@ -104,12 +120,14 @@ Object {
104120
"items": Object {
105121
"type": "boolean",
106122
},
123+
"title": "Foo2.bak",
107124
"type": "array",
108125
},
109126
},
110127
"required": Array [
111128
"bak",
112129
],
130+
"title": "Foo2",
113131
"type": "object",
114132
},
115133
},
@@ -124,12 +142,14 @@ Object {
124142
"additionalProperties": false,
125143
"properties": Object {
126144
"name": Object {
145+
"title": "SubDirType.name",
127146
"type": "string",
128147
},
129148
},
130149
"required": Array [
131150
"name",
132151
],
152+
"title": "SubDirType",
133153
"type": "object",
134154
},
135155
},
@@ -156,12 +176,14 @@ Object {
156176
"additionalProperties": false,
157177
"properties": Object {
158178
"name": Object {
179+
"title": "SubDirType.name",
159180
"type": "string",
160181
},
161182
},
162183
"required": Array [
163184
"name",
164185
],
186+
"title": "SubDirType",
165187
"type": "object",
166188
},
167189
},
@@ -176,25 +198,31 @@ Object {
176198
"additionalProperties": false,
177199
"properties": Object {
178200
"bar": Object {
201+
"title": "Foo.bar",
179202
"type": "string",
180203
},
181204
"baz": Object {
182205
"anyOf": Array [
183206
Object {
207+
"title": "Foo.baz",
184208
"type": "number",
185209
},
186210
Object {
187211
"$ref": "#/definitions/Foo",
212+
"title": "Foo.baz",
188213
},
189214
],
190-
"description": "@see baz documentation at http://documentation.yada",
191-
"title": "A baz is a number of another Foo",
215+
"description": "A baz is a number of another Foo
216+
217+
@see baz documentation at http://documentation.yada",
218+
"title": "Foo.baz",
192219
},
193220
},
194221
"required": Array [
195222
"bar",
196223
"baz",
197224
],
225+
"title": "Foo",
198226
"type": "object",
199227
},
200228
"Foo2": Object {
@@ -204,12 +232,14 @@ Object {
204232
"items": Object {
205233
"type": "boolean",
206234
},
235+
"title": "Foo2.bak",
207236
"type": "array",
208237
},
209238
},
210239
"required": Array [
211240
"bak",
212241
],
242+
"title": "Foo2",
213243
"type": "object",
214244
},
215245
},

lib/__snapshots__/converter.spec.ts.snap

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ import { suretype, v, compile, annotate } from 'suretype';
2020
/** The validation schema for a Foo */
2121
export const schemaFoo = suretype({
2222
name: \\"Foo\\",
23-
title: \\"The Foo type\\"
23+
title: \\"Foo\\",
24+
description: \\"The Foo type\\"
2425
}, v.object({
2526
int: annotate({
26-
title: \\"This is the integer thing\\",
27-
description: \\"@default 55\\"
27+
title: \\"Foo.int\\",
28+
description: \\"This is the integer thing\\\\n\\\\n@default 55\\"
2829
}, v.number().integer()),
29-
str: v.string().required(),
30+
str: annotate({
31+
title: \\"Foo.str\\"
32+
}, v.string().required()),
3033
stra: annotate({
31-
title: \\"Excellent array of strings\\"
34+
title: \\"Foo.stra\\",
35+
description: \\"Excellent array of strings\\"
3236
}, v.array(v.string()).required())
3337
}));
3438
@@ -83,7 +87,7 @@ paths: {}
8387
components:
8488
schemas:
8589
Foo:
86-
title: This is Foo
90+
description: This is Foo
8791
properties:
8892
gt5:
8993
exclusiveMinimum: 5

lib/convert-graphql.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,31 @@ describe( "convert-graphql", ( ) =>
3131
types: [
3232
{
3333
name: 'Foo',
34-
title: 'Foo type',
34+
title: 'Foo',
35+
description: 'Foo type',
3536
type: 'object',
3637
loc: expect.anything( ),
3738
properties: {
3839
bar: {
3940
node: {
4041
type: 'string',
42+
title: 'Foo.bar',
4143
loc: expect.anything( ),
4244
},
4345
required: true,
4446
},
4547
num: {
4648
node: {
4749
type: 'number',
50+
title: 'Foo.num',
4851
loc: expect.anything( ),
4952
},
5053
required: false,
5154
},
5255
int: {
5356
node: {
5457
type: 'integer',
58+
title: 'Foo.int',
5559
loc: expect.anything( ),
5660
},
5761
required: false,
@@ -81,7 +85,8 @@ describe( "convert-graphql", ( ) =>
8185
types: [
8286
{
8387
name: 'Foo',
84-
title: 'Foo type',
88+
title: 'Foo',
89+
description: 'Foo type',
8590
type: 'object',
8691
properties: {
8792
bar: {

lib/fixtures/validator.st.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { suretype, v } from 'suretype'
22

33
export const myval = suretype(
4-
{ name: 'Foo', title: 'This is Foo' },
4+
{ name: 'Foo', description: 'This is Foo' },
55
v.object( {
66
gt5: v.number( ).gt( 5 ),
77
gte5: v.number( ).gte( 5 ),

lib/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe( "index", ( ) =>
2020
expect( JSON.parse( data ) ).toStrictEqual( {
2121
$comment: expect.anything( ),
2222
definitions: {
23-
Foo: { type: [ 'number', 'string' ] },
23+
Foo: { type: [ 'number', 'string' ], title: 'Foo' },
2424
},
2525
} );
2626
} );
Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`ts-to-openapi ensure descriptions are forwarded 1`] = `
4+
"openapi: 3.0.0
5+
info:
6+
title: My API
7+
version: v1
8+
x-comment: >-
9+
Generated by core-types-json-schema
10+
(https://github.com/grantila/core-types-json-schema) on behalf of typeconv
11+
(https://github.com/grantila/typeconv)
12+
paths: {}
13+
components:
14+
schemas:
15+
Point:
16+
properties:
17+
x:
18+
title: Point.x
19+
description: The distance from the left in mm
20+
type: number
21+
'y':
22+
title: Point.y
23+
description: The distance from the top in mm
24+
type: number
25+
required:
26+
- x
27+
- 'y'
28+
additionalProperties: false
29+
title: Point
30+
type: object
31+
"
32+
`;
33+
334
exports[`ts-to-openapi typescript to openapi 1`] = `
435
"openapi: 3.0.0
536
info:
@@ -15,63 +46,44 @@ components:
1546
Foo:
1647
properties:
1748
a:
49+
title: Foo.a
1850
type: string
1951
b:
52+
title: Foo.b
2053
nullable: true
2154
c:
55+
title: Foo.c
2256
type: number
2357
d:
58+
title: Foo.d
2459
type: boolean
2560
e:
2661
$ref: '#/components/schemas/Thing'
62+
title: Foo.e
2763
required:
2864
- a
2965
- b
3066
- c
3167
- d
3268
- e
3369
additionalProperties: false
70+
title: Foo
3471
type: object
3572
Thing:
3673
properties:
3774
x:
75+
title: Thing.x
3876
enum:
3977
- 6
4078
type: number
4179
'y':
80+
title: Thing.y
4281
type: string
4382
required:
4483
- x
4584
- 'y'
4685
additionalProperties: false
47-
type: object
48-
"
49-
`;
50-
51-
exports[`ts-to-openapi typescript to openapi 2`] = `
52-
"openapi: 3.0.0
53-
info:
54-
title: My API
55-
version: v1
56-
x-comment: >-
57-
Generated by core-types-json-schema
58-
(https://github.com/grantila/core-types-json-schema) on behalf of typeconv
59-
(https://github.com/grantila/typeconv)
60-
paths: {}
61-
components:
62-
schemas:
63-
Point:
64-
properties:
65-
x:
66-
title: The distance from the left in mm
67-
type: number
68-
'y':
69-
title: The distance from the top in mm
70-
type: number
71-
required:
72-
- x
73-
- 'y'
74-
additionalProperties: false
86+
title: Thing
7587
type: object
7688
"
7789
`;

0 commit comments

Comments
 (0)