Add NestedHierarchy schema and tests#1447
Conversation
Added a new `NestedHierarchy` sealed trait with cases and a corresponding test to verify schema generation. This enhances test coverage for nested hierarchies in REST schemas.
There was a problem hiding this comment.
Pull request overview
This PR tightens generated OpenAPI schemas for non-flat (nested) sealed hierarchies so they don’t accept arbitrary extra object fields, improving schema strictness and client/server validation correctness.
Changes:
- Update
RestStructure.Union.createSchemafor non-flat hierarchies to setadditionalProperties: falseon discriminator wrapper objects. - Attempt to set
additionalProperties: falseon resolved (inlined) inner case schemas and addtitleon wrapper objects for readability. - Add a
NestedHierarchytest fixture and expected schema output assertions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| rest/src/main/scala/io/udash/rest/openapi/RestStructure.scala | Tightens non-flat union wrapper schemas and adjusts inlined inner case schemas (additionalProperties: false, plus wrapper title). |
| rest/src/test/scala/io/udash/rest/openapi/RestSchemaTest.scala | Adds a nested hierarchy definition and asserts the stricter, titled schema output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… case tests Only apply additionalProperties=false to inlined case schemas that are actually objects with the default setting, preserving @transparent (primitive) and map-like schema semantics. Add test covering both cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "oneOf": [ | ||
| { | ||
| "type": "object", | ||
| "title": "RestEntity", |
There was a problem hiding this comment.
Hm, are you sure this correct ? I don't know the context of your usecase, but it creates more then one schema with the same title, might break some API generators
There was a problem hiding this comment.
the open api generator for sure works wrong for nested hierarchies, because it encodes it the same way like the flatten ones (but there is no discriminator). This solution at least works for us (maybe I miss sth else)
There was a problem hiding this comment.
I think something might go wrong when you add @title for RestEntity class
Non-flat (nested) sealed hierarchy schemas does not have discriminator and should be encoded in open-api spec on its own way.