-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Types that reference JSONSchema are currently unusable #111
Comments
@brendanhay: Note that #110 just changed the types to more accurately match the OpenAPI spec. For example the Lines 19 to 21 in 381306b
The reason why "patternProperties": {
"additionalProperties": {
"$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps"
},
"type": "object"
}, It's actually not clear to how specifying "not": {
"$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps"
}, EIther way, I think this is fixable by changing The reason "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrBool": {
"description": "JSONSchemaPropsOrBool represents JSONSchemaProps or a boolean value. Defaults to true for the boolean property."
}, We can add an override to fix it to match the description, but you should also open an issue against the Kubernetes repository asking them to fix the OpenAPI spec for those I also agree that I know you think $ json-to-dhall https://prelude.dhall-lang.org/v12.0.0/JSON/Type <<< '{ "x": [ 1, [ { "y": true } ] ] }'
λ(JSON : Type)
→ λ ( json
: { array : List JSON → JSON
, bool : Bool → JSON
, null : JSON
, number : Double → JSON
, object : List { mapKey : Text, mapValue : JSON } → JSON
, string : Text → JSON
}
)
→ json.object
[ { mapKey = "x"
, mapValue =
json.array
[ json.number 1.0
, json.array
[ json.object [ { mapKey = "y", mapValue = json.bool True } ] ]
]
}
] ... and we could have it optionally import the Prelude to replace the |
Given the state of those OpenAPI definitions I'll maintain that writing/reusing a standalone JSON Schema Dhall package according the RFC is going to be smoother than attempting to fix upstream metadata or adding generator overrides, from my own experience, but YMMV. Regarding using One small improvement would be to have json.object (toMap
{ x = json.array
[ json.number 1.0
, json.array [ json.object (toMap { y = json.bool True }) ]
]
}) Not a huge improvement in this small example - but in my scenario(s) I have various YAML/JSON objects that are around ~5-10K lines in size, so potentially a win there. Although as stated previously you're still maintaining a JSON AST rather than a more first-class representation. (This is all moot though if a proper JSON Schema recursive type existed.) If only a |
@brendanhay: Yeah, we have to write a Dhall JSONSchema package anyway, since it would be pretty difficult for the The non-trivial part is converting it to YAML because it would require either:
Currently I'm leaning towards the former, since it is simpler and it seems sensible for the I also agree that We might someday support building in the Dhall ↔ JSON/YAML conversion functionality into the language, but right now the purpose of the command-line tools is to better understand what is required of those conversions to better inform the design of the corresponding language feature. |
Just updating on this: apparently JSON Schema is waaaaaay more complicated than I realize, to the point where it's easier to implement |
@brendanhay would it be possible to share an example of your workaround? |
As a concrete example, I'm attempting to convert various helm charts such as cert-manager into Dhall and there are various errors in the CustomResourceDefinition and related CustomResourceValidation types that are supposed to use JSONSchema:
externalDocumentation
is required but has its fields marked as optional. The property is actually optional.properties
has aText
value. It should be of typeJSONSchema
, whatever that might be.{}
. They should reference a recursiveJSONSchema
type similarly toJSONSchemaProps.properties
.{}
. Probably it should point to eitherPrelude.JSON.Type
orText
. (I personally find the former untenable outside of automated conversion.)Some thoughts/observations:
CustomResourceDefinition
's YAML asText
and post-processing this to decode theText
into a JSONValue
and reinsert it into the YAML/JSON AST when converting Dhall to YAML.dhall-kubernetes
regeneration.Prelude.JSON.Type
could be used as a shorter-term solution - but it's absolutely horrendous to work with when trying to represent ad-hoc JSON by hand.The text was updated successfully, but these errors were encountered: