Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Empty example object was emitted when the model contains a enum type property #4416

Open
4 tasks done
akishichinibu opened this issue Sep 12, 2024 · 1 comment · May be fixed by #4462
Open
4 tasks done

[Bug]: Empty example object was emitted when the model contains a enum type property #4416

akishichinibu opened this issue Sep 12, 2024 · 1 comment · May be fixed by #4462
Assignees
Labels
bug Something isn't working emitter:openapi3 Issues for @typespec/openapi3 emitter triaged:core

Comments

@akishichinibu
Copy link

akishichinibu commented Sep 12, 2024

Describe the bug

The example for model AA is generated correctly; however, the example of Output becomes an empty object when set the type of property to the enum Types in model A. It seems that this issue will disappear when replacing the type enum with a string literal.

import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi";
import "@typespec/openapi3";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.OpenAPI;

enum Types {
  A: "a";
  B: "b";
}

@example(#{
  type: Types.A,
  a: "a",
})
model A {
  type: Types.A;
  a: string;
}

model B {
  type: Types.B;
  b: int64;
}

@oneOf
@discriminator("type")
union X {
  A;
  B;
}

@example(#{
  x: #{
    type: Types.B,
    b: 4,
  }
})
model Output {
  x: X
}

model AA {
  type: "aa";
  a: string;
}

model BB {
  type: "bb";
  b: int64;
}

@oneOf
@discriminator("type")
union XX {
  AA;
  BB;
}

@example(#{
  xx: #{
    type: "aa",
    a: "aa",
  }
})
model Output2 {
  xx: XX
}

Output:

    Output:
      type: object
      required:
        - x
      properties:
        x:
          $ref: '#/components/schemas/X'
      example:
        x: {}
    Output2:
      type: object
      required:
        - xx
      properties:
        xx:
          $ref: '#/components/schemas/XX'
      example:
        xx:
          type: aa
          a: aa

Reproduction

👇
https://typespec.io/playground?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdNUZb3BlbmFwadwcMyI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwO9AVUmVzdNEVT3BlbkFQSTsKCmVudW3FGHMgewogIEE6ICJhIjsKICBCOiAiYiI7Cn0KCkBleGFtcGxlKCPEI%2BQAijrGMy5BLAogIGHFNCwKfSkKbW9kZWwgQcVLzSjEUmE6IHN0cmluZ8VVxitC0StCxCtiOiBpbnQ2NMZ%2Fb25lT2YKQGRpc2NyaW1pbmF0b3IoIsQ1IikKdW5pb24gWMVIxWdC8wC0eDogxQjPa%2BQAvsVtNMQKfeoAwk91dHB1dMVUeDogWOoAsEHsANwiYeYBK%2FUA2ewA2iJi5AFK%2FwDX9QDX5wDY5gDZ9QDa8ADb5ACV5gDY5QGYxg3xANsyxVjEPVjkAN4%3D&e=%40typespec%2Fopenapi3&options=%7B%7D&version=0.60.x

Checklist

@akishichinibu akishichinibu added the bug Something isn't working label Sep 12, 2024
@akishichinibu akishichinibu changed the title [Bug]: Empty example object was emitted when using the model's properties contain a enum Type [Bug]: Empty example object was emitted when the model's property contains a enum Type Sep 12, 2024
@akishichinibu akishichinibu changed the title [Bug]: Empty example object was emitted when the model's property contains a enum Type [Bug]: Empty example object was emitted when the model contains a enum type property Sep 12, 2024
@timotheeguerin
Copy link
Member

Simplified repro

Seems to be a combination of using an enum property inside a union

@timotheeguerin timotheeguerin added the emitter:openapi3 Issues for @typespec/openapi3 emitter label Sep 12, 2024
@markcowl markcowl added this to the [2024] October milestone Sep 16, 2024
@timotheeguerin timotheeguerin self-assigned this Sep 17, 2024
@timotheeguerin timotheeguerin linked a pull request Sep 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working emitter:openapi3 Issues for @typespec/openapi3 emitter triaged:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants