-
Notifications
You must be signed in to change notification settings - Fork 14
Support for oneOf #2
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
Comments
Hi Anton, thanks for this. Yes, I am looking into
Is this the type of usage you have in mind? If not, can you give me an example of the kind of usage you would like to see covered? In any case, this is not going to be straightforward and I can't promise anything immediately - perhaps a couple of weeks. |
Sure thing, here is an example: https://bitbucket.org/atlassianlabs/atlascode/raw/main/resources/schemas/pipelines-schema.json "script": {
"description": "Contains a list of commands that are executed in sequence. \n\nScripts are executed in the order in which they appear in a step. \n\nWe recommend that you move large scripts to a separate script file and call it from the bitbucket-pipelines.yml.",
"type": "array",
"items": {
"oneOf": [
{
"type": "string",
"description": "Command to execute",
"minLength": 1
},
{
"$ref": "#/definitions/pipe"
}
]
},
"minItems": 1
}, I think the closest thing in kotlin is sealed classes for this use case, but I may be wrong |
Thanks for giving such a comprehensive example. The sort of cases I have been looking at involve the use of a "discriminator" field ("customerType" in my example), which would allow the use of strongly-typed dependent properties. I like to think that if there are sufficient validations in the constructors for the generated classes, they will be usable by deserialization functions with no additional custom code or parameterization. To generate classes for your examples that would allow automatic deserialization would be very difficult, but if you were prepared to accept the use of One of the main advantages of code generation is that it gives you strongly-typed classes to work with and this would run counter to that principle, but with a limited amount of casting and custom deserialization it would probably still be valuable. Let me know what you think - would outputting |
I have made two changes to the Code Generator. The first is to allow The second change is to allow non-Kotlin identifiers - your example includes property names like You might like to try the new version - |
We also have schemas that use sourceDetails:
anyOf:
- properties:
bankAccountId:
type:
- string
- 'null'
__typename:
type: string
enum:
- BankAccountPaymentDetails
required:
- bankAccountId
- __typename
- properties:
linkedServerPaymentId:
type:
- string
- 'null'
__typename:
type: string
enum:
- ThirdPartyFeeReversalPaymentDetails
required:
- linkedServerPaymentId
- __typename
type:
- object
- 'null' In our case, we have a |
Hi Myron, I'm sure I don't need to tell you that this is a tricky issue. Producing a solution that meets even a moderate subset of the possible requirements is very difficult. I am narrowing down my focus onto something like the following (a bit more limited than my earlier example):
This would produce code something like:
This doesn't exactly meet your needs, but it might be close. One important point - this uses I have a use case similar to this related to my day job, so it's possible there may be a bit more urgency applied to this in the next few days, but I can't promise anything. |
That's exactly what I'm looking for :). ....although as you pointed out, my schema has |
It was pretty easy to switch our generator to use |
OK, version 0.47 includes an implementation of My example assumes that the generator is generating a set of files using
When there are other properties in the outer schema as well as the I am in any case thinking of providing a way of specifying generated class names, but that's a longer-term issue. I hope I'm not setting the expectation that I will always be able to respond to requests so quickly, but as I said earlier, I've had this issue in mind for some time. And a requirement from my day job (which has been satisfied by these changes) gave the topic a bit of impetus. Let me know if you have problems with the new version - with any luck it will be useful, if not ideal. |
Thanks @pwall567!
Nope. I appreciate the promptness but definitely don't have any right to expect it in the future. I'll let you know how this is working for us once we're able to try it. |
I just hit this issue actually, I wanted to do something simple like have different versions of the schema e.g. {
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"title": "iBlum Program Questionnaire Schema",
"oneOf": [
{
"$ref": "./questionnaire.schema-0.1.1.json#"
},
{
"$ref": "./questionnaire.schema-0.1.2.json#"
}
]
} where questionnaire.schema-0.1.1.json starts with {
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"title": "xyz",
"type": "object",
"properties": {
"schemaVersion": {
"type": "string",
"enum": ["0.1.1"]
}, But I get errors like |
Hi @trajano , as you will have found if you read the entire thread of this issue, code generation for I don't know what output you were hoping for, but any form of conditionality – deserialization into the 0.1.1 form or the 0.1.2 form – would depend on the deserialization software you were using. I am concerned that you are getting compile errors on the code generator output, but I can't guarantee the viability of code generated for |
@pwall567 yeah I agree. It is probably best to just have n+1 schema files where the +1 would just ensure that there is a schema version check and parser. Then have n version specific schemas. |
Hi! Thanks for an awesome project!
I'm trying to use it currently and my specific schema uses oneOf quite a lot.
Are there any plans to support this?
Thanks!
The text was updated successfully, but these errors were encountered: