RepreZen / KaiZen-OpenApi-Parser

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

Task/131 Support models with reference cycles #138

Closed andylowry closed 6 years ago

andylowry commented 6 years ago

@maybeec This should fix the problem with cycles. See the commit message on https://github.com/RepreZen/KaiZen-OpenApi-Parser/pull/138/commits/e351eec49e9e6e92c997fd761ae9d4c0c8c2ee94 for a summary of the changes, except that there's an important typo in that commit message. In the 4-step process, step 2 should read:

  1. That "placeholder" overlay object is registered in the reference registry as the overlay corresponding to the actual JsonNode passed to the factory method.

    I'll merge this and deploy a new version tomorrow morning.

Thanks very much for reporting this with a simple model, and for your investigation. The treatment of references is complex. There are two issues that should make things considerably easier to manage when I get to them: #123 and #119.

123 will just make JsonOverlay easier to work with in isolation, rather than having all the OAS stuff along for the ride. #119, though, should give me a much simpler approach to dealing with references in general. Currently the whole purpose of ChildOverlay is to make it possible for the API to expose reference details and still share objects created from the referenced JSON. The new approach intends to use an inspector class that can attach to any overlay object and provide information on references, parentage, etc. This should mean I can get rid of all the ChildOverlays and only interpose a delegating ReferenceOverlay when references are actually encountered. It should be much more efficient and significantly simpler, and it'll mean an end to polluting the API proper with methods supporting meta-features like reference inspection, parenting, serialization, etc.

maybeec commented 6 years ago

Great to hear! Thank you so much. Looking forward to the next release!

andylowry commented 6 years ago

Malte, the new release is available on maven central.

On 3/2/2018 3:19 AM, Malte Brunnlieb wrote:

Great to hear! Thank you so much. Looking forward to the next release!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RepreZen/KaiZen-OpenApi-Parser/pull/138#issuecomment-369852994, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGog5jQggx-52f3slbeVpEXLlpUU7uAks5taQCEgaJpZM4SZY2a.

andylowry commented 6 years ago

... v0.0.3.201803021300

On 3/2/2018 8:51 AM, Andy Lowry wrote:

Malte, the new release is available on maven central.

On 3/2/2018 3:19 AM, Malte Brunnlieb wrote:

Great to hear! Thank you so much. Looking forward to the next release!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RepreZen/KaiZen-OpenApi-Parser/pull/138#issuecomment-369852994, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGog5jQggx-52f3slbeVpEXLlpUU7uAks5taQCEgaJpZM4SZY2a.

maybeec commented 6 years ago

Great to hear! Thanks!

maybeec commented 6 years ago

Just checked version v0.0.3.201803021300

with this document:

openapi: 3.0.0
servers:
  - url: 'http://any'
info:
  title: any
  description: any
  version: 0.0.0
paths:
  /customMethod:
    get:
      operationId: customMethod
      responses:
        '200':
          description: Custom Method
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SampleData'
components:
  schemas:
    SampleData:
      x-component: comp
      type: object
      properties:
        mainData:
          type: object
          description: a single ref to MoreData (one-to-one)
          $ref: '#components/schemas/MoreData'
    MoreData:
      x-component: comp
      type: object
      any:
        counter:
          type: integer
          description: any

resulting in

