Skip to content

feat(openapi3): import readOnly/writeOnly as visibility decorators#9742

Merged
baywet merged 3 commits intomainfrom
copilot/support-import-readonly-and-writeonly
Feb 19, 2026
Merged

feat(openapi3): import readOnly/writeOnly as visibility decorators#9742
baywet merged 3 commits intomainfrom
copilot/support-import-readonly-and-writeonly

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

The import tool ignored readOnly and writeOnly properties, breaking import/emit symmetry since the emitter already generates these from @visibility decorators.

Changes

  • Type definitions: Added missing writeOnly property to OpenAPI3Schema and OpenAPISchema3_2
  • Import conversion:
    • readOnly: true@visibility(Lifecycle.Read)
    • writeOnly: true@visibility(Lifecycle.Create)
    • Mutual exclusivity validation (warns and ignores both if both present)
  • Tests: Coverage for all scenarios including nested properties and arrays

Example

Before:

properties:
  id:
    type: string
    readOnly: true
model Widget {
  id: string;  // readOnly lost
}

After:

model Widget {
  @visibility(Lifecycle.Read) id: string;
}
Original prompt

This section details on the original issue you should resolve

<issue_title>import tool - support importing readonly and writeonly</issue_title>
<issue_description>### Clear and concise description of the problem

The import tool currently does not support importing readOnly: true or writeOnly: true as a visibility decorator. We should add support for that because the emitters support the decorator, so the import/emit process is not symmetrical today.

Today the following OpenAPI descriptions

components:
  schemas:
    Widget:
      type: object
      required:
        - id
        - weight
        - color
      properties:
        id:
          type: string
          readOnly: true
        weight:
          type: integer
          format: int32
        color:
          type: string
          enum:
            - red
            - blue

or

components:
  schemas:
    Widget:
      type: object
      required:
        - id
        - weight
        - color
      properties:
        id:
          type: string
          writeOnly: true
        weight:
          type: integer
          format: int32
        color:
          type: string
          enum:
            - red
            - blue

both result to

model Widget {
  id: string;

  weight: int32;
  color: "red" | "blue";
}

As if the read/write only properties are absent.

It should instead result in

model Widget {
+  @visibility(Lifecycle.Read)
  id: string;

  weight: int32;
  color: "red" | "blue";
}

In the case readOnly is present

model Widget {
+  @visibility(Lifecycle.Create)
  id: string;

  weight: int32;
  color: "red" | "blue";
}

In the case writeOnly is present.

Also those properties should be treated as mutually exclusive and an error should be reported + both ignored in case they are both present.

Checklist

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.</issue_description>

<agent_instructions>use conventional commits.
run the formatting commands.
run the changelog command.
start by defining the unit tests first.</agent_instructions>

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


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

- Add readOnly and writeOnly properties to OpenAPI3Schema and OpenAPISchema3_2 types
- Implement conversion of readOnly to @visibility(Lifecycle.Read)
- Implement conversion of writeOnly to @visibility(Lifecycle.Create)
- Add mutual exclusivity check with warning when both are present
- Add comprehensive tests for all scenarios

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
@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 Feb 18, 2026
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for importing readonly and writeonly feat(openapi3): import readOnly/writeOnly as visibility decorators Feb 18, 2026
Copilot AI requested a review from baywet February 18, 2026 19:38
@baywet baywet marked this pull request as ready for review February 18, 2026 20:35
@baywet baywet enabled auto-merge February 18, 2026 20:35
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 18, 2026

Open in StackBlitz

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

commit: 8cd864b

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@baywet baywet added this pull request to the merge queue Feb 19, 2026
Merged via the queue into main with commit 72257df Feb 19, 2026
29 checks passed
@baywet baywet deleted the copilot/support-import-readonly-and-writeonly branch February 19, 2026 13:36
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.

import tool - support importing readonly and writeonly

4 participants

Comments