-
Notifications
You must be signed in to change notification settings - Fork 27
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
Current icarResource Discriminator property doesnt appear valid #278
Comments
@gra-moore the original idea of adding discriminator to this resource was to be allowed other resources be inherited from icarResource.json. So I confirmed from Anton, that there was nothing behind this decision but this. So we can try to apply the fix. Have you already tried above proposed way to fix this issue? |
@AlexeyHardCode Not quite sure I follow you? I understand the idea but as I said before I dont see how it would actually work given there is no resourceType property. My Proposal is to remove the discriminator, do you have an alternative? |
@gra-moore I don't have any alternatives at the moment. I hope that removing the discriminator won't break the structure. I'll try to remove it locally and see if I can generate the code afterwards. |
I tested different changes with our code-generator for Java and JS/TS:
Therefore, I think adding the required-definition is the solution which works best. |
I have several questions, some technical some policy.
"discriminator": { When request bodies or response payloads may be one of a number of different schemas, a discriminator object can be used to aid in serialization, deserialization, and validation. The discriminator is a specific object in a schema which is used to inform the consumer of the specification of an alternative schema based on the value associated with it. mapping | Map[string, string] | An object to hold mappings between payload values and schema names or references. I don't see that we have defined these mappings anywhere, is this stuff that is generated by tooling?
|
We are using the openapitools code-generator (v5.3.1) for Java, esp. Spring Boot. to 1.: No, we shouldn't publish sth. which is not conform to the requirements. That's true. Maybe there is a configuration-switch I didn't try to suppress the duplicated output within the data-json. Maybe not. But if there is not, we may solve this a different way. to 2.: "I don't see that we have defined these mappings anywhere, is this stuff that is generated by tooling?" --> Yes, it is: to 4: to 5: unclear what you are looking for |
Based on our discussion today, and some subsequent research:
This would all have been fine but:
Potential approach
Note that we have used different names for these discriminators through the ICAR specification: |
Agree with @cookeac summary above and highlight:
My proposal for minimal disruption and max compliance:
Impact:
From an opinion perspective - a goal of making it simpler to use this spec by supporting autogeneration tooling should not lead to compromising the long term correctness due to bugs in that tooling. |
I just tested out the Open API go generator. It produces the following structure based on the current ADE-1 version of the spec:
with event subtype represented as:
The serialisation is done such:
Neither the resourceType nor eventType property are added to the serialised representations. I conclude from this that any clients generating code for use in Go will not work when talking to services for other languages. This is the generator command to run to see the above.
|
It also appears that the kotlin generator does not suffer from the same bug as the java generator as it uses a different JSON serialiser. Again, the property is not found on the model constructs. Any kotlin client will not work with any services that require the resourceType field to be set. Here is the kotlin data structure for event `**
interface IcarEventCoreResource : IcarResource {
}` |
One final note. The dotnet generator recommended by Microsoft is here: NSwag uses this library for its JSON Schema: And here is the page that describes how discriminators work: https://github.com/RicoSuter/NJsonSchema/wiki/Inheritance From what I can see this dotnet tooling library is compliant with the specification that a discriminator must be specified as a property. I have not had a chance to run this tool on the open api files. |
There are several issues logged in openapi-generator about this. Essentially it seems that at present discriminators to support data binding and model properties are handled by two different parts of the generator code, and the "discriminator" part does not align with the OpenAPI spec (i.e. doesn't expect the discriminator will be a property in the model). It is possible to use annotations (As.EXISTING_PROPERTY) to tell the Java and C# generator to use the model property, but then it expects you to populate the value of the property yourself (which is how other languages will do it anyway). It does look like this is being addressed, filling in the model property automatically on serialization, which has recently been merged into master (6.0.0) for openapi-generator. See #9441 in https://github.com/OpenAPITools/openapi-generator/issues. I have no idea what that means though in actual usable releases in the roadmap. |
We agreed that it makes sense to try and align our ADE 1.3 release with when the repaired openapi-generator (6.0.0) is available. However, it could be released earlier if that is delayed. At the time we release 1.3, as there are not any semantic changes people can either:
We also agreed to tidy away the unnecessary discriminators in classes derived from ResourceType (collections and events). |
Discussed 21/04/2022: |
Reactivated this issue so we could discuss in the context of #295 and #299 |
The swagger seems incorrect: https://github.com/adewg/ICAR/blob/ADE-1/resources/icarResource.json with relation to the discriminator declaration.
According to the openAPI spec: https://swagger.io/specification/
While composition offers model extensibility, it does not imply a hierarchy between the models. To support polymorphism, the OpenAPI Specification adds the discriminator field. When used, the discriminator will be the name of the property that decides which schema definition validates the structure of the model. As such, the discriminator field MUST be a required field. There are two ways to define the value of a discriminator for an inheriting instance.
Use the schema name.
Override the schema name by overriding the property with a new value. If a new value exists, this takes precedence over the schema name. As such, inline schema definitions, which do not have a given id, cannot be used in polymorphism.
Key thing is that the descriminator property must be on the resource and must be required. From what I can see now this is not the case (unless it is a built in property of object).
The reason this is brought up is that resourceType is the name of the property we agreed on adding to support the streaming API. The PR to add this property will likely fix this issue. But we should discuss and see if this is really doing something we need and in the way we expect.
The text was updated successfully, but these errors were encountered: