TypeSpec library for emitting openapi from the TypeSpec REST protocol binding
npm install @azure-tools/typespec-autorest- Via the command line
tsp compile . --emit=@azure-tools/typespec-autorest- Via the config
emit:
- "@azure-tools/typespec-autorest"The config can be extended with options as follows:
emit:
- "@azure-tools/typespec-autorest"
options:
"@azure-tools/typespec-autorest":
option: valueType: absolutePath
Defines the emitter output directory. Defaults to {output-dir}/@azure-tools/typespec-autorest
See Configuring output directory for more info
Deprecated: This option is deprecated.
Type: string
Deprecated DO NOT USE. Use built-in emitter-output-dir instead
Type: string
Name of the output file. Output file will interpolate the following values:
- service-name: Name of the service if multiple
- version: Version of the service if multiple
- version-status:
previewif version contains preview, stable otherwise.
Default: {emitter-output-dir}/{service-name}/{version-status}/{version}/openapi.json
Example: Single service no versioning
openapi.yaml
Example: Multiple services no versioning
openapi.Org1.Service1.yamlopenapi.Org1.Service2.yaml
Example: Single service with versioning
openapi.v1.yamlopenapi.v2.yaml
Example: Multiple service with versioning
openapi.Org1.Service1.v1.yamlopenapi.Org1.Service1.v2.yamlopenapi.Org1.Service2.v1.0.yamlopenapi.Org1.Service2.v1.1.yaml
Example: Versioning with version-status
arm-folder/AzureService/stable/2020-01-01.yamlarm-folder/AzureService/preview/2020-01-01.yaml
Type: string
Directory where the examples are located. Default: {project-root}/examples.
Deprecated: This option is deprecated.
Type: string
DEPRECATED. Use examples-dir instead
Type: string
Type: string
Deprecated. Do not use this option. Specify the path directly in emitter-output-dir.
Type: string
Path to the common-types.json file folder. Default: '${project-root}/../../common-types/resource-management'
Type: "crlf" | "lf"
Default: "lf"
Set the newline character for emitting files.
Type: boolean
Omit unreachable types. By default all types declared under the service namespace will be included. With this flag on only types references in an operation will be emitted.
Type: string
Default: "omit"
Decide how to deal with the Version enum when when omit-unreachable-types is not set. Default to 'omit'
Type: "inline-only" | "never"
Default: "never"
If the generated openapi types should have the x-typespec-name extension set with the name of the TypeSpec type that created it.
This extension is meant for debugging and should not be depended on.
Type: boolean
Default: false
Create read-only property schema for lro status
Type: "none" | "final-state-only" | "all"
Default: "final-state-only"
Determine whether and how to emit x-ms-long-running-operation-options for lro resolution
Type: "never" | "for-visibility-changes"
Default: "for-visibility-changes"
Determine whether and how to emit schemas for common-types rather than referencing them
Type: "xml-service" | "none"
Default: "xml-service"
Strategy for applying XML serialization metadata to schemas.
Type: "legacy-feature-files"
Determines whether output should be split into multiple files. The only supported option for splitting is "legacy-feature-files", which uses the typespec-azure-resource-manager @feature decorators to split into output files based on feature.
Type: boolean
Default: false
When enabled, the emitter will not copy example files to the output directory. Instead, it will reference the source example files using relative file paths.
Type: "namespaced" | "name-only"
Default: "namespaced"
Strategy for naming the OpenAPI names derived from TypeSpec types. "namespaced" (default) includes the namespace prefix for types outside the service namespace (e.g. LiftrBase.Foo). "name-only" uses only the type name without any namespace prefix (e.g. Foo), reporting an error when two types collapse to the same name.
@example - attaches example files to an operation. Multiple examples can be specified.
@example can be specified on Operations.
@Autorest.example(pathOrUri: valueof string, title: valueof string)Operation
| Name | Type | Description |
|---|---|---|
| pathOrUri | valueof string |
path or Uri to the example file. |
| title | valueof string |
name or description of the example file. |
@useRef - is used to replace the TypeSpec model type in emitter output with a pre-existing named OpenAPI schema such as Azure Resource Manager common types.
@useRef can be specified on Models and ModelProperty.
@Autorest.useRef(jsonRef: valueof string)Model | ModelProperty
| Name | Type | Description |
|---|---|---|
| jsonRef | valueof string |
path or Uri to an OpenAPI schema. |