bump-sh / bump-sh/cli

[overlay] incorrectly concatenates enum arrays during deep merge

Open
#792 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
71
Forks
9
Avg merge
7m
Merged PRs (30d)
4

Description

## Description

When using `bump overlay` to apply an overlay that adds new properties to a schema, enum arrays from nested properties are incorrectly appended to existing enum arrays at different paths, resulting in duplicate values.

## Environment

- bump-cli version: 2.9.8
- Node.js version: 24.x

## Steps to Reproduce

1. Have an OpenAPI spec with a property containing an enum:

```yaml
# base-spec.yaml
paths:
/items/{id}:
put:
requestBody:
content:
application/json:
schema:
type: object
properties:
method:
type: string
enum: [GET, POST, PUT, DELETE]
```

2. Apply an overlay that adds a nested object with a property of the same name:

```yaml
# overlay.yaml
overlay: 1.0.0
actions:
- target: $.paths['/items/{id}'].put.requestBody.content['application/json'].schema.properties
update:
request:
type: object
properties:
method:
type: string
enum: [GET, POST, PUT, DELETE]
```

3. Run: `bump overlay base-spec.yaml overlay.yaml`

## Expected Behavior

The top-level `method.enum` should remain unchanged with 4 values:

```yaml
method:
enum: [GET, POST, PUT, DELETE]
```

And a new `request.properties.method.enum` should be added with 4 values.

## Actual Behavior

The top-level `method.enum` is incorrectly modified to have 8 values (duplicated):

```yaml
method:
enum: [GET, POST, PUT, DELETE, GET, POST, PUT, DELETE]
```

## Root Cause

In `src/core/overlay.ts`, the `update` method uses mergician with `appendArrays: true`:

```javascript
const merger = mergician({ appendArrays: true });
```

This causes arrays to be concatenated during deep merge. When the overlay adds a nested property with the same name (`method`) containing an enum array, mergician appears to find and concatenate enum arrays from different schema paths.

## Suggested Fix

https://github.com/bump-sh/cli/pull/791

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.