Kotlin / dataframe

Structured data processing in Kotlin
https://kotlin.github.io/dataframe/overview.html
Apache License 2.0
834 stars 63 forks source link

OpenAPI: broken error reporting and code generation for two-dimensional array inside an object #255

Open einsweniger opened 1 year ago

einsweniger commented 1 year ago

dataframe: 0.9.1

error reporting

I had to check why the code generation fails by running my input through one of the already set-up tests in this repository, because the only error message I received was: Error while reading types-only from data at http://localhost:5118/swagger/v1/swagger.json: java.lang.IllegalArgumentException: Unknown stream format

code generation

code generation fails, given an object/map of variably named, two dimensional arrays. As an example in typescript:

export interface NamedTables {
    tables?: { [key: string]: Array<Array<string>>; };
}

To reproduce, use the OpenApi description of it:

openapi: 3.0.1
info:
  title: nested example
  version: '1.0'
paths:
  /api/showTables:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NamedTables'
      responses:
        '200':
          description: Success
components:
  schemas:
    NamedTables:
      type: object
      properties:
        tables:
          type: object
          additionalProperties:
            type: array
            items:
              type: array
              items:
                type: string
      additionalProperties: false

I can see this is an edge-case, but I thought I'd mention it, since this is a valid OpenApi description. The error that I got when testing it was:

class io.swagger.v3.oas.models.media.MapSchema cannot be cast to class io.swagger.v3.oas.models.media.ArraySchema java.lang.ClassCastException: class io.swagger.v3.oas.models.media.MapSchema cannot be cast to class io.swagger.v3.oas.models.media.ArraySchema (io.swagger.v3.oas.models.media.MapSchema and io.swagger.v3.oas.models.media.ArraySchema are in unnamed module of loader 'app') at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.toFieldType(readOpenapi.kt:847) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.toMarker(readOpenapi.kt:556) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.toFieldType(readOpenapi.kt:1003) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.toMarker(readOpenapi.kt:487) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.toMarker$default(readOpenapi.kt:290) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.toMarkers$lambda$9$lambda$8(readOpenapi.kt:207) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.toMarkers(readOpenapi.kt:244) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.readOpenApi(readOpenapi.kt:105) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.readOpenApiAsString(readOpenapi.kt:70) at org.jetbrains.kotlinx.dataframe.io.ReadOpenapiKt.readOpenApiAsString$default(readOpenapi.kt:59) at org.jetbrains.kotlinx.dataframe.io.OpenApi.readCodeForGeneration(OpenApi.kt:65) at OpenApiTests.execGeneratedCode(OpenApiTests.kt:35) at OpenApiTests.Advanced test Petstore Json(OpenApiTests.kt:183) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38) at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33) at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94) at jdk.proxy1/jdk.proxy1.$Proxy2.processTestClass(Unknown Source) at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176) at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129) at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100) at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60) at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56) at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133) at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71) at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69) at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Jolanrensen commented 1 year ago

Thanks! Looks like it should definitely work, I'll check it out :)