Skip to content

Fix OpenAPI import: preserve description and decorators for anyOf/oneOf with null#8514

Merged
baywet merged 10 commits intomainfrom
copilot/fix-8513
Sep 24, 2025
Merged

Fix OpenAPI import: preserve description and decorators for anyOf/oneOf with null#8514
baywet merged 10 commits intomainfrom
copilot/fix-8513

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 22, 2025

The OpenAPI 3.1 import tool was losing description and decorator information when converting schemas with anyOf/oneOf containing a definition + null type. This is a common pattern in OpenAPI 3.1 as an equivalent to nullable: true from OpenAPI 3.0.

Before this fix:

# OpenAPI 3.1 schema
ReasoningEffort:
  anyOf:
    - type: string
      enum: [minimal, low, medium, high]
      default: medium
      description: "Constrains effort on reasoning for reasoning models..."
    - type: 'null'

Generated incomplete TypeSpec:

union ReasoningEffort {
  "minimal" | "low" | "medium" | "high",
  null,
}

After this fix:

/**
 * Constrains effort on reasoning for reasoning models...
 */
union ReasoningEffort {
  "minimal" | "low" | "medium" | "high" = "medium",
  null,
}

Changes Made

  1. Enhanced union metadata extraction: Added logic to identify and extract descriptions and decorators from meaningful (non-null) members in anyOf/oneOf scenarios.

  2. Support for type arrays: Fixed handling of OpenAPI 3.1 type arrays like ["string", "null"] to properly preserve constraints and descriptions.

  3. Improved type identification: Updated getTypeSpecKind to correctly identify type arrays containing "null" as unions rather than scalars.

Test Coverage

Added comprehensive test suite covering:

  • anyOf with definition + null
  • oneOf with constraints + null
  • Type arrays like ["integer", "null"]
  • Reference types with null
  • Edge cases and backward compatibility

All existing tests continue to pass (1609 tests).

Fixes #8513.

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: node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build (dns block)

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


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 22, 2025 19:17
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] [Bug]: import tool anyOf type null + definition leads to loss of information Fix OpenAPI import: preserve description and decorators for anyOf/oneOf with null Sep 22, 2025
Copilot AI requested a review from baywet September 22, 2025 19:28
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 23, 2025

All changed packages have been documented.

  • @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

[converter] anyOf/oneOf type + type:null gets imported properly and maintains decorators, documentation,...

Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
baywet and others added 2 commits September 23, 2025 13:53
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@baywet baywet added this pull request to the merge queue Sep 24, 2025
Merged via the queue into main with commit 4d6a5fe Sep 24, 2025
22 checks passed
@baywet baywet deleted the copilot/fix-8513 branch September 24, 2025 18:39
@timotheeguerin timotheeguerin added emitter:openapi3 Issues for @typespec/openapi3 emitter openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter labels Mar 2, 2026
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]: import tool anyOf type null + definition leads to loss of information

3 participants