openapi-merge icon indicating copy to clipboard operation
openapi-merge copied to clipboard

Exception when merging files with nullable enums

Open halfpastfouram opened this issue 1 year ago • 1 comments

Command I'm running:

% npx openapi-merge-cli --config openapi-merge.yaml

Files i'm using:

File 1:

openapi: 3.0.3
info:
  title: Test
  version: 0.0.1
paths:
  /some/endpoint1:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/someSchema'
      responses:
        '200':
          description: successful operation
components:
  schemas:
    someSchema:
      type: object
      properties:
        someField:
          type: string
          nullable: true
          enum:
            - "A"
            - "B"
            - "C"
            - null

File 2 (identical to File 1, except for endpoint):

openapi: 3.0.3
info:
  title: Test
  version: 0.0.1
paths:
  /some/endpoint2:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/someSchema'
      responses:
        '200':
          description: successful operation
components:
  schemas:
    someSchema:
      type: object
      properties:
        someField:
          type: string
          nullable: true
          enum:
            - "A"
            - "B"
            - "C"
            - null

Output:

## /opt/homebrew/Cellar/node/20.8.0/bin/node: Running v1.3.1 (+1ms)
## Loaded the configuration: 2 inputs (+36ms)
## Loading input 0: specs/test1.yaml (+0ms)
## Loading input 1: specs/test2.yaml (+0ms)
## Loaded the inputs into memory, merging the results. (+1ms)
An uncaught exception was thrown TypeError: Cannot use 'in' operator to search for '$ref' in null
    at Object.isReference (/Users/.../node_modules/atlassian-openapi/lib/type-checks.js:85:48)
    at compare (/Users/.../node_modules/openapi-merge/dist/component-equivalence.js:63:51)
    at /Users/.../node_modules/openapi-merge/dist/component-equivalence.js:80:39
    at Array.every (<anonymous>)
    at compare (/Users/.../node_modules/openapi-merge/dist/component-equivalence.js:80:26)
    at /Users/.../node_modules/openapi-merge/dist/component-equivalence.js:80:39
    at Array.every (<anonymous>)
    at compare (/Users/.../node_modules/openapi-merge/dist/component-equivalence.js:80:26)
    at /Users/.../node_modules/openapi-merge/dist/component-equivalence.js:80:39
    at Array.every (<anonymous>)

Platform: macOS Ventura (22D49)
Node version:

% /opt/homebrew/Cellar/node/20.8.0/bin/node -v
v20.8.0

halfpastfouram avatar Nov 09 '23 14:11 halfpastfouram

Removing - null from one of the two files resolves the problem, but seeing as I need to do this programatically I cannot manually remove the - null option from just one of the files.

halfpastfouram avatar Nov 09 '23 14:11 halfpastfouram