Skip to content

Commit

Permalink
Fix nested record traversal
Browse files Browse the repository at this point in the history
Also updated test fixtures to cover the use case
  • Loading branch information
frankgrimes97 committed Dec 6, 2022
1 parent 3c9cfcd commit 26776c8
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion avrolint.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ let getRecordSchema = function(field) {

const upperCaseFieldType = field.type.type?.toUpperCase();
if (upperCaseFieldType === "RECORD") {
return field;
return field.type;
} else if (upperCaseFieldType === "ARRAY" && field.type.items?.type?.toUpperCase() === "RECORD") {
return field.type.items;
} else if (upperCaseFieldType === "MAP" && field.type.values?.type?.toUpperCase() === "RECORD") {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion tests/fixtures/invalid-missing-docs.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
"name": "id",
"type": "int"
},
{
"name": "MyNestedRecord",
"type": {
"type": "record",
"name": "NestedRecordA",
"fields":
[
{
"name": "nestedId",
"type": "int"
}
]
}
},
{
"name": "MyArrayOfNestedRecords",
"type": {
Expand Down Expand Up @@ -46,7 +60,7 @@
"name": "MyUnionNestedRecord",
"type": [ "null", {
"type": "record",
"name": "NestedRecordA",
"name": "NestedRecordD",
"fields":
[
{
Expand Down
29 changes: 23 additions & 6 deletions tests/fixtures/valid.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@
"type": "int",
"doc": "My Record Identifier"
},
{
"name": "MyNestedRecord",
"type": {
"type": "record",
"name": "NestedRecordA",
"fields":
[
{
"name": "nestedId",
"type": "int",
"doc": "My Record Identifier"
}
],
"doc": "My Nested RecordA Identifier"
},
"doc": "My Nested Record"
},
{
"name": "MyArrayOfNestedRecords",
"type": {
"type": "array",
"items": {
"type": "record",
"name": "NestedRecordA",
"name": "NestedRecordB",
"fields":
[
{
Expand All @@ -24,7 +41,7 @@
"doc": "My Record Identifier"
}
],
"doc": "My Nested RecordA Identifier"
"doc": "My Nested RecordB Identifier"
}
},
"doc": "My Array Of Nested Records"
Expand All @@ -35,7 +52,7 @@
"type": "map",
"values": {
"type": "record",
"name": "NestedRecordB",
"name": "NestedRecordC",
"fields":
[
{
Expand All @@ -44,7 +61,7 @@
"doc": "My Record Identifier"
}
],
"doc": "My Nested RecordB Identifier"
"doc": "My Nested RecordC Identifier"
}
},
"doc": "My Map Of Nested Records"
Expand All @@ -53,7 +70,7 @@
"name": "MyUnionNestedRecord",
"type": [ "null", {
"type": "record",
"name": "NestedRecordC",
"name": "NestedRecordD",
"fields":
[
{
Expand All @@ -62,7 +79,7 @@
"doc": "My Record Identifier"
}
],
"doc": "My Nested RecordC Identifier"
"doc": "My Nested RecordD Identifier"
}],
"doc": "My Union Of Nested Record"
}
Expand Down
8 changes: 8 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ test('throws error on invalid AVSC file with missing docs', async () => {

const expectedErrorMessage = `Invalid Schema at '${fileName}'! The following fields are not documented:
com.samsung.ads.MyRecord.id
com.samsung.ads.MyRecord.MyNestedRecord
com.samsung.ads.MyRecord.MyNestedRecord.nestedId
com.samsung.ads.MyRecord.MyArrayOfNestedRecords
com.samsung.ads.MyRecord.MyArrayOfNestedRecords.nestedId
com.samsung.ads.MyRecord.MyMapOfNestedRecords
Expand All @@ -75,6 +77,8 @@ test('throws error on multiple invalid AVSC files with missing docs', async () =

const expectedErrorMessage = `Invalid Schema at '${fileName}'! The following fields are not documented:
com.samsung.ads.MyRecord.id
com.samsung.ads.MyRecord.MyNestedRecord
com.samsung.ads.MyRecord.MyNestedRecord.nestedId
com.samsung.ads.MyRecord.MyArrayOfNestedRecords
com.samsung.ads.MyRecord.MyArrayOfNestedRecords.nestedId
com.samsung.ads.MyRecord.MyMapOfNestedRecords
Expand All @@ -95,6 +99,8 @@ test('throws error on invalid AVSC files, one valid and one with missing docs',

const expectedErrorMessage = `Invalid Schema at '${fileNameInvalid}'! The following fields are not documented:
com.samsung.ads.MyRecord.id
com.samsung.ads.MyRecord.MyNestedRecord
com.samsung.ads.MyRecord.MyNestedRecord.nestedId
com.samsung.ads.MyRecord.MyArrayOfNestedRecords
com.samsung.ads.MyRecord.MyArrayOfNestedRecords.nestedId
com.samsung.ads.MyRecord.MyMapOfNestedRecords
Expand Down Expand Up @@ -129,6 +135,8 @@ test('throws error on multiple invalid AVSC files', async () => {

const expectedErrorMessage1 = `Invalid Schema at '${fileName1}'! The following fields are not documented:
com.samsung.ads.MyRecord.id
com.samsung.ads.MyRecord.MyNestedRecord
com.samsung.ads.MyRecord.MyNestedRecord.nestedId
com.samsung.ads.MyRecord.MyArrayOfNestedRecords
com.samsung.ads.MyRecord.MyArrayOfNestedRecords.nestedId
com.samsung.ads.MyRecord.MyMapOfNestedRecords
Expand Down

0 comments on commit 26776c8

Please sign in to comment.