Skip to content

Commit 58d72e5

Browse files
authored
properly show oneOf and anyOfs in examples in docs view (#758)
* properly show oneOf and anyOfs in examples in docs view * apply formatting changes --------- Co-authored-by: Logende <[email protected]>
1 parent d81e522 commit 58d72e5

5 files changed

Lines changed: 114 additions & 83 deletions

File tree

meta_configurator/src/schema/oneTimeSchemaPreprocessor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function preprocessOneTimeRecursive(schema: JsonSchemaType | undefined, schemaPa
4747
}
4848

4949
induceTitles(schema);
50+
induceTypeByProperties(schema);
5051

5152
convertConstToEnum(schema);
5253
injectTypesOfEnum(schema);
@@ -100,6 +101,13 @@ function preprocessSchemaRecord(
100101
}
101102
}
102103

104+
function induceTypeByProperties(schema: JsonSchemaObjectType): void {
105+
// if the type is not defined but the schema has the "properties" field, then we can assume that the type is "object"
106+
if (schema.type === undefined && schema.properties !== undefined) {
107+
schema.type = 'object';
108+
}
109+
}
110+
103111
function induceTitles(schema: JsonSchemaObjectType): void {
104112
induceTitlesOnObject(schema.properties ?? {});
105113
induceTitlesOnObject(schema.definitions ?? {});

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,54 @@
99
- [type](#%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2Ftype)
1010

1111
---
12-
### [Composition Schema](#root)
12+
### <a id="root"></a>[Composition Schema](#root)
1313
#### Properties
1414

1515
| Name | Type | Required | Description |
1616
|------|------|------|------|
17-
| Person | [Person](#%2Fproperties%2FPerson) | false | \- |
17+
| Person | <u>[Person](#%2Fproperties%2FPerson)</u> | <span style="color:salmon">false</span> | \- |
1818

1919
#### Example
2020

2121
```json
2222
{
2323
"Person": {
24-
"name": "{string}"
24+
"name": "{string}",
25+
"type": "Student",
26+
"currentSemester": "{integer}"
2527
}
2628
}
2729
```
2830
---
29-
### [Person](#%2Fproperties%2FPerson)
31+
### <a id="%2Fproperties%2FPerson"></a>[Person](#%2Fproperties%2FPerson)
3032
#### Properties
3133

3234
| Name | Type | Required | Description |
3335
|------|------|------|------|
34-
| name | string | false | \- |
36+
| <a id="%2Fproperties%2FPerson%2Fproperties%2Fname"></a>name | string | <span style="color:salmon">false</span> | \- |
3537

3638
#### oneOf
37-
Option 1
38-
##### [Student](#%2Fproperties%2FPerson%2FoneOf%2F0)
39-
Option 2
40-
##### [oneOf[1]](#%2Fproperties%2FPerson%2FoneOf%2F1)
39+
<b>Option 1</b>
40+
##### <u>[Student](#%2Fproperties%2FPerson%2FoneOf%2F0)</u>
41+
<b>Option 2</b>
42+
##### <u>[oneOf[1]](#%2Fproperties%2FPerson%2FoneOf%2F1)</u>
4143
#### Example
4244

4345
```json
4446
{
45-
"name": "{string}"
47+
"name": "{string}",
48+
"type": "Student",
49+
"currentSemester": "{integer}"
4650
}
4751
```
4852
---
49-
### [Student](#%2Fproperties%2FPerson%2FoneOf%2F0)
53+
### <a id="%2Fproperties%2FPerson%2FoneOf%2F0"></a>[Student](#%2Fproperties%2FPerson%2FoneOf%2F0)
5054
#### Properties
5155

5256
| Name | Type | Required | Description |
5357
|------|------|------|------|
54-
| type | [type](#%2Fproperties%2FPerson%2FoneOf%2F0%2Fproperties%2Ftype) | false | \- |
55-
| currentSemester | integer | false | \- |
58+
| type | <u>[type](#%2Fproperties%2FPerson%2FoneOf%2F0%2Fproperties%2Ftype)</u> | <span style="color:salmon">false</span> | \- |
59+
| <a id="%2Fproperties%2FPerson%2FoneOf%2F0%2Fproperties%2FcurrentSemester"></a>currentSemester | integer | <span style="color:salmon">false</span> | \- |
5660

5761
#### Example
5862

@@ -63,18 +67,18 @@ Option 2
6367
}
6468
```
6569
---
66-
### [type](#%2Fproperties%2FPerson%2FoneOf%2F0%2Fproperties%2Ftype)
70+
### <a id="%2Fproperties%2FPerson%2FoneOf%2F0%2Fproperties%2Ftype"></a>[type](#%2Fproperties%2FPerson%2FoneOf%2F0%2Fproperties%2Ftype)
6771
#### Enumeration Values
6872
- `Student`
6973

7074
---
71-
### [oneOf\[1\]](#%2Fproperties%2FPerson%2FoneOf%2F1)
75+
### <a id="%2Fproperties%2FPerson%2FoneOf%2F1"></a>[oneOf\[1\]](#%2Fproperties%2FPerson%2FoneOf%2F1)
7276
#### Properties
7377

7478
| Name | Type | Required | Description |
7579
|------|------|------|------|
76-
| type | [type](#%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2Ftype) | false | \- |
77-
| avgGrade | number | false | \- |
80+
| type | <u>[type](#%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2Ftype)</u> | <span style="color:salmon">false</span> | \- |
81+
| <a id="%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2FavgGrade"></a>avgGrade | number | <span style="color:salmon">false</span> | \- |
7882

7983
#### Example
8084

@@ -85,6 +89,6 @@ Option 2
8589
}
8690
```
8791
---
88-
### [type](#%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2Ftype)
92+
### <a id="%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2Ftype"></a>[type](#%2Fproperties%2FPerson%2FoneOf%2F1%2Fproperties%2Ftype)
8993
#### Enumeration Values
90-
- `Graduate`
94+
- `Graduate`

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
- [Person](#%2Fproperties%2FPerson)
66

77
---
8-
### [Conditionals Schema](#root)
8+
### <a id="root"></a>[Conditionals Schema](#root)
99
#### Properties
1010

1111
| Name | Type | Required | Description |
1212
|------|------|------|------|
13-
| Person | [Person](#%2Fproperties%2FPerson) | false | \- |
13+
| Person | <u>[Person](#%2Fproperties%2FPerson)</u> | <span style="color:salmon">false</span> | \- |
1414

1515
#### Example
1616

@@ -23,16 +23,16 @@
2323
}
2424
```
2525
---
26-
### [Person](#%2Fproperties%2FPerson)
26+
### <a id="%2Fproperties%2FPerson"></a>[Person](#%2Fproperties%2FPerson)
2727
#### Properties
2828

2929
| Name | Type | Required | Description |
3030
|------|------|------|------|
31-
| name | string | false | \- |
32-
| married | boolean | false | \- |
31+
| <a id="%2Fproperties%2FPerson%2Fproperties%2Fname"></a>name | string | <span style="color:salmon">false</span> | \- |
32+
| <a id="%2Fproperties%2FPerson%2Fproperties%2Fmarried"></a>married | boolean | <span style="color:salmon">false</span> | \- |
3333

34-
35-
Conditionals
34+
<details>
35+
<summary>Conditionals</summary>
3636
#### if
3737
```json
3838
{
@@ -60,11 +60,12 @@ Conditionals
6060
"type": "string",
6161
"title": "partnerName"
6262
}
63-
}
63+
},
64+
"type": "object"
6465
}
6566
```
6667

67-
68+
</details>
6869
#### Example
6970

7071
```json

0 commit comments

Comments
 (0)