Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

When importing OpenAPI schemas with anyOf/oneOf containing {type: "integer", format: "unixtime"} and {type: "null"}, the converter was dropping the @encode(DateTimeKnownEncoding.unixTimestamp, integer) decorator.

Before:

finished_at:
  anyOf:
    - type: integer
      format: unixtime
    - type: "null"
finished_at?: utcDateTime | null  // Missing @encode decorator

After:

@encode(DateTimeKnownEncoding.unixTimestamp, integer)
finished_at?: utcDateTime | null

Changes

  • decorators.ts: Modified getDecoratorsForSchema to extract format property from anyOf/oneOf members when not present at schema root
  • Tests: Added coverage for both anyOf and oneOf union variants with unixtime format
  • Changelog: Added fix entry for @typespec/openapi3
Original prompt

This section details on the original issue you should resolve

<issue_title>converter - import anyOf unixtime missed decorator</issue_title>
<issue_description>When importing this OpenAPI schema

components:
  schemas:
    FineTuningJob:
      type: object
      properties:
        created_at:
          type: integer
          description: The Unix timestamp (in seconds) for when the fine-tuning job was created.
          format: unixtime

I get the following result

@encode(DateTimeKnownEncoding.unixTimestamp, integer) created_at: utcDateTime

However, if the schema is instead an anyOf with null, I get the following TypeSpec result, which misses the encode decorator

components:
  schemas:
    FineTuningJob:
      type: object
      properties:
        finished_at:
          anyOf:
            - type: integer
              description: The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be null if the fine-tuning job is still running.
              format: unixtime
            - type: "null"
finished_at: utcDateTime | null

The decorator should be present whenever a union type with null is emitted.</issue_description>

<agent_instructions>run the formatting script before any commit.
when you're done with all the changes, run npx @chronus/chronus add to add a bugfix entry to the changelog.
use conventional commits.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 9, 2025 16:51
…rmat

When a property schema uses anyOf/oneOf with a union of {type: "integer", format: "unixtime"} and {type: "null"}, the converter now correctly emits the @encode(DateTimeKnownEncoding.unixTimestamp, integer) decorator along with the utcDateTime | null type.

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
- Remove redundant empty array fallback
- Add proper type checking for memberType to handle edge cases
- Improve code structure for better null safety

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing decorator for anyOf unixtime in converter fix(openapi3): emit @encode decorator for anyOf/oneOf with unixtime format Dec 9, 2025
Copilot AI requested a review from baywet December 9, 2025 17:11
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 9, 2025

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/openapi@9164
npm i https://pkg.pr.new/microsoft/typespec/@typespec/openapi3@9164

commit: 00205b9

@baywet baywet marked this pull request as ready for review December 9, 2025 17:25
@baywet baywet enabled auto-merge December 9, 2025 17:25
…-20.md

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

All changed packages have been documented.

  • @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

Import OpenAPI schemas with anyOf/oneOf containing unixtime format correctly emits @encode(DateTimeKnownEncoding.unixTimestamp, integer) decorator for nullable utcDateTime properties

@baywet baywet added this pull request to the merge queue Dec 9, 2025
Merged via the queue into main with commit c3eb172 Dec 9, 2025
23 checks passed
@baywet baywet deleted the copilot/fix-anyof-unixtime-decorator branch December 9, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

converter - import anyOf unixtime missed decorator

3 participants