-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
feat: flatten allOf cases in message payloads #16
Conversation
830eb0e
to
6ec4393
Compare
|
||
|
||
Nunjucks.addFilter('additionalPropertiesAllowedForAll', (items) => items.every(p => p.additionalProperties() === true || p.additionalProperties() === undefined || p.additionalProperties() === null)); | ||
Nunjucks.addFilter('additionalPropertiesDisabledForAll', (items) => items.every(p => p.additionalProperties() === false) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a nice way to in-line this within the template. Suggestions welcome!
test/spec/asyncapi.yml
Outdated
@@ -145,6 +145,7 @@ components: | |||
x-pi: false | |||
sentAt: | |||
$ref: "#/components/schemas/sentAt" | |||
additionalProperties: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are currently no allOf usages in the template. I wasn't sure on the best example to add here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe take something from this https://github.com/asyncapi/tck/blob/master/tests/asyncapi-2.0/Schema%20Object/valid-polymorphism.yaml
don't worry it has nothing to do with streetlight example, we anyway need to one day prepare one dummy example that can be used in all the templates, that cover all cases. Other solution might be we make it possible to use tck
as the library, maybe
@jamescrowley How should I treat https://github.com/asyncapi/html-template/pull/13/files? as it is correct and I can merge, but you also did the same changes in this PR |
@jamescrowley lgtm, I just adjusted the PR summary as we use conventional commits. You can rebase this PR |
In the case of 'allOf' schema elements, the consumer doesn't need to know that it's been constructed of multiple definitions (unlike oneOf or anyOf). Therefore, the template can just render the combined children.
When we're using 'allOf', * if all elements in the allOf allows additional properties, then this will work * other set-ups are likely edge cases, as the properties would need to overlap so they're accepted by all
6ec4393
to
a5c8d31
Compare
@derberg I've re-based. I'm leaning towards just removing the 'additionalProperties' display entirely, given it's not really clear what the author's intent would be? While technically they might be permitted (if additionalProperties is missing or set to true), but that could just be due to the json schema limitations. Thoughts? |
@jamescrowley I merged into Also please extend |
I think this is a valid concern. It could probably be configured using a template param? So people can decide what to do. For instance, for public APIs, you might not want to share your AsyncAPI files. However, if it's something internal and you let people inspect the AsyncAPI file, it's useful to have an indicator that you're using inheritance. We can also have just an indicator nearby the schema using |
There are other problems here unfortunately. Within allOf, you can define the same properties in each definition, with different levels of 'specificity' on the constraint (ie, maybe just type: object, and another schema one putting tighter restrictions on it). Right now, the template just ends up listing the properties twice. In theory you could try and merge this definitions into the most constrained version, but we're definitely veering into complex territory. It may be worth consulting closer with how OpenAPI approaches this. I may have bitten off more than I can chew trying to generalise this right now - in our internal version, I'm just taking the 'last' occurrence of the property name as the 'most constrained, but that's not exactly generally applicable! |
This pull request has been automatically marked as stale because it has not had recent activity 😴 |
Description
This PR flattens usage of 'allOf' in message payloads. Usage of 'additionalProperties' can be problematic when using allOf, as it requires all provided schemas to successfully validate a message. See https://json-schema.org/understanding-json-schema/reference/combining.html#allof.
Therefore, most scenarios other than when 'additionalProperties' are permitted in every schema are likely to be edge cases as far as I can tell. Feedback especially welcome on this issue.
Note: I have based this off the changes in #13 for now
Related issue(s)
(Attempts) to Fix asyncapi/asyncapi-react#596