cjbooms / fabrikt

Generates Kotlin Code from OpenApi3 Specifications
Apache License 2.0
157 stars 41 forks source link

Integer Parameter List won't build #237

Open thejeff77 opened 1 year ago

thejeff77 commented 1 year ago

Build Error:

Task :fabrikt-client:compileKotlin FAILED e: /Users/me@company.com/Projects/gha-kotlin-client-generate/fabrikt-client/src/main/kotlin/com/company/client/V1SomeresourceClient.kt: (35, 24): Type mismatch: inferred type is List? but List? was expected

For spec file:

{
    "openapi": "3.0.1",
    "info": {
        "title": "Some Resource Service",
        "description": "Microservice for some resource",
        "version": "v0.0.1"
    },
    "servers": [
        {
            "url": "https://resource-service.com",
            "description": "Generated server url"
        }
    ],
    "paths": {
        "/v1/someresource": {
            "delete": {
                "operationId": "deleteSomeResource",
                "parameters": [
                    {
                        "name":"ids",
                        "in":"query",
                        "required":false,
                        "schema":{
                            "type":"array",
                            "items":{
                                "type":"integer"
                            }
                        }
                    }
                ]
            }
        }
    },
    "components": {
        "schemas": {
        }
    }
}
cjbooms commented 1 year ago

Fabrikt has only limited support for generating from inline schemas, and doesn't handle unlined schemas in parameter sections. The issue is fabrikt does not have a unique class name to use when the schema is inlined like this.

Migrate the inline parameter definition to reference a schema in the schemas section as per examples.

thejeff77 commented 1 year ago

Gotcha, can I keep this open as a feature request?

Our use case is code-first generated openapi files via springdoc. I.E. we write code, the app runs, and it creates the openapi spec at runtime.

It is tedious and a learning curve to manipulate how springdoc creates spec files, although we have a way to work around this, it isn't clean. It would be high value for us to have fabrikt work with inline definitions in cases like these.

For classname, perhaps this could be generated/made-up based on information available.

For example, it seems to default to "Parameter", it could perhaps generate names like Parameter1, Parameter2, and perhaps incorporate type in there. For this case, perhaps LongArrayParameter would be a good generated class name. The code would have to know how to make sure it doesn't have class name overlap, and how to avoid that when adding new class names.

Thanks