Edit

Share via


Generate a TypeSpec file

Dev Proxy allows you to generate a TypeSpec file from the intercepted API requests and responses. Using Dev Proxy you can quickly create a TypeSpec file for an existing API and benefit from the tooling that supports TypeSpec.

To generate a TypeSpec file using Dev Proxy:

  1. In the configuration file, enable the TypeSpecGeneratorPlugin plugin:

    {
      "plugins": [
        {
          "name": "TypeSpecGeneratorPlugin",
          "enabled": true,
          "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
        }
      ]
      // [...] shortened for brevity
    }
    
  2. Optionally, configure the plugin in the configuration file:

    {
      "typeSpecGeneratorPlugin": {
        "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.27.0/typespecgeneratorplugin.schema.json",
        "ignoreResponseTypes": false
      }
      // [...] shortened for brevity
    }
    
  3. In the configuration file, to the list of URLs to watch, add the URL of the API for which you want to generate a TypeSpec file:

    { 
      "urlsToWatch": [
        "https://api.example.com/*",
      ]
      // [...] shortened for brevity
    }
    

    Tip

    To create better TypeSpec files, consider using a local language model with Dev Proxy. Using a local language model, the TypeSpecGeneratorPlugin generates clearer operation IDs and descriptions, giving you a better starting point for your TypeSpec file. For more information, see Use a local language model.

  4. Start Dev Proxy:

    devproxy
    
  5. Start recording requests by pressing r

  6. Perform the requests you want to include in the TypeSpec file

  7. Stop recording requests by pressing s

  8. Dev Proxy generates a TypeSpec file and saves it to a file in the current directory. Dev Proxy names the file after the host name of the API followed by the current date and time, for example: api.example.com-20231219091700.tsp.

Screenshot of two command prompt windows. One shows Dev Proxy recording API requests. The other shows the generated TypeSpec file.

Next steps

Learn more about the TypeSpecGeneratorPlugin.