Skip to content

[Bug]: enum examples are not correctly translated to OpenAPI using @opExample. #9229

@sindhukapa

Description

@sindhukapa

Describe the bug

When defining a response with an enum in TypeSpec, the example value specified for that enum is not correctly translated into the generated OpenAPI spec. Instead of including the example value, the generated OpenAPI spec embeds it as an empty JSON object {}.

This issue occurs in both TypeSpec 1.3 , and persists even after upgrading When defining a response with an enum in TypeSpec, the example value specified for that enum is not correctly translated into the generated OpenAPI spec. Instead of including the example value, the generated OpenAPI spec embeds it as an empty JSON object {}.

This issue occurs in both TypeSpec 1.3, and persists even after upgrading to latest 1.7.

Reproduction

Steps to Reproduce:

Define a TypeSpec model with an enum in a response, and specify an example value.

Export the service to OpenAPI.

Observe that the example in the OpenAPI spec is {} instead of the enum example.

In this example, Version 1 uses an enum and includes an example, but when we check the generated OpenAPI spec, the example appears as {} instead of the actual value. In contrast, Version 2 includes an example without using an enum, and it is correctly translated into the OpenAPI spec.

Link to Playground with example:

Checklist

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions