-
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
Make APIs type safe according to AAS meta model spec #197
Comments
The problem with |
Yes, I'm aware of how
This is exactly what we have here, and what I'm requesting. I do know that in some cases distinguishing between present/not present/null is necessary (in particular for PUT/PATCH requests in REST APIs) and I also know JsonNullable. However, I don't think this is relevant here. The AAS meta model clearly states that some fields are optional, a value of |
Although I have a different interpretation of that quote, it doesn't really matter. As long as there is no need to differentiate between |
What exactly is the benefit of having optional properties return It maybe is helpful that the AAS metamodel classes in AAS4J are designed in such a way that it is possible to create instances that are not valid, e.g. by not setting the idShort where it is actually required. We made the design decision that we think it is better to allow the creation of invalid instances and than add a validator component that will check if a given instance if compliant to the standard. Unfortunately, this validator is currently not available as we did not yet finish updating it to the metamodel v3.0. Generally speaking, there are multiple things the AAS metamodel classes can be used for, e.g. as result format from loading AAS model files, to create AAS models from code or as payload for API operations. The only scenario I really think using My approach upon implementing PATCH using AAS4J was therefore not to parse the payload to the AAS4J classes but to treat it as a generic JSON Merge request and use libraries that can execute any JSON Merge request on any object instance. Coming back to the potential implications of using For clarification, I do not categorically oppose the use of |
Hi @mjacoby, thanks for the comprehensive answer.
The point is to have caller code not ever receive null, so by providing
This is interesting, although not my current use case.
Best practice here is to always return a (possibly empty) collection, never null nor Optional. This is exactly what
Using
|
Many properties in the AAS meta model are optional. However, in the AAS4J API, corresponding methods return
null
when a certain value is not present in a loaded Environment. One (arbitrarily chosen) example:AdministrativeInformation#getVersion()
returns the value of an optional field, but neither the API nor the JavaDoc indicate this. The only way to find out is by opening the link and look at the specification.IMO adding this information in the JavaDoc (i.e., "@returns Returns the String for the property version or null") would only be a weak workaround; I'd actually like to have such methods return
java.util.Optional<String>
. This is the only way to work robustly with the API.The text was updated successfully, but these errors were encountered: