The core of this SDK is the type extractor function. This issue is about building one.
Requirements
- Build a function that accept anything and returns a Json string representing its type.
The resulting types are the following:
string
int
float
bool
null
list
object
unknown
The return format is:
{
propertyType: string;
}
- When parsing lists, extract the types present in the list in an additional field:
{
propertyType: string;
children: string[]; // e.g. [string, null]
}
- When parsing objects, extract the object fields recursively:
{
propertyType: string;
children: {
propertyName: string; // object field's name
propertyType: string;
children?: any
}[];
}
- Build a function that accepts a map of string keys to values of any type and returns an array of objects of the following type:
{
propertyName: string; // map key
// The other fields are the result of the function build on step 3 applied to the map value
propertyType: string;
children: {
propertyName: string; // object field's name
propertyType: string;
children?: any
}[];
}
Add tests to verify the correct behavior.
Reference code
We have this logic and tests for it implemented in the Avo Inspector SDKs for other platforms
TypeScript:
The function: https://github.com/avohq/node-avo-inspector/blob/main/src/AvoSchemaParser.ts#L6
Tests: https://github.com/avohq/node-avo-inspector/blob/main/src/tests/TestParsing.ts
Java:
The function: https://github.com/avohq/android-avo-inspector/blob/33934530274af6aa7640dfaba54b4d626bbe6e48/avoinspector/src/main/java/app/avo/inspector/AvoSchemaExtractor.java#L172
Tests: https://github.com/avohq/android-avo-inspector/blob/33934530274af6aa7640dfaba54b4d626bbe6e48/avoinspector/src/test/java/app/avo/inspector/MapSimpleTypeSchemaExtractionTests.java
good first issue