This package provides the Cadl emitter to produce OpenAPI 3.0 output from Cadl source.
In your cadl project root
npm install @cadl-lang/openapi3
- Via the command line
cadl compile . --emit @cadl-lang/openapi3
- Via the config
Add the following to the cadl-project.yaml
file.
emitters:
@cadl-lang/openapi3: true
For configuration see options
import "@cadl-lang/openapi3";
using OpenAPI.V3;
// Using `using`
@useRef("common.json#/components/schemas/Foo")
model Foo {}
// Using fully qualified names
@OpenAPI.V3.oneOf
union MyUnion {
cat: Cat,
dog: Dog,
}
Emitter options can be configured via the cadl-project.yaml
configuration:
emitters:
'@cadl-lang/openapi3':
<optionName>: <value>
# For example
emitters:
'@cadl-lang/openapi3':
outputFile: my-custom-openapi.json
or via the command line with
--option "@cadl-lang/openapi3.<optionName>=<value>"
# For example
--option "@cadl-lang/openapi3.outputFile=my-custom-openapi.json"
Configure the name of the swagger output file relative to the compiler output-path
.