codified icon indicating copy to clipboard operation
codified copied to clipboard

Open API 3 Specs Generation

Open dacloutier opened this issue 9 months ago • 2 comments

This is probably more of a limitation with the Open Api spec generation, but I'm curious as to why this is happening.

I'm building a proof of concept using the Open Api Schema annotations to generate the Open Api Spec document. And I get a spec document that doesn't seem to be usable to figure out the deserialization.

There doesn't seem to be a link between the CodifiedEnum and the Known Unknown objects.

Here's a code snippet of the Response class:

@ApiModel(
    description = "An order from a customer"
)
data class Order(
//...
    @Schema(
        name = "status",
        example = "DRAFT",
        description = "The status of the order",
        required = true
    )
    @Serializable(with = OrderStatus.CodifiedSerializer::class)
    val status: CodifiedEnum<OrderStatus, String>,
// ...
}

Here's a code snippet of the OrderStatus enum:

@ApiModel(
    description = "All order statuses"
)
enum class OrderStatus(override val code: String) : Codified<String> {
    DRAFT("DRAFT"), PROCESSED("PROCESSED"), CANCELLED("CANCELLED");

    object CodifiedSerializer : KSerializer<CodifiedEnum<OrderStatus, String>> by codifiedEnumSerializer()
}

The generated open api spec:

    Order:
      required:
      - id
      - status
      type: object
      properties:
        id:
          type: string
          description: The order identifier
          example: 2c93808457d787030157e02e7be22210
        status:
          $ref: '#/components/schemas/CodifiedEnumOrderStatusString'
    CodifiedEnumOrderStatusString:
      type: object
      description: The status of the order
      example: DRAFT
      allOf:
      - $ref: '#/components/schemas/CodifiedEnum'
    CodifiedEnum:
      type: object
    Known:
      required:
      - value
      type: object
      allOf:
      - $ref: '#/components/schemas/CodifiedEnumOrderStatusString'
      - type: object
        properties:
          value:
            type: string
      - $ref: '#/components/schemas/CodifiedEnum'
    Unknown:
      required:
      - value
      type: object
      allOf:
      - $ref: '#/components/schemas/CodifiedEnumOrderStatusString'
      - type: object
        properties:
          value:
            type: object
      - $ref: '#/components/schemas/CodifiedEnum'

dacloutier avatar Oct 05 '23 20:10 dacloutier