RepreZen / KaiZen-OpenApi-Parser

High-performance Parser, Validator, and Java Object Model for OpenAPI 3.x
130 stars 31 forks source link

IllegalStateException with $ref of $ref schema #163

Open jmini opened 6 years ago

jmini commented 6 years ago

This might be a corner case, but right now the parser do not support referenced of referenced schemas. With this OAS3 specification:

openapi: 3.0.1
info:
  title: chained redirects test
  version: '1.0'
servers:
  - url: 'http://localhost:8000/'
paths:
  /some/ping:
    get:
      operationId: pingGet
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SomeObj'
components:
  schemas:
    SomeObj:
      $ref: '#/components/schemas/SomeOther'
    SomeOther:
      type: object
      properties:
        s1:
          type: string
        s3:
          type: string

I get this error:

Exception in thread "main" java.lang.IllegalStateException: Referenced object is not compatible with referencing site
    at com.reprezen.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:53)
    at com.reprezen.jsonoverlay.MapOverlay.fillWithJson(MapOverlay.java:73)
    at com.reprezen.jsonoverlay.MapOverlay.elaborate(MapOverlay.java:50)
    at com.reprezen.jsonoverlay.OverlayFactory.create(OverlayFactory.java:44)
    at com.reprezen.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.jsonoverlay.ChildMapOverlay.<init>(ChildMapOverlay.java:26)
    at com.reprezen.jsonoverlay.PropertiesOverlay.createChildMap(PropertiesOverlay.java:174)
    at com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.elaborateChildren(OpenApi3Impl.java:840)
    at com.reprezen.jsonoverlay.PropertiesOverlay.ensureElaborated(PropertiesOverlay.java:68)
    at com.reprezen.jsonoverlay.PropertiesOverlay.maybeElaborateChildrenAtCreation(PropertiesOverlay.java:62)
    at com.reprezen.jsonoverlay.PropertiesOverlay.elaborate(PropertiesOverlay.java:199)
    at com.reprezen.jsonoverlay.OverlayFactory.create(OverlayFactory.java:44)
    at com.reprezen.jsonoverlay.OverlayFactory.create(OverlayFactory.java:26)
    at com.reprezen.kaizen.oasparser.OpenApiParser.parse(OpenApiParser.java:101)
    at com.reprezen.kaizen.oasparser.OpenApiParser.parse(OpenApiParser.java:90)
    at com.reprezen.kaizen.oasparser.OpenApiParser.parse(OpenApiParser.java:67)
    at com.reprezen.kaizen.oasparser.OpenApi3Parser.parse(OpenApi3Parser.java:43)
    at ...