Skip to content

Commit d81e522

Browse files
authored
752 in schema diagram and documentation view use smarter type descriptions (#753)
* show names for enums with title as type descriptions * show name of array item node as type description in parent attribute list * apply formatting changes * remove PR from triggers of npm test --------- Co-authored-by: Logende <[email protected]>
1 parent 66eed9d commit d81e522

9 files changed

Lines changed: 148 additions & 27 deletions

File tree

.github/workflows/npm-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Node.js CI
22

3-
on: [push, workflow_dispatch, pull_request]
3+
on: [push, workflow_dispatch]
44

55
jobs:
66
build:

meta_configurator/src/schema/graph-representation/__tests__/schemaGraphConstructorArrays.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ describe('test schema graph constructor with objects and attributes, without adv
175175
expect(attrPropArraySimple.typeDescription).toEqual('boolean[]');
176176

177177
const attrPropArrayComplex = rootNode.attributes[1];
178-
// array to inlined object. Because object has no custom title, we refer to it as just object
179-
expect(attrPropArrayComplex.typeDescription).toEqual('object[]');
178+
// array to inlined object.
179+
expect(attrPropArrayComplex.typeDescription).toEqual('propertyArrayToComplex entry[]');
180180

181181
const attrPropArrayRefSimple = rootNode.attributes[2];
182182
// array to ref of simple type

meta_configurator/src/schema/graph-representation/schemaGraphConstructor.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type {JsonSchemaObjectType, JsonSchemaType, TopLevelSchema} from '@/schema/jsonSchemaType';
22
import type {Path} from '@/utility/path';
3-
import {getTypeDescription, isSubSchemaDefinedInDefinitions} from '@/schema/schemaReadingUtils';
3+
import {
4+
doesSchemaHaveType,
5+
getTypeDescription,
6+
isSubSchemaDefinedInDefinitions,
7+
} from '@/schema/schemaReadingUtils';
48
import {jsonPointerToPath, pathToString} from '@/utility/pathUtils';
59
import {useSettings} from '@/settings/useSettings';
610
import {mergeAllOfs} from '@/schema/mergeAllOfs';
@@ -369,11 +373,19 @@ export function generateAttributeTypeDescription(
369373
if (arrayItemObject) {
370374
if (arrayItemObject.schema.title) {
371375
typeDescription = arrayItemObject.title + '[]';
376+
} else if (
377+
doesSchemaHaveType(arrayItemObject.schema, 'object', true) ||
378+
doesSchemaHaveType(arrayItemObject.schema, 'array', true)
379+
) {
380+
// if the array item is of type object or array, use the fallback display name
381+
typeDescription = arrayItemObject.fallbackDisplayName + '[]';
372382
} else {
383+
// otherwise, use the type description of the array item
373384
typeDescription = getTypeDescription(arrayItemObject.schema) + '[]';
374385
}
375386
} else {
376387
if (isObjectSchema(schema.items)) {
388+
// if there is no corresponding node for the array item, use the type description of the items
377389
typeDescription = getTypeDescription(schema.items as JsonSchemaObjectType) + '[]';
378390
}
379391
}
@@ -392,6 +404,14 @@ export function generateAttributeTypeDescription(
392404
}
393405
}
394406

407+
// if data type is an enum, overwrite with title of the enum if existing
408+
// else, leave the type description as is
409+
if (isEnumSchema(schema)) {
410+
if (schema.title && schema.title.length > 0) {
411+
typeDescription = schema.title;
412+
}
413+
}
414+
395415
return typeDescription;
396416
}
397417

meta_configurator/src/utility/documentation/__tests__/samples/arrays.expected.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
- [nestedArraysAndObjectsProperty entry](#%2Fproperties%2FnestedArraysAndObjectsProperty%2Fitems)
77

88
---
9-
### <a id="root"></a>[My Schema](#root)
9+
### [My Schema](#root)
1010
#### Properties
1111

1212
| Name | Type | Required | Description |
1313
|------|------|------|------|
14-
| <a id="%2Fproperties%2FnumberArrayProperty%2Fitems"></a>numberArrayProperty | number\[\] | <span style="color:salmon">false</span> | \- |
15-
| objectArrayProperty | <u>[object\[\]](#%2Fproperties%2FobjectArrayProperty%2Fitems)</u> | <span style="color:salmon">false</span> | \- |
16-
| <a id="%2Fproperties%2FnestedArraysProperty%2Fitems%2Fitems%2Fitems"></a>nestedArraysProperty | array\[\] | <span style="color:salmon">false</span> | \- |
17-
| nestedArraysAndObjectsProperty | <u>[object\[\]](#%2Fproperties%2FnestedArraysAndObjectsProperty%2Fitems)</u> | <span style="color:salmon">false</span> | \- |
14+
| numberArrayProperty | number\[\] | false | \- |
15+
| objectArrayProperty | [objectArrayProperty entry\[\]](#%2Fproperties%2FobjectArrayProperty%2Fitems) | false | \- |
16+
| nestedArraysProperty | nestedArraysProperty entry\[\] | false | \- |
17+
| nestedArraysAndObjectsProperty | [nestedArraysAndObjectsProperty entry\[\]](#%2Fproperties%2FnestedArraysAndObjectsProperty%2Fitems) | false | \- |
1818

1919
#### Example
2020

@@ -45,12 +45,12 @@
4545
}
4646
```
4747
---
48-
### <a id="%2Fproperties%2FobjectArrayProperty%2Fitems"></a>[objectArrayProperty entry](#%2Fproperties%2FobjectArrayProperty%2Fitems)
48+
### [objectArrayProperty entry](#%2Fproperties%2FobjectArrayProperty%2Fitems)
4949
#### Properties
5050

5151
| Name | Type | Required | Description |
5252
|------|------|------|------|
53-
| <a id="%2Fproperties%2FobjectArrayProperty%2Fitems%2Fproperties%2FbooleanProperty"></a>booleanProperty | boolean | <span style="color:salmon">false</span> | \- |
53+
| booleanProperty | boolean | false | \- |
5454

5555
#### Example
5656

@@ -60,12 +60,12 @@
6060
}
6161
```
6262
---
63-
### <a id="%2Fproperties%2FnestedArraysAndObjectsProperty%2Fitems"></a>[nestedArraysAndObjectsProperty entry](#%2Fproperties%2FnestedArraysAndObjectsProperty%2Fitems)
63+
### [nestedArraysAndObjectsProperty entry](#%2Fproperties%2FnestedArraysAndObjectsProperty%2Fitems)
6464
#### Properties
6565

6666
| Name | Type | Required | Description |
6767
|------|------|------|------|
68-
| <a id="%2Fproperties%2FnestedArraysAndObjectsProperty%2Fitems%2Fproperties%2FarrayProp%2Fitems"></a>arrayProp | string\[\] | <span style="color:salmon">false</span> | \- |
68+
| arrayProp | string\[\] | false | \- |
6969

7070
#### Example
7171

meta_configurator/src/utility/documentation/__tests__/samples/composition.expected.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Option 2
5151

5252
| Name | Type | Required | Description |
5353
|------|------|------|------|
54-
| type | [enum](#%2Fproperties%2FPerson%2FoneOf%2F0%2Fproperties%2Ftype) | false | \- |
54+
| type | [type](#%2Fproperties%2FPerson%2FoneOf%2F0%2Fproperties%2Ftype) | false | \- |
5555
| currentSemester | integer | false | \- |
5656

5757
#### Example
@@ -73,7 +73,7 @@ Option 2
7373

7474
| Name | Type | Required | Description |
7575
|------|------|------|------|
76-
| type | [enum](#%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2Ftype) | false | \- |
76+
| type | [type](#%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2Ftype) | false | \- |
7777
| avgGrade | number | false | \- |
7878

7979
#### Example

meta_configurator/src/utility/documentation/__tests__/samples/enumeration.expected.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
- [diet](#%2Fproperties%2Fdiet)
77

88
---
9-
### <a id="root"></a>[root](#root)
9+
### [root](#root)
1010
#### Properties
1111

1212
| Name | Type | Required | Description |
1313
|------|------|------|------|
14-
| country | <u>[enum](#%2Fproperties%2Fcountry)</u> | <span style="color:lightblue">true</span> | \- |
15-
| diet | <u>[enum](#%2Fproperties%2Fdiet)</u> | <span style="color:lightblue">true</span> | \- |
14+
| country | [country](#%2Fproperties%2Fcountry) | true | \- |
15+
| diet | [diet](#%2Fproperties%2Fdiet) | true | \- |
1616

1717
#### Example
1818

@@ -23,9 +23,9 @@
2323
}
2424
```
2525
---
26-
### <a id="%2Fproperties%2Fcountry"></a>[country](#%2Fproperties%2Fcountry)
27-
<details>
28-
<summary>Enumeration Values</summary>
26+
### [country](#%2Fproperties%2Fcountry)
27+
28+
Enumeration Values
2929
- `United States`
3030
- `Canada`
3131
- `Mexico`
@@ -46,11 +46,11 @@
4646
- `Russia`
4747
- `Saudi Arabia`
4848
- `United Arab Emirates`
49-
</details>
49+
5050

5151
---
52-
### <a id="%2Fproperties%2Fdiet"></a>[diet](#%2Fproperties%2Fdiet)
52+
### [diet](#%2Fproperties%2Fdiet)
5353
#### Enumeration Values
5454
- `herbivore`
5555
- `carnivore`
56-
- `omnivore`
56+
- `omnivore`

meta_configurator/src/utility/documentation/__tests__/samples/featureTesting.expected.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Conditionals
160160
|------|------|------|------|------|
161161
| city | string | false | City name | - |
162162
| zipCode | string | false | Zip code | "12345" |
163-
| country | [enum](#%2Fproperties%2Faddress%2Fproperties%2Fcountry) | false | Country name | - |
163+
| country | [country](#%2Fproperties%2Faddress%2Fproperties%2Fcountry) | false | Country name | - |
164164
| moreInfo | [moreInfo](#%2Fproperties%2Faddress%2Fproperties%2FmoreInfo) | false | More info about the address | - |
165165
| street | string | false | Street name | "Main Street" |
166166
| number | number | false | \- | - |
@@ -259,10 +259,10 @@ Conditionals
259259
|------|------|------|------|
260260
| info | string | false | Some info |
261261
| neighborhood | string | false | Neighborhood name |
262-
| timeZone | [enum](#%2Fproperties%2Faddress%2Fproperties%2FmoreInfo%2Fproperties%2FtimeZone) | false | Time zone |
262+
| timeZone | [timeZone](#%2Fproperties%2Faddress%2Fproperties%2FmoreInfo%2Fproperties%2FtimeZone) | false | Time zone |
263263
| booleanArray | boolean\[\] | false | Boolean array |
264264
| numbers | number\[\] | false | Numbers |
265-
| objects | [object\[\]](#%2Fproperties%2Faddress%2Fproperties%2FmoreInfo%2Fproperties%2Fobjects%2Fitems) | false | Objects |
265+
| objects | [objects entry\[\]](#%2Fproperties%2Faddress%2Fproperties%2FmoreInfo%2Fproperties%2Fobjects%2Fitems) | false | Objects |
266266

267267
#### Example
268268

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Untitled schema
2+
### Table of Contents
3+
4+
- [root](#root)
5+
- [inlinedArray entry](#%2Fproperties%2FinlinedArray%2Fitems)
6+
- [ABC](#%2Fproperties%2Fenum)
7+
- [enumInDefs](#%2F%24defs%2FenumInDefs)
8+
- [constantValue](#%2Fproperties%2FconstantValue)
9+
10+
---
11+
### [root](#root)
12+
#### Properties
13+
14+
| Name | Type | Required | Description |
15+
|------|------|------|------|
16+
| inlinedArray | [inlinedArray entry\[\]](#%2Fproperties%2FinlinedArray%2Fitems) | false | \- |
17+
| enum | [ABC](#%2Fproperties%2Fenum) | false | \- |
18+
| referenceToEnumInDefs | [enumInDefs](#%2F%24defs%2FenumInDefs) | false | \- |
19+
| constantValue | [constantValue](#%2Fproperties%2FconstantValue) | false | \- |
20+
21+
#### Example
22+
23+
```json
24+
{
25+
"inlinedArray": [
26+
{
27+
"name": "{string}"
28+
}
29+
],
30+
"enum": "{string}",
31+
"referenceToEnumInDefs": "{integer}",
32+
"constantValue": "myConstant"
33+
}
34+
```
35+
---
36+
### [inlinedArray entry](#%2Fproperties%2FinlinedArray%2Fitems)
37+
#### Properties
38+
39+
| Name | Type | Required | Description |
40+
|------|------|------|------|
41+
| name | string | false | \- |
42+
43+
#### Example
44+
45+
```json
46+
{
47+
"name": "{string}"
48+
}
49+
```
50+
---
51+
### [ABC](#%2Fproperties%2Fenum)
52+
#### Enumeration Values
53+
- `A`
54+
- `B`
55+
- `C`
56+
57+
---
58+
### [enumInDefs](#%2F%24defs%2FenumInDefs)
59+
#### Enumeration Values
60+
- `1`
61+
- `3`
62+
- `5`
63+
64+
---
65+
### [constantValue](#%2Fproperties%2FconstantValue)
66+
#### Enumeration Values
67+
- `myConstant`
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"type": "object",
3+
"$defs": {
4+
"enumInDefs": {
5+
"type": "integer",
6+
"enum": [1, 3, 5]
7+
}
8+
},
9+
"properties": {
10+
"inlinedArray": {
11+
"type": "array",
12+
"items": {
13+
"type": "object",
14+
"properties": {
15+
"name": {
16+
"type": "string"
17+
}
18+
}
19+
}
20+
},
21+
"enum": {
22+
"title": "ABC",
23+
"type": "string",
24+
"enum": ["A", "B", "C"]
25+
},
26+
"referenceToEnumInDefs": {
27+
"$ref": "#/$defs/enumInDefs"
28+
},
29+
"constantValue": {
30+
"type": "string",
31+
"enum": ["myConstant"]
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)