Open aneophyte opened 6 years ago
Yea good idea. Wanna PR that change? The name of this function is now inferRawSchema btw
@aneophyte -I will implement this request/feature. Just to be clear on the requirement, can you please provide a sample input and the expected output?
The library has changed quite a bit since I last posted this issue. But the following is probably what I want:
Input:
{"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": null
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}
Output:
{ widget:
{ debug: 'string',
window:
{ title: 'string',
name: 'string',
width: 'number',
height: 'number' },
image:
{ src: 'string',
name: 'string',
hOffset: 'number',
vOffset: 'number',
alignment: 'null' // <--- Echo this, instead of crashing },
text:
{ data: 'string',
size: 'number',
style: 'string',
name: 'string',
hOffset: 'number',
vOffset: 'number',
alignment: 'string',
onMouseUp: 'string' } } }
By the way, I have not had the time to check the newer version. I am currently using version 1.1.0.
~Edit: Ok, just checked. There is no longer a typeSchema generator. It was very useful for generating schema for existing APIs. But since toString()
prints out the entire function, would it make sense to copy paste it as the source code...~
Whoops, just noticed mafintosh's response about inferRawSchema
.
Got Error: Unexpected key in object
when parsing.
Steps:
inferRawSchema
for the object I posted above.Thank you @aneophyte -I will try to get a PR through ASAP. I am currently moving cities and need to pack an entire house, thus it might take me a little bit longer.
With the latest version, null is supported. So I think this can be closed?
It appears that
compile.schema
errors out withCannot infer type
when it findsnull
in any of the field. This renders the function somewhat unusable. Couldn't the function leavenull
as it is and return the rest of the schema instead?