java.lang.NullPointerException
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.fillWithJson(MapOverlay.java:62)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.<init>(MapOverlay.java:41)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:180)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:151)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.createAndRegister(OverlayFactory.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildMapOverlay.<init>(ChildMapOverlay.java:26)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.createChildMap(PropertiesOverlay.java:142)
    at com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.elaborateChildren(SchemaImpl.java:1313)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.ensureElaborated(PropertiesOverlay.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.maybeElaborateChildrenAtCreation(PropertiesOverlay.java:44)
    at com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.<init>(SchemaImpl.java:51)
    at com.reprezen.kaizen.oasparser.ovl3.SchemaImpl$1._create(SchemaImpl.java:1442)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay$PropertiesOverlayFactory.createAndRegister(PropertiesOverlay.java:214)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:26)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:58)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.createChild(PropertiesOverlay.java:126)
    at com.reprezen.kaizen.oasparser.ovl3.MediaTypeImpl.elaborateChildren(MediaTypeImpl.java:253)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.ensureElaborated(PropertiesOverlay.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.maybeElaborateChildrenAtCreation(PropertiesOverlay.java:44)
    at com.reprezen.kaizen.oasparser.ovl3.MediaTypeImpl.<init>(MediaTypeImpl.java:32)
    at com.reprezen.kaizen.oasparser.ovl3.MediaTypeImpl$1._create(MediaTypeImpl.java:300)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay$PropertiesOverlayFactory.createAndRegister(PropertiesOverlay.java:214)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.fillWithJson(MapOverlay.java:61)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.<init>(MapOverlay.java:41)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:180)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:151)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.createAndRegister(OverlayFactory.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildMapOverlay.<init>(ChildMapOverlay.java:26)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.createChildMap(PropertiesOverlay.java:142)
    at com.reprezen.kaizen.oasparser.ovl3.ResponseImpl.elaborateChildren(ResponseImpl.java:283)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.ensureElaborated(PropertiesOverlay.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.maybeElaborateChildrenAtCreation(PropertiesOverlay.java:44)
    at com.reprezen.kaizen.oasparser.ovl3.ResponseImpl.<init>(ResponseImpl.java:33)
    at com.reprezen.kaizen.oasparser.ovl3.ResponseImpl$1._create(ResponseImpl.java:327)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay$PropertiesOverlayFactory.createAndRegister(PropertiesOverlay.java:214)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.fillWithJson(MapOverlay.java:61)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.<init>(MapOverlay.java:41)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:180)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:151)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.createAndRegister(OverlayFactory.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildMapOverlay.<init>(ChildMapOverlay.java:26)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.createChildMap(PropertiesOverlay.java:142)
    at com.reprezen.kaizen.oasparser.ovl3.OperationImpl.elaborateChildren(OperationImpl.java:719)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.ensureElaborated(PropertiesOverlay.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.maybeElaborateChildrenAtCreation(PropertiesOverlay.java:44)
    at com.reprezen.kaizen.oasparser.ovl3.OperationImpl.<init>(OperationImpl.java:45)
    at com.reprezen.kaizen.oasparser.ovl3.OperationImpl$1._create(OperationImpl.java:791)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay$PropertiesOverlayFactory.createAndRegister(PropertiesOverlay.java:214)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.fillWithJson(MapOverlay.java:61)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.<init>(MapOverlay.java:41)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:180)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:151)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.createAndRegister(OverlayFactory.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildMapOverlay.<init>(ChildMapOverlay.java:26)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.createChildMap(PropertiesOverlay.java:142)
    at com.reprezen.kaizen.oasparser.ovl3.PathImpl.elaborateChildren(PathImpl.java:435)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.ensureElaborated(PropertiesOverlay.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.maybeElaborateChildrenAtCreation(PropertiesOverlay.java:44)
    at com.reprezen.kaizen.oasparser.ovl3.PathImpl.<init>(PathImpl.java:156)
    at com.reprezen.kaizen.oasparser.ovl3.PathImpl$1._create(PathImpl.java:481)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay$PropertiesOverlayFactory.createAndRegister(PropertiesOverlay.java:214)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.fillWithJson(MapOverlay.java:61)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay.<init>(MapOverlay.java:41)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:180)
    at com.reprezen.kaizen.oasparser.jsonoverlay.MapOverlay$MapOverlayFactory._create(MapOverlay.java:151)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.createAndRegister(OverlayFactory.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildOverlay.<init>(ChildOverlay.java:65)
    at com.reprezen.kaizen.oasparser.jsonoverlay.ChildMapOverlay.<init>(ChildMapOverlay.java:26)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.createChildMap(PropertiesOverlay.java:142)
    at com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.elaborateChildren(OpenApi3Impl.java:1104)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.ensureElaborated(PropertiesOverlay.java:50)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay.maybeElaborateChildrenAtCreation(PropertiesOverlay.java:44)
    at com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.<init>(OpenApi3Impl.java:110)
    at com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl$1._create(OpenApi3Impl.java:1206)
    at com.reprezen.kaizen.oasparser.jsonoverlay.PropertiesOverlay$PropertiesOverlayFactory.createAndRegister(PropertiesOverlay.java:214)
    at com.reprezen.kaizen.oasparser.jsonoverlay.OverlayFactory.create(OverlayFactory.java:43)
    at com.reprezen.kaizen.oasparser.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:79)
    at com.reprezen.kaizen.oasparser.OpenApiParser.parse(OpenApiParser.java:74)
    at com.reprezen.kaizen.oasparser.OpenApi3Parser.parse(OpenApi3Parser.java:47)
    at com.capgemini.cobigen.openapiplugin.inputreader.OpenAPIInputReader.read(OpenAPIInputReader.java:472)
    at com.capgemini.cobigen.openapiplugin.unittest.inputreader.OpenAPIInputReaderTest.getInputs(OpenAPIInputReaderTest.java:214)
    at com.capgemini.cobigen.openapiplugin.unittest.inputreader.OpenAPIInputReaderTest.testPropertyRefOneToOne(OpenAPIInputReaderTest.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

@andylowry Maybe it gets fixed with the new PR #146, but I just want to keep you updated. Maybe you can check the above document as well.