Support default value for array properties - #352
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes invalid YAML emitted by the ramldoc generator when rendering default: values for array-typed properties that contain a single default element.
Changes:
- Add a regression RAML fixture covering an array property with a single-element default.
- Add a generator test asserting the produced RAML contains
default: "InventorySupply"and not the invaliddefault: - "InventorySupply". - Update
Instance.toYaml()to unwrap single-elementArrayInstancevalues before serialization.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| languages/ramldoc/src/test/resources/arraydefault.raml | Adds a minimal RAML spec fixture reproducing the single-item array default scenario. |
| languages/ramldoc/src/test/kotlin/io/vrap/codegen/languages/ramldoc/TestCodeGenerator.kt | Adds a regression test validating the generated output for array defaults. |
| languages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/extensions/VrapExtensions.kt | Changes YAML serialization behavior to unwrap single-item arrays. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
all othercallers (e.g. renderAnnotation) keep the original sequence-preserving behavior. Also fixes a compile error in OasResourceRenderer.renderQueryParameter: queryParameter. Adds regression tests: array default renders as scalar (testArrayDefaultWithSingleElementRendersAsScalar) and array annotation still renders as sequence (testArrayAnnotationWithSingleElementRendersAsSequence).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (1)
languages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/model/OasTypeRenderer.kt:251
- This changes an unused overload, so it cannot affect generated OpenAPI-backed types as described. All active callers use
renderProperty(name: String, type: Schema<Any>, required: List<String>?)(for example, lines 127, 157, and 169), while this RAML-model overload has no caller; the active overload also never emitstype.default. Update the active OAS rendering path if OAS support is intended, or remove this ineffective change from the PR's stated scope.
| default: ${property.type.default.toYaml(true)}""" else ""}${if (property.type?.isInlineType == true && property.type?.annotations != null) """
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #351
Summary
When a RAML property has an array type with a single-element
default:value, theramldoclanguage module generates invalid YAML — the array'sdefaultis rendered as a YAML block-sequence item spliced onto the same line as thedefault:key, which is not legal YAML.Expected output
Root cause
In
languages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/extensions/VrapExtensions.kt, theInstance.toYaml()extension function handlesArrayInstancevalues by passing the rawList<Instance>to Jackson'sYAMLMapper, which correctly serializes it as a YAML block sequence (e.g.- "InventorySupply"). The renderer call sites (e.g.RamlObjectTypeRenderer.kt,OasTypeRenderer.kt,RamlResourceRenderer.kt) then splice this directly afterdefault:on a single source line, which is invalid for a sequence.Fix
Unwrap single-element
ArrayInstancedefaults to their scalar value before serialization intoYaml(), so they render as a plain scalar (default: "InventorySupply") instead of a block sequence. Multi-element array defaults are a separate, currently unsupported case (no valid single-line representation exists in YAML for them) and are out of scope for this fix.Affected files
languages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/extensions/VrapExtensions.ktlanguages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/model/RamlObjectTypeRenderer.ktlanguages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/model/RamlResourceRenderer.kt(query-param defaults, same pattern)Test coverage
Added
testArrayDefaultWithSingleElementRendersAsScalarinlanguages/ramldoc/src/test/kotlin/io/vrap/codegen/languages/ramldoc/TestCodeGenerator.kt, backed by fixturelanguages/ramldoc/src/test/resources/arraydefault.raml, asserting the generated output containsdefault: "InventorySupply"and notdefault: - "InventorySupply".