@typespec/openapi3 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +124 -0
- package/dist/src/decorators.d.ts +6 -0
- package/dist/src/decorators.d.ts.map +1 -0
- package/dist/src/decorators.js +23 -0
- package/dist/src/decorators.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +216 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +92 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/openapi.d.ts +11 -0
- package/dist/src/openapi.d.ts.map +1 -0
- package/dist/src/openapi.js +1247 -0
- package/dist/src/openapi.js.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +8 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/types.d.ts +508 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# TypeSpec OpenAPI 3.0 Emitter
|
|
2
|
+
|
|
3
|
+
This package provides the [TypeSpec](https://github.com/microsoft/typespec) emitter to produce OpenAPI 3.0 output from TypeSpec source.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
In your typespec project root
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @typespec/openapi3
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Emit OpenAPI 3.0 spec
|
|
14
|
+
|
|
15
|
+
1. Via the command line
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
tsp compile . --emit @typespec/openapi3
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. Via the config
|
|
22
|
+
|
|
23
|
+
Add the following to the `tspconfig.yaml` file.
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
emitters:
|
|
27
|
+
@typespec/openapi3: true
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For configuration [see options](#emitter-options)
|
|
31
|
+
|
|
32
|
+
## Use OpenAPI 3.0 specific decorators:
|
|
33
|
+
|
|
34
|
+
```typespec
|
|
35
|
+
import "@typespec/openapi3";
|
|
36
|
+
|
|
37
|
+
using OpenAPI;
|
|
38
|
+
|
|
39
|
+
// Using `using`
|
|
40
|
+
@useRef("common.json#/components/schemas/Foo")
|
|
41
|
+
model Foo {}
|
|
42
|
+
|
|
43
|
+
// Using fully qualified names
|
|
44
|
+
@OpenAPI.oneOf
|
|
45
|
+
union MyUnion {
|
|
46
|
+
cat: Cat,
|
|
47
|
+
dog: Dog,
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Decorators
|
|
52
|
+
|
|
53
|
+
- [@useRef](#useref)
|
|
54
|
+
- [@oneOf](#oneof)
|
|
55
|
+
|
|
56
|
+
### @useRef
|
|
57
|
+
|
|
58
|
+
Syntax:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
@useRef(urlString)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`@useRef`
|
|
65
|
+
|
|
66
|
+
`@useRef` is used to replace the TypeSpec model type in emitter output with a pre-existing named OpenAPI schema.
|
|
67
|
+
|
|
68
|
+
### @oneOf
|
|
69
|
+
|
|
70
|
+
Syntax:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
@oneOf()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`@oneOf`emits `oneOf` keyword for a union type in the resulting OpenAPI 3.0 specification. It indicates that the value of union type can only contain exactly one of the subschemas.
|
|
77
|
+
|
|
78
|
+
`@oneOf` can only be applied to a union types.
|
|
79
|
+
|
|
80
|
+
## Emitter options:
|
|
81
|
+
|
|
82
|
+
Emitter options can be configured via the `tspconfig.yaml` configuration:
|
|
83
|
+
|
|
84
|
+
```yaml
|
|
85
|
+
emitters:
|
|
86
|
+
'@typespec/openapi3':
|
|
87
|
+
<optionName>: <value>
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# For example
|
|
91
|
+
emitters:
|
|
92
|
+
'@typespec/openapi3':
|
|
93
|
+
outputFile: my-custom-openapi.json
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
or via the command line with
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
--option "@typespec/openapi3.<optionName>=<value>"
|
|
100
|
+
|
|
101
|
+
# For example
|
|
102
|
+
--option "@typespec/openapi3.output-file=my-custom-openapi.json"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### `output-file`
|
|
106
|
+
|
|
107
|
+
Configure the name of the swagger output file relative to the compiler `output-path`.
|
|
108
|
+
|
|
109
|
+
### `new-line`
|
|
110
|
+
|
|
111
|
+
Set the newline character for emitting files. Can be either:
|
|
112
|
+
|
|
113
|
+
- `lf`(Default)
|
|
114
|
+
- `crlf`
|
|
115
|
+
|
|
116
|
+
### `omit-unreachable-types`
|
|
117
|
+
|
|
118
|
+
Only include types referenced via an operation.
|
|
119
|
+
|
|
120
|
+
## See also
|
|
121
|
+
|
|
122
|
+
- [TypeSpec Getting Started](https://github.com/microsoft/typespec#getting-started)
|
|
123
|
+
- [TypeSpec Website](https://microsoft.github.io/typespec)
|
|
124
|
+
- [TypeSpec for the OpenAPI Developer](https://github.com/microsoft/typespec/blob/main/docs/typespec-for-openapi-dev.md)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DecoratorContext, Program, Type } from "@typespec/compiler";
|
|
2
|
+
export declare function $useRef(context: DecoratorContext, entity: Type, refUrl: string): void;
|
|
3
|
+
export declare function getRef(program: Program, entity: Type): string | undefined;
|
|
4
|
+
export declare function $oneOf(context: DecoratorContext, entity: Type): void;
|
|
5
|
+
export declare function getOneOf(program: Program, entity: Type): boolean;
|
|
6
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAA2B,MAAM,oBAAoB,CAAC;AAI9F,wBAAgB,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAMrF;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAEzE;AAGD,wBAAgB,MAAM,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,QAK7D;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAEhE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { validateDecoratorTarget } from "@typespec/compiler";
|
|
2
|
+
import { createStateSymbol } from "./lib.js";
|
|
3
|
+
const refTargetsKey = createStateSymbol("refs");
|
|
4
|
+
export function $useRef(context, entity, refUrl) {
|
|
5
|
+
if (!validateDecoratorTarget(context, entity, "@useRef", ["Model", "ModelProperty"])) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
context.program.stateMap(refTargetsKey).set(entity, refUrl);
|
|
9
|
+
}
|
|
10
|
+
export function getRef(program, entity) {
|
|
11
|
+
return program.stateMap(refTargetsKey).get(entity);
|
|
12
|
+
}
|
|
13
|
+
const oneOfKey = createStateSymbol("oneOf");
|
|
14
|
+
export function $oneOf(context, entity) {
|
|
15
|
+
if (!validateDecoratorTarget(context, entity, "@oneOf", "Union")) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
context.program.stateMap(oneOfKey).set(entity, true);
|
|
19
|
+
}
|
|
20
|
+
export function getOneOf(program, entity) {
|
|
21
|
+
return program.stateMap(oneOfKey).get(entity);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,UA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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC;AAEnC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { JSONSchemaType } from "@typespec/compiler";
|
|
2
|
+
export type FileType = "yaml" | "json";
|
|
3
|
+
export interface OpenAPI3EmitterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* If the content should be serialized as YAML or JSON.
|
|
6
|
+
* @default yaml, it not specified infer from the `output-file` extension
|
|
7
|
+
*/
|
|
8
|
+
"file-type"?: FileType;
|
|
9
|
+
/**
|
|
10
|
+
* Name of the output file.
|
|
11
|
+
* @default `openapi.yaml` or `openapi.json` if {@link OpenAPI3EmitterOptions["file-type"]} is `"json"`
|
|
12
|
+
*/
|
|
13
|
+
"output-file"?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Set the newline character for emitting files.
|
|
16
|
+
* @default lf
|
|
17
|
+
*/
|
|
18
|
+
"new-line"?: "crlf" | "lf";
|
|
19
|
+
/**
|
|
20
|
+
* Omit unreachable types.
|
|
21
|
+
* 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.
|
|
22
|
+
*/
|
|
23
|
+
"omit-unreachable-types"?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare const libDef: {
|
|
26
|
+
readonly name: "@typespec/openapi3";
|
|
27
|
+
readonly diagnostics: {
|
|
28
|
+
readonly "invalid-server-variable": {
|
|
29
|
+
readonly severity: "error";
|
|
30
|
+
readonly messages: {
|
|
31
|
+
readonly default: import("@typespec/compiler").CallableMessage<["propName"]>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
readonly "resource-namespace": {
|
|
35
|
+
readonly severity: "error";
|
|
36
|
+
readonly messages: {
|
|
37
|
+
readonly default: "Resource goes on namespace";
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
readonly "path-query": {
|
|
41
|
+
readonly severity: "error";
|
|
42
|
+
readonly messages: {
|
|
43
|
+
readonly default: "OpenAPI does not allow paths containing a query string.";
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
readonly "duplicate-body": {
|
|
47
|
+
readonly severity: "error";
|
|
48
|
+
readonly messages: {
|
|
49
|
+
readonly default: "Duplicate @body declarations on response type";
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
readonly "duplicate-header": {
|
|
53
|
+
readonly severity: "error";
|
|
54
|
+
readonly messages: {
|
|
55
|
+
readonly default: import("@typespec/compiler").CallableMessage<["header"]>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
readonly "status-code-in-default-response": {
|
|
59
|
+
readonly severity: "error";
|
|
60
|
+
readonly messages: {
|
|
61
|
+
readonly default: "a default response should not have an explicit status code";
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
readonly "invalid-schema": {
|
|
65
|
+
readonly severity: "error";
|
|
66
|
+
readonly messages: {
|
|
67
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
readonly "union-null": {
|
|
71
|
+
readonly severity: "error";
|
|
72
|
+
readonly messages: {
|
|
73
|
+
readonly default: "Cannot have a union containing only null types.";
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
readonly "union-unsupported": {
|
|
77
|
+
readonly severity: "error";
|
|
78
|
+
readonly messages: {
|
|
79
|
+
readonly default: "Unions are not supported unless all options are literals of the same type.";
|
|
80
|
+
readonly type: import("@typespec/compiler").CallableMessage<["kind"]>;
|
|
81
|
+
readonly empty: "Empty unions are not supported for OpenAPI v3 - enums must have at least one value.";
|
|
82
|
+
readonly null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.";
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
readonly "invalid-default": {
|
|
86
|
+
readonly severity: "error";
|
|
87
|
+
readonly messages: {
|
|
88
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
readonly "inline-cycle": {
|
|
92
|
+
readonly severity: "error";
|
|
93
|
+
readonly messages: {
|
|
94
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
readonly emitter: {
|
|
99
|
+
readonly options: JSONSchemaType<OpenAPI3EmitterOptions>;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
export declare const $lib: import("@typespec/compiler").TypeSpecLibrary<{
|
|
103
|
+
"invalid-server-variable": {
|
|
104
|
+
readonly default: import("@typespec/compiler").CallableMessage<["propName"]>;
|
|
105
|
+
};
|
|
106
|
+
"resource-namespace": {
|
|
107
|
+
readonly default: "Resource goes on namespace";
|
|
108
|
+
};
|
|
109
|
+
"path-query": {
|
|
110
|
+
readonly default: "OpenAPI does not allow paths containing a query string.";
|
|
111
|
+
};
|
|
112
|
+
"duplicate-body": {
|
|
113
|
+
readonly default: "Duplicate @body declarations on response type";
|
|
114
|
+
};
|
|
115
|
+
"duplicate-header": {
|
|
116
|
+
readonly default: import("@typespec/compiler").CallableMessage<["header"]>;
|
|
117
|
+
};
|
|
118
|
+
"status-code-in-default-response": {
|
|
119
|
+
readonly default: "a default response should not have an explicit status code";
|
|
120
|
+
};
|
|
121
|
+
"invalid-schema": {
|
|
122
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
123
|
+
};
|
|
124
|
+
"union-null": {
|
|
125
|
+
readonly default: "Cannot have a union containing only null types.";
|
|
126
|
+
};
|
|
127
|
+
"union-unsupported": {
|
|
128
|
+
readonly default: "Unions are not supported unless all options are literals of the same type.";
|
|
129
|
+
readonly type: import("@typespec/compiler").CallableMessage<["kind"]>;
|
|
130
|
+
readonly empty: "Empty unions are not supported for OpenAPI v3 - enums must have at least one value.";
|
|
131
|
+
readonly null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.";
|
|
132
|
+
};
|
|
133
|
+
"invalid-default": {
|
|
134
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
135
|
+
};
|
|
136
|
+
"inline-cycle": {
|
|
137
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
138
|
+
};
|
|
139
|
+
}, OpenAPI3EmitterOptions>;
|
|
140
|
+
export declare const reportDiagnostic: <C extends "invalid-server-variable" | "resource-namespace" | "path-query" | "duplicate-body" | "duplicate-header" | "status-code-in-default-response" | "invalid-schema" | "union-null" | "union-unsupported" | "invalid-default" | "inline-cycle", M extends keyof {
|
|
141
|
+
"invalid-server-variable": {
|
|
142
|
+
readonly default: import("@typespec/compiler").CallableMessage<["propName"]>;
|
|
143
|
+
};
|
|
144
|
+
"resource-namespace": {
|
|
145
|
+
readonly default: "Resource goes on namespace";
|
|
146
|
+
};
|
|
147
|
+
"path-query": {
|
|
148
|
+
readonly default: "OpenAPI does not allow paths containing a query string.";
|
|
149
|
+
};
|
|
150
|
+
"duplicate-body": {
|
|
151
|
+
readonly default: "Duplicate @body declarations on response type";
|
|
152
|
+
};
|
|
153
|
+
"duplicate-header": {
|
|
154
|
+
readonly default: import("@typespec/compiler").CallableMessage<["header"]>;
|
|
155
|
+
};
|
|
156
|
+
"status-code-in-default-response": {
|
|
157
|
+
readonly default: "a default response should not have an explicit status code";
|
|
158
|
+
};
|
|
159
|
+
"invalid-schema": {
|
|
160
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
161
|
+
};
|
|
162
|
+
"union-null": {
|
|
163
|
+
readonly default: "Cannot have a union containing only null types.";
|
|
164
|
+
};
|
|
165
|
+
"union-unsupported": {
|
|
166
|
+
readonly default: "Unions are not supported unless all options are literals of the same type.";
|
|
167
|
+
readonly type: import("@typespec/compiler").CallableMessage<["kind"]>;
|
|
168
|
+
readonly empty: "Empty unions are not supported for OpenAPI v3 - enums must have at least one value.";
|
|
169
|
+
readonly null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.";
|
|
170
|
+
};
|
|
171
|
+
"invalid-default": {
|
|
172
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
173
|
+
};
|
|
174
|
+
"inline-cycle": {
|
|
175
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
176
|
+
};
|
|
177
|
+
}[C]>(program: import("@typespec/compiler").Program, diag: import("@typespec/compiler").DiagnosticReport<{
|
|
178
|
+
"invalid-server-variable": {
|
|
179
|
+
readonly default: import("@typespec/compiler").CallableMessage<["propName"]>;
|
|
180
|
+
};
|
|
181
|
+
"resource-namespace": {
|
|
182
|
+
readonly default: "Resource goes on namespace";
|
|
183
|
+
};
|
|
184
|
+
"path-query": {
|
|
185
|
+
readonly default: "OpenAPI does not allow paths containing a query string.";
|
|
186
|
+
};
|
|
187
|
+
"duplicate-body": {
|
|
188
|
+
readonly default: "Duplicate @body declarations on response type";
|
|
189
|
+
};
|
|
190
|
+
"duplicate-header": {
|
|
191
|
+
readonly default: import("@typespec/compiler").CallableMessage<["header"]>;
|
|
192
|
+
};
|
|
193
|
+
"status-code-in-default-response": {
|
|
194
|
+
readonly default: "a default response should not have an explicit status code";
|
|
195
|
+
};
|
|
196
|
+
"invalid-schema": {
|
|
197
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
198
|
+
};
|
|
199
|
+
"union-null": {
|
|
200
|
+
readonly default: "Cannot have a union containing only null types.";
|
|
201
|
+
};
|
|
202
|
+
"union-unsupported": {
|
|
203
|
+
readonly default: "Unions are not supported unless all options are literals of the same type.";
|
|
204
|
+
readonly type: import("@typespec/compiler").CallableMessage<["kind"]>;
|
|
205
|
+
readonly empty: "Empty unions are not supported for OpenAPI v3 - enums must have at least one value.";
|
|
206
|
+
readonly null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.";
|
|
207
|
+
};
|
|
208
|
+
"invalid-default": {
|
|
209
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
210
|
+
};
|
|
211
|
+
"inline-cycle": {
|
|
212
|
+
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
213
|
+
};
|
|
214
|
+
}, C, M>) => void, createStateSymbol: (name: string) => symbol;
|
|
215
|
+
export type OpenAPILibrary = typeof $lib;
|
|
216
|
+
//# sourceMappingURL=lib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,cAAc,EAAgB,MAAM,oBAAoB,CAAC;AAEzF,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AACvC,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IAEH,WAAW,CAAC,EAAE,QAAQ,CAAC;IAEvB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAcD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6ET,CAAC;AAEX,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAgC,CAAC;AAClD,eAAO,MAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAE,iBAAiB,0BAAS,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG,OAAO,IAAI,CAAC"}
|
package/dist/src/lib.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";
|
|
2
|
+
const EmitterOptionsSchema = {
|
|
3
|
+
type: "object",
|
|
4
|
+
additionalProperties: false,
|
|
5
|
+
properties: {
|
|
6
|
+
"file-type": { type: "string", enum: ["yaml", "json"], nullable: true },
|
|
7
|
+
"output-file": { type: "string", nullable: true },
|
|
8
|
+
"new-line": { type: "string", enum: ["crlf", "lf"], default: "lf", nullable: true },
|
|
9
|
+
"omit-unreachable-types": { type: "boolean", nullable: true },
|
|
10
|
+
},
|
|
11
|
+
required: [],
|
|
12
|
+
};
|
|
13
|
+
export const libDef = {
|
|
14
|
+
name: "@typespec/openapi3",
|
|
15
|
+
diagnostics: {
|
|
16
|
+
"invalid-server-variable": {
|
|
17
|
+
severity: "error",
|
|
18
|
+
messages: {
|
|
19
|
+
default: paramMessage `Server variable '${"propName"}' must be assignable to 'string'. It must either be a string, enum of string or union of strings.`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
"resource-namespace": {
|
|
23
|
+
severity: "error",
|
|
24
|
+
messages: {
|
|
25
|
+
default: "Resource goes on namespace",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
"path-query": {
|
|
29
|
+
severity: "error",
|
|
30
|
+
messages: {
|
|
31
|
+
default: `OpenAPI does not allow paths containing a query string.`,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
"duplicate-body": {
|
|
35
|
+
severity: "error",
|
|
36
|
+
messages: {
|
|
37
|
+
default: "Duplicate @body declarations on response type",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
"duplicate-header": {
|
|
41
|
+
severity: "error",
|
|
42
|
+
messages: {
|
|
43
|
+
default: paramMessage `The header ${"header"} is defined across multiple content types`,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
"status-code-in-default-response": {
|
|
47
|
+
severity: "error",
|
|
48
|
+
messages: {
|
|
49
|
+
default: "a default response should not have an explicit status code",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
"invalid-schema": {
|
|
53
|
+
severity: "error",
|
|
54
|
+
messages: {
|
|
55
|
+
default: paramMessage `Couldn't get schema for type ${"type"}`,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
"union-null": {
|
|
59
|
+
severity: "error",
|
|
60
|
+
messages: {
|
|
61
|
+
default: "Cannot have a union containing only null types.",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
"union-unsupported": {
|
|
65
|
+
severity: "error",
|
|
66
|
+
messages: {
|
|
67
|
+
default: "Unions are not supported unless all options are literals of the same type.",
|
|
68
|
+
type: paramMessage `Type "${"kind"}" cannot be used in unions`,
|
|
69
|
+
empty: "Empty unions are not supported for OpenAPI v3 - enums must have at least one value.",
|
|
70
|
+
null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
"invalid-default": {
|
|
74
|
+
severity: "error",
|
|
75
|
+
messages: {
|
|
76
|
+
default: paramMessage `Invalid type '${"type"}' for a default value`,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
"inline-cycle": {
|
|
80
|
+
severity: "error",
|
|
81
|
+
messages: {
|
|
82
|
+
default: paramMessage `Cycle detected in '${"type"}'. Use @friendlyName decorator to assign an OpenAPI definition name and make it non-inline.`,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
emitter: {
|
|
87
|
+
options: EmitterOptionsSchema,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
export const $lib = createTypeSpecLibrary(libDef);
|
|
91
|
+
export const { reportDiagnostic, createStateSymbol } = $lib;
|
|
92
|
+
//# sourceMappingURL=lib.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.js","sour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Q,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,cAAc,QAAQ,2CAA2C;aACvF;SACF;QACD,iCAAiC,EAAE;YACjC,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,4DAA4D;aACtE;SACF;QACD,gBAAgB,EAAE;YAChB,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,gCAAgC,MAAM,EAAE;aAC9D;SACF;QACD,YAAY,EAAE;YACZ,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,iDAAiD;aAC3D;SACF;QACD,mBAAmB,EAAE;YACnB,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,4EAA4E;gBACrF,IAAI,EAAE,YAAY,CAAA,SAAS,MAAM,4BAA4B;gBAC7D,KAAK,EACH,qFAAqF;gBACvF,IAAI,EAAE,+HAA+H;aACtI;SACF;QACD,iBAAiB,EAAE;YACjB,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,iBAAiB,MAAM,uBAAuB;aACpE;SACF;QACD,cAAc,EAAE;YACd,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,sBAAsB,MAAM,6FAA6F;aAC/I;SACF;KACF;IACD,OAAO,EAAE;QACP,OAAO,EAAE,oBAA8D;KACxE;CACO,CAAC;AAEX,MAAM,CAAC,MAAM,IAAI,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EmitContext, NewLine } from "@typespec/compiler";
|
|
2
|
+
import { FileType, OpenAPI3EmitterOptions } from "./lib.js";
|
|
3
|
+
export declare function $onEmit(context: EmitContext<OpenAPI3EmitterOptions>): Promise<void>;
|
|
4
|
+
export declare function resolveOptions(context: EmitContext<OpenAPI3EmitterOptions>): ResolvedOpenAPI3EmitterOptions;
|
|
5
|
+
export interface ResolvedOpenAPI3EmitterOptions {
|
|
6
|
+
fileType: FileType;
|
|
7
|
+
outputFile: string;
|
|
8
|
+
newLine: NewLine;
|
|
9
|
+
omitUnreachableTypes: boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EA2CX,OAAO,EAcR,MAAM,oBAAoB,CAAC;AAmC5B,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAoB,MAAM,UAAU,CAAC;AAsB9E,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,sBAAsB,CAAC,iBAIzE;AAgBD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,WAAW,CAAC,sBAAsB,CAAC,GAC3C,8BAA8B,CAahC;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;CAC/B"}
|