ghostbuster91 / sttp-openapi-generator

Generate sttp client from openapi specification with ease!
Apache License 2.0
32 stars 11 forks source link

Fails to generate for Grist spec #270

Open nafg opened 1 year ago

nafg commented 1 year ago

The spec is at https://raw.githubusercontent.com/gristlabs/grist-help/master/api/grist.yml

The error is:

grist.compileOpenApiSpec scala.MatchError: class Schema {
    type: null
    format: null
    $ref: null
    description: This can be an integer id, or a string subdomain (e.g. `gristlabs`), or `current` if the org is implied by the domain in the url
    title: null
    multipleOf: null
    maximum: null
    exclusiveMaximum: null
    minimum: null
    exclusiveMinimum: null
    maxLength: null
    minLength: null
    pattern: null
    maxItems: null
    minItems: null
    uniqueItems: null
    maxProperties: null
    minProperties: null
    required: null
    not: null
    properties: null
    additionalProperties: null
    nullable: null
    readOnly: null
    writeOnly: null
    example: null
    externalDocs: null
    deprecated: null
    discriminator: null
    xml: null
} (of class io.swagger.v3.oas.models.media.Schema)
    io.github.ghostbuster91.sttp.client3.openapi.SafeSchema$.apply(SafeOpenApi.scala:249)
    io.github.ghostbuster91.sttp.client3.openapi.SafeComponents.$anonfun$schemas$2(SafeOpenApi.scala:34)
    scala.collection.MapView$MapValues.$anonfun$iterator$1(MapView.scala:119)
    scala.collection.Iterator$$anon$9.next(Iterator.scala:584)
    scala.collection.mutable.Growable.addAll(Growable.scala:62)
    scala.collection.mutable.Growable.addAll$(Growable.scala:57)
    scala.collection.immutable.MapBuilderImpl.addAll(Map.scala:690)
    scala.collection.immutable.Map$.from(Map.scala:641)
    scala.collection.IterableOnceOps.toMap(IterableOnce.scala:1293)
    scala.collection.IterableOnceOps.toMap$(IterableOnce.scala:1292)
    scala.collection.AbstractIterable.toMap(Iterable.scala:933)
    io.github.ghostbuster91.sttp.client3.openapi.SafeComponents.$anonfun$schemas$1(SafeOpenApi.scala:34)
    scala.Option.map(Option.scala:242)
    io.github.ghostbuster91.sttp.client3.openapi.SafeComponents.schemas(SafeOpenApi.scala:34)
    io.github.ghostbuster91.sttp.client3.openapi.OpenApiEnumFlattener$.$anonfun$collectComponentsSchemas$1(OpenApiEnumFlattener.scala:38)
    scala.Option.map(Option.scala:242)
    io.github.ghostbuster91.sttp.client3.openapi.OpenApiEnumFlattener$.collectComponentsSchemas(OpenApiEnumFlattener.scala:37)
    io.github.ghostbuster91.sttp.client3.openapi.OpenApiEnumFlattener$.flatten(OpenApiEnumFlattener.scala:10)
    io.github.ghostbuster91.sttp.client3.Codegen.$anonfun$generate$1(Codegen.scala:27)
    io.github.ghostbuster91.sttp.client3.openapi.SafeOpenApiParser.$anonfun$parse$1(SafeOpenApiParser.scala:23)
    scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:183)
    scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:179)
    scala.collection.immutable.List.foldLeft(List.scala:79)
    io.github.ghostbuster91.sttp.client3.openapi.SafeOpenApiParser.parse(SafeOpenApiParser.scala:23)
    io.github.ghostbuster91.sttp.client3.Codegen.generate(Codegen.scala:30)
    io.github.ghostbuster91.sttp.client3.OpenApiCodegenScalaModule.$anonfun$compileOpenApiSpec$3(OpenApiCodegenScalaModule.scala:73)
    scala.collection.immutable.List.map(List.scala:246)
    io.github.ghostbuster91.sttp.client3.OpenApiCodegenScalaModule.$anonfun$compileOpenApiSpec$2(OpenApiCodegenScalaModule.scala:60)
    mill.define.Task$TraverseCtx.evaluate(Task.scala:380)
nafg commented 1 year ago

I fixed it up a bunch. Now it works with Guardrail (except for the server templating which I can string-replace in my build). Here is the fixed-up file: https://github.com/gristlabs/grist-help/pull/243/files#diff-ed8057bfb897295d502b09b2a80b95fb6ee9de4272cfa2c100922d3c542af030

However, it still fails with this generator. Here is the new error:

grist.compileOpenApiSpec scala.MatchError: class ObjectSchema {
    class Schema {
        type: object
        format: null
        $ref: #/components/schemas/User
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
    }
} (of class io.github.ghostbuster91.sttp.client3.openapi.SafeObjectSchema)
ghostbuster91 commented 1 year ago

Thanks for the report. I will try to finish rewriting the parser soon. Hopefully it will fix it