Skip to content

import tool - composition of object + enum not handled correctly #10040

@baywet

Description

@baywet

The following OpenAPI description

components:
  schemas:
    VoiceIdsOrCustomVoice:
      title: Voice
      description: |
        A built-in voice name or a custom voice reference.
      anyOf:
        - $ref: '#/components/schemas/VoiceIdsShared'
        - type: object
          description: Custom voice reference.
          additionalProperties: false
          required:
            - id
          properties:
            id:
              type: string
    VoiceIdsShared:
      example: ash
      anyOf:
        - type: string
        - type: string
          enum:
            - alloy
            - ash
            - ballad
            - coral
            - echo
            - sage
            - shimmer
            - verse
            - marin
            - cedar

Results in the following TypeSpec definition after import

/** Custom voice reference. */
@summary("Voice")
model VoiceIdsOrCustomVoice {
  /** The custom voice ID, e.g. `voice_1234`. */
  id: string;
}

union VoiceIdsShared {
  string,

    | "alloy"
    | "ash"
    | "ballad"
    | "coral"
    | "echo"
    | "sage"
    | "shimmer"
    | "verse"
    | "marin"
    | "cedar",
}

But should really be

/** Custom voice reference. */
@summary("Voice")
union VoiceIdsOrCustomVoice {
  VoiceIdsShared,
  {
    id: string,
  },
}

union VoiceIdsShared {
  string,

    | "alloy"
    | "ash"
    | "ballad"
    | "coral"
    | "echo"
    | "sage"
    | "shimmer"
    | "verse"
    | "marin"
    | "cedar",
}

Interestingly enough, the following input OpenAPI description works as expected even though it's more complex.

components:
  schemas:
    VoiceIdsOrCustomVoice:
      title: Voice
      description: |
        A built-in voice name or a custom voice reference.
      anyOf:
        - allOf:
            - $ref: '#/components/schemas/VoiceIdsShared'
          type: string
        - type: object
          description: Custom voice reference.
          additionalProperties: false
          required:
            - id
          properties:
            id:
              type: string
    VoiceIdsShared:
      example: ash
      anyOf:
        - type: string
        - type: string
          enum:
            - alloy
            - ash
            - ballad
            - coral
            - echo
            - sage
            - shimmer
            - verse
            - marin
            - cedar

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopenapi3:converterIssues for @typespec/openapi3 openapi to typespec converter

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions