api-elements.js icon indicating copy to clipboard operation
api-elements.js copied to clipboard

Documents using reserved API Element names as schema ids fail parsing

Open kylef opened this issue 5 years ago • 0 comments
trafficstars

For example:

openapi: 3.0.3
info:
  title: API
  version: v1
paths:
  '/':
    get:
      summary: Hello
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  "$ref": "#/components/schemas/member"
components:
  schemas:
    member:
      type: object
      properties:
        id:
          type: string

Where member is the element name of a member element, the parser fails on this input:

TypeError: Cannot read property 'element' of undefined
    at isParseResult (/Users/kyle/Projects/apiaryio/api-elements.js/packages/openapi3-parser/lib/predicates.js:12:42)
    at /Users/kyle/Projects/apiaryio/api-elements.js/node_modules/ramda/src/internal/_pipe.js:3:14
    at /Users/kyle/Projects/apiaryio/api-elements.js/node_modules/ramda/src/internal/_arity.js:11:19
    at _ifElse (/Users/kyle/Projects/apiaryio/api-elements.js/node_modules/ramda/src/ifElse.js:39:22)
    at f1 (/Users/kyle/Projects/apiaryio/api-elements.js/node_modules/ramda/src/internal/_curry1.js:19:17)
    at transformMember (/Users/kyle/Projects/apiaryio/api-elements.js/packages/openapi3-parser/lib/parser/parseObject.js:125:32)
    at ParseResult.<anonymous> (/Users/kyle/Projects/apiaryio/api-elements.js/node_modules/minim/lib/primitives/ArrayElement.js:323:23)
    at Array.map (<anonymous>)
    at ParseResult.map (/Users/kyle/Projects/apiaryio/api-elements.js/node_modules/minim/lib/primitives/ArrayElement.js:70:25)
    at ParseResult.fantasy-land/chain (/Users/kyle/Projects/apiaryio/api-elements.js/node_modules/minim/lib/primitives/ArrayElement.js:323:8)

kylef avatar Jul 04 '20 12:07 kylef