nomisRev / OpenAPI-kt

Kotlin Multiplatform Typed OpenAPI Document Parser (KotlinX) with Typed Secondary Custom ADT for inspection, typed transformations, code generation, etc.
8 stars 1 forks source link

An operation is not implemented: Name Generated for inline objects of unions not yet supported. #90

Open martinbonnin opened 6 days ago

martinbonnin commented 6 days ago

Not 100% sure what's happening here. I think the following is valid?

openapi: 3.0.1
info:
  title: Hello World API
  version: '1.0'
paths:
  /hello-world:
    get:
      operationId: hello-world
      responses:
        '200':
          description: updated
          content:
            application/json:
              schema:
                allOf:
                  - type: object
                    properties:
                      id:
                        type: integer
                  - type: object
                    properties:
                      username:
                        type: string
nomisRev commented 4 days ago

Hey @martinbonnin,

Okay, I see. Without having looked at the code, I think this might be just a branch missing somewhere in the code where I left a TODO. Reason being that there is no name defined for the allOf type here, so a name needs to be generated.

A generalised name generation could be:

sealed interface GetHelloWorldResponse
@JvmInline value class First(val id: Int): GetHelloWorldResponse
@JvmInline value class Second(val username: String): GetHelloWorldResponse

Much more desirable would be:

sealed interface GetHelloWorldResponse
@JvmInline value class Id(val id: Int): GetHelloWorldResponse
@JvmInline value class Username(val value: String): GetHelloWorldResponse

I'm open to building a special case into the (not yet overrideable) name generation part, to detect that if a name needs to be generated for an object with a single property, it can use the property name for name generation. In the case there is no conflict in the property names of the different subtypes of course.

Thank you for opening the issues 🙏

martinbonnin commented 4 days ago

It's an allOf() though so my understanding is more that it should contain all properties?

@JvmInline value class GetHelloWorldResponse(val id: Int, val value: String)