OpenAPI3 to TypeSpec
Converting OpenAPI 3 into TypeSpec
This package includes the tsp-openapi3
CLI for converting OpenAPI 3 specs into TypeSpec.
The generated TypeSpec depends on the @typespec/http
, @typespec/openapi
and @typespec/openapi3
libraries.
Usage
- via the command line
tsp-openapi3 arguments
The path to the OpenAPI3 yaml or json file must be passed as a position argument.
The named arguments are:
Name | Type | Required | Description |
---|---|---|---|
output-dir | string | required | The output directory for generated TypeSpec files. Will be created if it does not exist. |
help | boolean | optional | Show help. |
Examples
1. Convert component schemas into models
All schemas present at #/components/schemas
will be converted into a model or scalar as appropriate.
OpenAPI3 | TypeSpec |
2. Convert component parameters into models or fields
All parameters present at #/components/parameters
will be converted to a field in a model. If the model doesnโt exist in #/components/schemas
, then it will be created.
OpenAPI3 | TypeSpec |
3. Convert path routes to operations
All routes using one of the HTTP methods supported by @typespec/http
will be converted into operations at the file namespace level. A model is also generated for each operation response.
At this time, no automatic operation grouping under interfaces is performed.
OpenAPI3 | TypeSpec |