Skip to content

feat(openapi3): Import OpenAPI deprecated field as #deprecated directive#9289

Merged
baywet merged 4 commits intomainfrom
copilot/fix-deprecated-decorators-import
Jan 6, 2026
Merged

feat(openapi3): Import OpenAPI deprecated field as #deprecated directive#9289
baywet merged 4 commits intomainfrom
copilot/fix-deprecated-decorators-import

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 5, 2026

OpenAPI documents with deprecated: true on schemas or properties were losing this information during conversion to TypeSpec. The deprecated flag must round-trip as TypeSpec's #deprecated directive.

Changes

Core Implementation

  • Added TypeSpecDirective interface and directives field to TypeSpecDeclaration and TypeSpecModelProperty
  • Created getDirectivesForSchema() to extract deprecated: true from OpenAPI schemas
  • Created generateDirectives() to output #deprecated "deprecated" syntax

Integration Points

  • Updated schema transforms (populateEnum, populateModel, populateUnion, populateScalar) to extract directives
  • Updated model property generation to include directives from schema properties
  • Ensured directives render before decorators in generated TypeSpec

Example

Input OpenAPI:

components:
  schemas:
    Foo:
      type: object
      properties:
        bar:
          type: string
          deprecated: true

Output TypeSpec:

model Foo {
  #deprecated "deprecated"
  bar?: string;
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: /usr/local/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build /usr/local/bin/node s/.b�� sc -p ./tsconfig.build.json sh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: tsp-openapi3: "deprecated" decorators not imported</issue_title>
<issue_description>### Describe the bug

OpenAPI that declares @deprecated does not result in #deprecated on import.

detected as part of the "TypeSpec for Sefaria" hack.

Reproduction

Easiest way to see is to round-trip this model:

model Foo {
  #deprecated "omit"
  bar?: string
}

TSP -> OpenAPI: Playground
Result from importing the OpenAPI output: Playground

model Foo {
  bar?: string;
}

Checklist

<agent_instructions>Make sure you read through the whole discussion and not just the first message.
Make sure you follow conventional commit.
This issue is a feature request not a bug.
Make sure you run the formatting command before committing.
Start by implementing unit tests for the import tool first, then fix the code.
When you're done, run npx @chronus/chronus add to add a new feature changelog entry.</agent_instructions>

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

@baywet Hi @Arithmomaniac Thank you for using the SDK and for reaching out.

I'll shortly assign copilot to go implement a fix for this issue.

For completeness, here is the OpenAPI description that's being imported.

openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths: {}
components:
  schemas:
    Foo:
      type: object
      properties:
        bar:
          type: string
          deprecated: true

Let us know if you have any additional comments or questions.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 5, 2026 20:16
…penAPI

- Added TypeSpecDirective interface to represent directives
- Added directives field to TypeSpecDeclaration and TypeSpecModelProperty
- Created getDirectivesForSchema function to extract deprecated from OpenAPI schemas
- Created generateDirectives function to output directive syntax (#deprecated)
- Updated all model/scalar/enum/union generation to include directives
- Added comprehensive tests for deprecated properties, models, scalars

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix deprecated decorators not imported in OpenAPI feat(openapi3): Import OpenAPI deprecated field as #deprecated directive Jan 5, 2026
Copilot AI requested a review from baywet January 5, 2026 20:33
@baywet baywet marked this pull request as ready for review January 5, 2026 21:45
@baywet baywet enabled auto-merge January 5, 2026 21:45
@microsoft-github-policy-service microsoft-github-policy-service bot added emitter:openapi3 Issues for @typespec/openapi3 emitter openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter labels Jan 5, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jan 5, 2026

Open in StackBlitz

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

commit: c0deb2e

@baywet baywet added this pull request to the merge queue Jan 6, 2026
Merged via the queue into main with commit d87949b Jan 6, 2026
23 checks passed
@baywet baywet deleted the copilot/fix-deprecated-decorators-import branch January 6, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:openapi3 Issues for @typespec/openapi3 emitter openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: tsp-openapi3: "deprecated" decorators not imported

3 participants