Skip to content

Generated openapi.yml doesn't use "components" property, OpenApi document size exceeds the limit of 102400 B #7224

@Alive-Fish

Description

@Alive-Fish

Is your feature request related to a problem? Please describe the problem.

Original issue: OfficeDev/microsoft-365-agents-toolkit#14796

Describe the bug

OpenAPI supports a "components" property in json and yml files that allows declaring modules in one place, and then referencing them with "refs" elsewhere to keep the files small.

When provisioning a Declarative Agent using the toolkit, the specs/openapi.json uses the "components" property, but appPackage/.generated/<agent>-openapi.yml doesn't.

This means that it's very easy to hit the 102KB limit in the size of the openapi.yml file.

To Reproduce

  • Create a demo Declarative Agent through the VS Code Extension
  • Edit the actions to contain a "model". Or, simply replace the "main.tsp" file with the contents of this playground which only modifies the Github Demo agent to extract query parameters to a model
  • Run the "provision" task (or otherwise "compile" the typespec files
  • Inspect appPackage/.generated/specs/openapi.json and notice that it uses a "components" property to hold the model
  • Inspect appPackage/.generated/<agent>-openapi.yml and notice that it does NOT use a "components" property to hold this model

Expected behavior

The "Components" property is used to kep file sizes small.

This is obviously not an issue in the demo, but in an agent with even modestly sized "models" with a handful of properties that are used across APIs, this quickly runs into a limit. Our current DA hits this limit with only 10 exposed CRUD actions split across 2 entities, and we believe using the "components" to avoid code duplication would allow for a wider API surface.

VS Code Extension Information (please complete the following information):

  • OS: Windows
  • VS Code Version: 6.2.2
  • NPM Packages:
    "@microsoft/m365agentstoolkit-cli": "^1.0.0",
    "@microsoft/typespec-m365-copilot": "1.0.0-rc.6",
    "@typespec/compiler": "1.5.0",
    "@typespec/http": "1.5.0",
    "@typespec/json-schema": "1.5.0",
    "@typespec/openapi": "1.5.0",
    "@typespec/openapi3": "1.5.0",
    "@typespec/rest": "0.75.0"

Additional context

Here are the generated files. Note: In this simple example, the model is only used once so this example wouldn't make the file smaller, but if the model was used in several places (such as an enum that defines the possible states of an Issue that is needed in several API operations), the yml file would be smaller if it used the "components" property with refs.

Openapi.json file:

{
  "openapi": "3.0.0",
  "info": {
    "title": "GitHub",
    "x-privacy-policy-url": "https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement",
    "x-legal-info-url": "https://docs.github.com/en/site-policy/github-terms/github-terms-of-service",
    "x-ai-description": "Search open issues from GitHub repositories.",
    "x-description-for-human": "Search open issues on GitHub.",
    "version": "0.0.0"
  },
  "tags": [],
  "paths": {
    "/search/issues": {
      "get": {
        "operationId": "searchIssues",
        "description": "Search open issues from GitHub repositories.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IssuesParams.q"
          },
          {
            "$ref": "#/components/parameters/IssuesParams.per_page"
          }
        ],
        "responses": {
          "200": {
            "description": "The request has succeeded.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "x-ai-adaptive-card": {
          "data_path": "$.items",
          "file": "adaptiveCards/searchIssues.json",
          "title": "$.title",
          "url": "$.html_url"
        }
      }
    }
  },
  "components": {
    "parameters": {
      "IssuesParams.per_page": {
        "name": "per_page",
        "in": "query",
        "required": true,
        "description": "The number of results per page. Default is 5.",
        "schema": {
          "type": "integer",
          "default": 5
        },
        "explode": false
      },
      "IssuesParams.q": {
        "name": "q",
        "in": "query",
        "required": true,
        "description": "The search query. Default is `repo:OfficeDev/microsoft-365-agents-toolkit is:open`.",
        "schema": {
          "type": "string",
          "default": "repo:OfficeDev/microsoft-365-agents-toolkit is:issue is:open"
        },
        "explode": false
      }
    }
  },
  "servers": [
    {
      "url": "https://api.github.com",
      "variables": {}
    }
  ]
}

Yaml file:

openapi: 3.0.4
info:
  title: GitHub - Subset
  version: 0.0.0
  x-privacy-policy-url: https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement
  x-legal-info-url: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service
  x-ai-description: Search open issues from GitHub repositories.
servers:
  - url: https://api.github.com
paths:
  /search/issues:
    get:
      description: Search open issues from GitHub repositories.
      operationId: searchIssues
      parameters:
        - name: q
          in: query
          description: The search query. Default is `repo:OfficeDev/microsoft-365-agents-toolkit is:open`.
          required: true
          explode: false
          schema:
            type: string
            default: repo:OfficeDev/microsoft-365-agents-toolkit is:issue is:open
        - name: per_page
          in: query
          description: The number of results per page. Default is 5.
          required: true
          explode: false
          schema:
            type: integer
            default: 5
      responses:
        '200':
          description: The request has succeeded.
          content:
            text/plain:
              schema:
                type: string
      x-ai-adaptive-card:
        data_path: $.items
        file: adaptiveCards/searchIssues.json
        title: $.title
        url: $.html_url
components: { }

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.

Client library/SDK language

TypeScript

Describe the solution you'd like

As title and description.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptPull requests that update Javascript codestatus:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:featureNew experience request

    Type

    No type

    Projects

    Status

    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions