swagger-api / apidom

Semantic parser for API specifications
https://swagger-api.github.io/apidom/
70 stars 18 forks source link

Empty array element is not parsed as Node, refs https://github.com/swagger-api/apidom/issues/883 #916

Closed frantuma closed 2 years ago

frantuma commented 3 years ago

Similar to https://github.com/swagger-api/apidom/issues/883, when an array item is empty in YAML (see below), such item is not parsed as an element

e.g.


asyncapi: '2.2.0'
components:
  schemas:
    test:
      type: object
      required:
        - 

is parsed into:

/home/frantuma/.nvm/versions/node/v16.9.0/bin/node /dati/dev/progetti/swagger/projects/apidom/master/apidom/node_modules/mocha/bin/mocha --require ts-node/register/transpile-only --ui bdd --reporter /opt/WebStorm/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js /dati/dev/progetti/swagger/projects/apidom/master/apidom/packages/apidom-ls/test/openapi-yaml-parse.ts --grep ^apidom-parse-test test parse yaml$
asyncApi2 0:0 - 7:0
member 0:0 - 0:17
string 0:0 - 0:8
asyncApiVersion 0:10 - 0:17
member 1:0 - 7:0
string 1:0 - 1:10
components 2:2 - 7:0
member 2:2 - 7:0
string 2:2 - 2:9
object 3:4 - 7:0
member 3:4 - 7:0
string 3:4 - 3:8
schema 4:6 - 7:0
member 4:6 - 4:18
string 4:6 - 4:10
string 4:12 - 4:18
member 5:6 - 7:0
string 5:6 - 5:14
array 6:8 - 7:0

or

asyncapi: '2.2.0'
components:
  schemas:
    test:
      type: object
      required:
        - 
        - aa

is parsed into:

member 0:0 - 0:17
string 0:0 - 0:8
asyncApiVersion 0:10 - 0:17
member 1:0 - 8:0
string 1:0 - 1:10
components 2:2 - 8:0
member 2:2 - 8:0
string 2:2 - 2:9
object 3:4 - 8:0
member 3:4 - 8:0
string 3:4 - 3:8
schema 4:6 - 8:0
member 4:6 - 4:18
string 4:6 - 4:10
string 4:12 - 4:18
member 5:6 - 8:0
string 5:6 - 5:14
array 6:8 - 8:0
string 7:10 - 7:12

We would need to have these items parsed as the expected array type, or if not possible as string elements, similarly to what done in https://github.com/swagger-api/apidom/issues/883 for member values.

char0n commented 3 years ago

Right, this looks as another corner-case and follow up of #812.

char0n commented 2 years ago

First PR fixing this has landed: https://github.com/swagger-api/apidom/pull/941

The above PRs map and fix all the possible cases of empty nodes as documented in YAML 1.2.2 specification.

I'll be building empty node replacement on top of these changes.