Skip to content

Fix OpenAPI import: additionalProperties: true should generate Record<unknown>#8584

Merged
baywet merged 4 commits intomainfrom
copilot/fix-3403d84a-ba1c-421d-b0a6-15db1f3ff2b0
Sep 29, 2025
Merged

Fix OpenAPI import: additionalProperties: true should generate Record<unknown>#8584
baywet merged 4 commits intomainfrom
copilot/fix-3403d84a-ba1c-421d-b0a6-15db1f3ff2b0

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 26, 2025

Fixes an inconsistency in the OpenAPI import tool where additionalProperties: true and additionalProperties: {} generated different TypeSpec types, despite having identical semantic meaning in OpenAPI 3.1.

Problem

When importing an OpenAPI 3.1 specification with different additionalProperties values:

components:
  schemas:
    Foo:
      type: object
      properties:
        bar:
          type: object
          additionalProperties: true
        baz:
          type: object
          additionalProperties: {}

The conversion would produce inconsistent TypeSpec output:

model Foo {
  bar: {}                // ❌ Should be Record<unknown>
  baz: Record<unknown>   // ✅ Correct
}

Both additionalProperties: true and additionalProperties: {} semantically mean "additional properties are allowed with any type" in OpenAPI, so they should generate the same TypeSpec representation.

Solution

Updated the conversion logic in two places:

  1. generate-types.ts: Modified the getObjectType method to explicitly handle additionalProperties: true by generating Record<unknown>

  2. transform-component-schemas.ts: Updated the schema transformation to preserve additionalProperties: true during the conversion process

Result

Both scenarios now correctly generate Record<unknown>:

model Foo {
  bar: Record<unknown>   // ✅ Now correct for additionalProperties: true
  baz: Record<unknown>   // ✅ Still correct for additionalProperties: {}
}

Added comprehensive test coverage for both additionalProperties: true and additionalProperties: {} scenarios to prevent regression.

Fixes #[issue-number]

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:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: OpenAPI import tool - additional properties import issue</issue_title>
<issue_description>### Describe the bug

When importing an OpenAPI 3.1 description, additionalProperies: {} results in Record but additionalProperties: true results in {} type.

I'd expect both scenarios to result in the same exact TypeSpec definition since in both cases the OpenAPI semantics mean "additional properties are supported, we don't know their type thought"

Reproduction

components:
  schemas:
    Foo:
      type: object
      properties:
        bar:
          type: object
          additionalProperties: true
        baz:
          type: object
          additionalProperties: {}

Results in

model Foo {
  bar: {}
  baz: Record<unknown>
}

Where I'd expect instead

model Foo {
  bar: Record<unknown>
  baz: Record<unknown>
}

Checklist

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

Fixes #8583

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot AI changed the title [WIP] [Bug]: OpenAPI import tool - additional properties import issue Fix OpenAPI import: additionalProperties: true should generate Record<unknown> Sep 26, 2025
Copilot AI requested a review from baywet September 26, 2025 20:49
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 29, 2025

All changed packages have been documented.

  • @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

[importer] fixes import of additional properties : true {} to result in Record

@baywet baywet added this pull request to the merge queue Sep 29, 2025
Merged via the queue into main with commit d792c7e Sep 29, 2025
22 checks passed
@baywet baywet deleted the copilot/fix-3403d84a-ba1c-421d-b0a6-15db1f3ff2b0 branch September 29, 2025 18:29
@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]: OpenAPI import tool - additional properties import issue

3 participants