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]: Nullable Generic Scalar generated as object #5156

Open
4 tasks done
maennchen opened this issue Nov 20, 2024 · 0 comments
Open
4 tasks done

[Bug]: Nullable Generic Scalar generated as object #5156

maennchen opened this issue Nov 20, 2024 · 0 comments
Labels
bug Something isn't working needs-area

Comments

@maennchen
Copy link

Describe the bug

When using a scalar as a generic, the OpenAPI output sometimes is defined as type object even though the file is not an object.

Using typespec v0.62.0

Reproduction

Typespec

scalar ISODate extends string;

alias RangeUnbound = null;

model Range<Inner> {
  from: Inner | RangeUnbound;
  to: Inner | RangeUnbound;
  lowerInclusive: boolean;
  upperInclusive: boolean;
}

model ISODateRange is Range<ISODate> {}

OpenAPI Output

ISODateRange:
  type: object
  required:
    - from
    - to
    - lowerInclusive
    - upperInclusive
  properties:
    from:
      type: object
      allOf:
        - $ref: '#/components/schemas/ISODate'
      nullable: true
    to:
      type: object
      allOf:
        - $ref: '#/components/schemas/ISODate'
      nullable: true
    lowerInclusive:
      type: boolean
    upperInclusive:
      type: boolean

Expected

RangeUnbound:
  type: null
ISODateRange:
  type: object
  required:
    - from
    - to
    - lowerInclusive
    - upperInclusive
  properties:
    from:
      oneOf:
        - $ref: '#/components/schemas/ISODate'
        - $ref: '#/components/schemas/RangeUnbound'
    to:
      oneOf:
        - $ref: '#/components/schemas/ISODate'
        - $ref: '#/components/schemas/RangeUnbound'
    lowerInclusive:
      type: boolean
    upperInclusive:
      type: boolean

or

ISODateRange:
  type: object
  required:
    - from
    - to
    - lowerInclusive
    - upperInclusive
  properties:
    from:
      type: string
      nullable: true
    to:
      type: string
      nullable: true
    lowerInclusive:
      type: boolean
    upperInclusive:
      type: boolean

Checklist

@maennchen maennchen added the bug Something isn't working label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-area
Projects
None yet
Development

No branches or pull requests

1 participant