Skip to content

Support default value for array properties - #352

Merged
jenschude merged 5 commits into
mainfrom
support-default-values-for-arrays
Aug 13, 2026
Merged

Support default value for array properties#352
jenschude merged 5 commits into
mainfrom
support-default-values-for-arrays

Conversation

@stmeissner

@stmeissner stmeissner commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #351

Summary

When a RAML property has an array type with a single-element default: value, the ramldoc language module generates invalid YAML — the array's default is rendered as a YAML block-sequence item spliced onto the same line as the default: key, which is not legal YAML.

Expected output

roles:
  type: array
  items:
    type: ChannelRoleEnum
  default: "InventorySupply"
  required: true

Root cause

In languages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/extensions/VrapExtensions.kt, the Instance.toYaml() extension function handles ArrayInstance values by passing the raw List<Instance> to Jackson's YAMLMapper, 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 after default: on a single source line, which is invalid for a sequence.

Fix

Unwrap single-element ArrayInstance defaults to their scalar value before serialization in toYaml(), 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.kt
  • languages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/model/RamlObjectTypeRenderer.kt
  • languages/ramldoc/src/main/kotlin/io/vrap/codegen/languages/ramldoc/model/RamlResourceRenderer.kt (query-param defaults, same pattern)

Test coverage

Added testArrayDefaultWithSingleElementRendersAsScalar in languages/ramldoc/src/test/kotlin/io/vrap/codegen/languages/ramldoc/TestCodeGenerator.kt, backed by fixture languages/ramldoc/src/test/resources/arraydefault.raml, asserting the generated output contains default: "InventorySupply" and not default: - "InventorySupply".

@stmeissner
stmeissner requested a review from a team as a code owner August 10, 2026 16:45
@stmeissner
stmeissner requested a lite review from Copilot August 11, 2026 08:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 invalid default: - "InventorySupply".
  • Update Instance.toYaml() to unwrap single-element ArrayInstance values 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).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 emits type.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) """

@jenschude
jenschude merged commit aff5e6c into main Aug 13, 2026
6 checks passed
@jenschude
jenschude deleted the support-default-values-for-arrays branch August 13, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RAML doc generator emits invalid YAML for single-item array default values

3 participants