Skip to content

tsp-openapi3 - Not escaping keywords in union variants #7724

@timotheeguerin

Description

@timotheeguerin

Discussed in #7723

Originally posted by joprice June 24, 2025
When generating typespec from an openapi schema, with a component definition like

 "ComposerStep": {
          "oneOf": [
            {
              "$ref": "#/components/schemas/ComposerStepInit"
            },
            {
              "$ref": "#/components/schemas/ComposerStepContinue"
            },
            {
              "$ref": "#/components/schemas/ComposerStepSuggestions"
            }
          ],
          "discriminator": {
            "propertyName": "tag",
            "mapping": {
              "init": "#/components/schemas/ComposerStepInit",
              "continue": "#/components/schemas/ComposerStepContinue",
              "suggestions": "#/components/schemas/ComposerStepSuggestions"
            }
          }
        }

The union case name "init" is not escaped with backticks, resulting in a syntax error:

@discriminated(#{ envelope: "none", discriminatorPropertyName: "tag" })
@oneOf
union ComposerStep {    
  init: ComposerStepInit
  continue: ComposerStepContinue
  suggestions: ComposerStepSuggestions
}

I found a test checking for keyword escapes, but perhaps it's not hitting this node in the ast, or "init" is not included in the reserved word list.</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions