@typespec/openapi3 0.67.0-dev.0 → 0.67.0-dev.11
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/dist/src/encoding.d.ts.map +1 -1
- package/dist/src/encoding.js +17 -6
- package/dist/src/encoding.js.map +1 -1
- package/dist/src/lib.d.ts +0 -141
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +5 -3
- package/dist/src/lib.js.map +1 -1
- package/dist/src/openapi-helpers-3-0.d.ts.map +1 -1
- package/dist/src/openapi-helpers-3-1.d.ts.map +1 -1
- package/dist/src/openapi.d.ts.map +1 -1
- package/dist/src/openapi.js +66 -116
- package/dist/src/openapi.js.map +1 -1
- package/dist/src/schema-emitter-3-0.d.ts.map +1 -1
- package/dist/src/schema-emitter-3-0.js +0 -1
- package/dist/src/schema-emitter-3-0.js.map +1 -1
- package/dist/src/schema-emitter-3-1.d.ts.map +1 -1
- package/dist/src/schema-emitter-3-1.js +0 -1
- package/dist/src/schema-emitter-3-1.js.map +1 -1
- package/dist/src/schema-emitter.d.ts +1 -1
- package/dist/src/schema-emitter.d.ts.map +1 -1
- package/dist/src/schema-emitter.js +2 -11
- package/dist/src/schema-emitter.js.map +1 -1
- package/dist/src/versioning-module.d.ts +3 -0
- package/dist/src/versioning-module.d.ts.map +1 -0
- package/dist/src/versioning-module.js +9 -0
- package/dist/src/versioning-module.js.map +1 -0
- package/package.json +24 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,oBAAoB,CAAC;AAGzF,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnE,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,MAAM,GAAG,aAAa,EACpC,MAAM,EAAE,cAAc,GAAG,gBAAgB,EACzC,mBAAmB,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,KAAK,MAAM,EACrE,OAAO,EAAE,8BAA8B,GACtC,cAAc,GAAG,gBAAgB,CAuBnC"}
|
package/dist/src/encoding.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { getEncode } from "@typespec/compiler";
|
|
2
2
|
import { ObjectBuilder } from "@typespec/compiler/emitter-framework";
|
|
3
|
+
import { isHeader } from "@typespec/http";
|
|
3
4
|
import { getSchemaForStdScalars } from "./std-scalar-schemas.js";
|
|
4
5
|
export function applyEncoding(program, typespecType, target, getEncodedFieldName, options) {
|
|
6
|
+
const encodedFieldName = getEncodedFieldName(typespecType);
|
|
7
|
+
const targetObject = new ObjectBuilder(target);
|
|
5
8
|
const encodeData = getEncode(program, typespecType);
|
|
6
9
|
if (encodeData) {
|
|
7
|
-
const newTarget = new ObjectBuilder(target);
|
|
8
10
|
const newType = getSchemaForStdScalars(encodeData.type, options);
|
|
9
|
-
|
|
11
|
+
targetObject.type = newType.type;
|
|
10
12
|
// If the target already has a format it takes priority. (e.g. int32)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return newTarget;
|
|
13
|
+
targetObject[encodedFieldName] = mergeFormatAndEncoding(targetObject[encodedFieldName], encodeData.encoding, newType.format);
|
|
14
|
+
return targetObject;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
if (isDateTimeHeader(program, typespecType, targetObject, encodedFieldName)) {
|
|
17
|
+
targetObject[encodedFieldName] = "http-date";
|
|
18
|
+
return targetObject;
|
|
19
|
+
}
|
|
20
|
+
return targetObject;
|
|
16
21
|
}
|
|
17
22
|
function mergeFormatAndEncoding(format, encoding, encodeAsFormat) {
|
|
18
23
|
switch (format) {
|
|
@@ -40,4 +45,10 @@ function mergeFormatAndEncoding(format, encoding, encodeAsFormat) {
|
|
|
40
45
|
return encodeAsFormat ?? encoding ?? format;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
48
|
+
function isDateTimeHeader(program, typespecType, target, encodedFieldName) {
|
|
49
|
+
if (isHeader(program, typespecType) && target[encodedFieldName] === "date-time") {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
43
54
|
//# sourceMappingURL=encoding.js.map
|
package/dist/src/encoding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,MAAM,UAAU,aAAa,CAC3B,OAAgB,EAChB,YAAoC,EACpC,MAAyC,EACzC,mBAAqE,EACrE,OAAuC;IAEvC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAC3D,MAAM,YAAY,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAE/C,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,EAAE,YAAY,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AoC,EACpC,MAA0B,EAC1B,gBAAwB;IAExB,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,gBAAgB,CAAC,KAAK,WAAW,EAAE,CAAC;QAChF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/src/lib.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { JSONSchemaType } from "@typespec/compiler";
|
|
2
1
|
export type FileType = "yaml" | "json";
|
|
3
2
|
export type OpenAPIVersion = "3.0.0" | "3.1.0";
|
|
4
3
|
export interface OpenAPI3EmitterOptions {
|
|
@@ -64,146 +63,6 @@ export interface OpenAPI3EmitterOptions {
|
|
|
64
63
|
*/
|
|
65
64
|
"seal-object-schemas"?: boolean;
|
|
66
65
|
}
|
|
67
|
-
export declare const libDef: {
|
|
68
|
-
readonly name: "@typespec/openapi3";
|
|
69
|
-
readonly diagnostics: {
|
|
70
|
-
readonly "oneof-union": {
|
|
71
|
-
readonly severity: "error";
|
|
72
|
-
readonly messages: {
|
|
73
|
-
readonly default: "@oneOf decorator can only be used on a union or a model property which type is a union.";
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
readonly "inconsistent-shared-route-request-visibility": {
|
|
77
|
-
readonly severity: "error";
|
|
78
|
-
readonly messages: {
|
|
79
|
-
readonly default: "All operations with `@sharedRoutes` must have the same `@requestVisibility`.";
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
readonly "invalid-server-variable": {
|
|
83
|
-
readonly severity: "error";
|
|
84
|
-
readonly messages: {
|
|
85
|
-
readonly default: import("@typespec/compiler").CallableMessage<["propName"]>;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
readonly "invalid-format": {
|
|
89
|
-
readonly severity: "warning";
|
|
90
|
-
readonly messages: {
|
|
91
|
-
readonly default: import("@typespec/compiler").CallableMessage<["value", "paramType"]>;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
readonly "invalid-style": {
|
|
95
|
-
readonly severity: "warning";
|
|
96
|
-
readonly messages: {
|
|
97
|
-
readonly default: import("@typespec/compiler").CallableMessage<["style", "paramType"]>;
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
readonly "path-reserved-expansion": {
|
|
101
|
-
readonly severity: "warning";
|
|
102
|
-
readonly messages: {
|
|
103
|
-
readonly default: "Reserved expansion of path parameter with '+' operator #{allowReserved: true} is not supported in OpenAPI3.";
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
readonly "resource-namespace": {
|
|
107
|
-
readonly severity: "error";
|
|
108
|
-
readonly messages: {
|
|
109
|
-
readonly default: "Resource goes on namespace";
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
readonly "path-query": {
|
|
113
|
-
readonly severity: "error";
|
|
114
|
-
readonly messages: {
|
|
115
|
-
readonly default: "OpenAPI does not allow paths containing a query string.";
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
readonly "duplicate-header": {
|
|
119
|
-
readonly severity: "error";
|
|
120
|
-
readonly messages: {
|
|
121
|
-
readonly default: import("@typespec/compiler").CallableMessage<["header"]>;
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
readonly "status-code-in-default-response": {
|
|
125
|
-
readonly severity: "error";
|
|
126
|
-
readonly messages: {
|
|
127
|
-
readonly default: "a default response should not have an explicit status code";
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
readonly "invalid-schema": {
|
|
131
|
-
readonly severity: "error";
|
|
132
|
-
readonly messages: {
|
|
133
|
-
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
readonly "union-null": {
|
|
137
|
-
readonly severity: "error";
|
|
138
|
-
readonly messages: {
|
|
139
|
-
readonly default: "Cannot have a union containing only null types.";
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
readonly "empty-union": {
|
|
143
|
-
readonly severity: "error";
|
|
144
|
-
readonly messages: {
|
|
145
|
-
readonly default: "Empty unions are not supported for OpenAPI v3 - enums must have at least one value.";
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
readonly "empty-enum": {
|
|
149
|
-
readonly severity: "error";
|
|
150
|
-
readonly messages: {
|
|
151
|
-
readonly default: "Empty enums are not supported for OpenAPI v3 - enums must have at least one value.";
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
readonly "enum-unique-type": {
|
|
155
|
-
readonly severity: "error";
|
|
156
|
-
readonly messages: {
|
|
157
|
-
readonly default: "Enums are not supported unless all options are literals of the same type.";
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
readonly "inline-cycle": {
|
|
161
|
-
readonly severity: "error";
|
|
162
|
-
readonly messages: {
|
|
163
|
-
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
readonly "unsupported-status-code-range": {
|
|
167
|
-
readonly severity: "error";
|
|
168
|
-
readonly messages: {
|
|
169
|
-
readonly default: import("@typespec/compiler").CallableMessage<["start", "end"]>;
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
readonly "invalid-model-property": {
|
|
173
|
-
readonly severity: "error";
|
|
174
|
-
readonly messages: {
|
|
175
|
-
readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
readonly "unsupported-auth": {
|
|
179
|
-
readonly severity: "warning";
|
|
180
|
-
readonly messages: {
|
|
181
|
-
readonly default: import("@typespec/compiler").CallableMessage<["authType"]>;
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
readonly "xml-attribute-invalid-property-type": {
|
|
185
|
-
readonly severity: "warning";
|
|
186
|
-
readonly messages: {
|
|
187
|
-
readonly default: import("@typespec/compiler").CallableMessage<["name"]>;
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
readonly "xml-unwrapped-invalid-property-type": {
|
|
191
|
-
readonly severity: "warning";
|
|
192
|
-
readonly messages: {
|
|
193
|
-
readonly default: import("@typespec/compiler").CallableMessage<["name"]>;
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
readonly "invalid-component-fixed-field-key": {
|
|
197
|
-
readonly severity: "warning";
|
|
198
|
-
readonly messages: {
|
|
199
|
-
readonly default: import("@typespec/compiler").CallableMessage<["value"]>;
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
readonly emitter: {
|
|
204
|
-
readonly options: JSONSchemaType<OpenAPI3EmitterOptions>;
|
|
205
|
-
};
|
|
206
|
-
};
|
|
207
66
|
export declare const $lib: import("@typespec/compiler").TypeSpecLibrary<{
|
|
208
67
|
"oneof-union": {
|
|
209
68
|
readonly default: "@oneOf decorator can only be used on a union or a model property which type is a union.";
|
package/dist/src/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AACvC,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,CAAC;AAC/C,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IAEH,WAAW,CAAC,EAAE,QAAQ,CAAC;IAEvB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAYvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC;IAEpD;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC;IAE5C;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAuGD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAkJf,CAAC;AACH,eAAO,MAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sDAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAE,iBAAiB,0BAAS,CAAC;AAE9E,MAAM,MAAM,cAAc,GAAG,OAAO,IAAI,CAAC"}
|
package/dist/src/lib.js
CHANGED
|
@@ -96,8 +96,11 @@ const EmitterOptionsSchema = {
|
|
|
96
96
|
},
|
|
97
97
|
required: [],
|
|
98
98
|
};
|
|
99
|
-
export const
|
|
99
|
+
export const $lib = createTypeSpecLibrary({
|
|
100
100
|
name: "@typespec/openapi3",
|
|
101
|
+
capabilities: {
|
|
102
|
+
dryRun: true,
|
|
103
|
+
},
|
|
101
104
|
diagnostics: {
|
|
102
105
|
"oneof-union": {
|
|
103
106
|
severity: "error",
|
|
@@ -235,7 +238,6 @@ export const libDef = {
|
|
|
235
238
|
emitter: {
|
|
236
239
|
options: EmitterOptionsSchema,
|
|
237
240
|
},
|
|
238
|
-
};
|
|
239
|
-
export const $lib = createTypeSpecLibrary(libDef);
|
|
241
|
+
});
|
|
240
242
|
export const { createDiagnostic, reportDiagnostic, createStateSymbol } = $lib;
|
|
241
243
|
//# sourceMappingURL=lib.js.map
|
package/dist/src/lib.js.map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M,kBAAkB,QAAO,cAErC,CAAC;AAEF,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"openapi-helpers-3-0.d.ts","sourceRoot":"","sources":["../../src/openapi-helpers-3-0.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAO5C,eAAO,MAAM,aAAa,EAAE,wBAAwB,CAAC,eAAe,CAOnE,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,cAErC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,QAAQ,cAAc,KAAG,OAE1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-helpers-3-1.d.ts","sourceRoot":"","sources":["../../src/openapi-helpers-3-1.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAc9C,eAAO,MAAM,aAAa,EAAE,wBAAwB,CAAC,eAAe,CAOnE,CAAC;AAEF,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"openapi-helpers-3-1.d.ts","sourceRoot":"","sources":["../../src/openapi-helpers-3-1.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAc9C,eAAO,MAAM,aAAa,EAAE,wBAAwB,CAAC,eAAe,CAOnE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,cAAc,MAAM,KAAG,gBAKzD,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,QAAQ,gBAAgB,KAAG,OAE5D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,EA8BX,OAAO,EACP,OAAO,EAKR,MAAM,oBAAoB,CAAC;AA6C5B,OAAO,EAAoB,QAAQ,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG9F,OAAO,EAcL,qBAAqB,EAOtB,MAAM,YAAY,CAAC;AAsBpB,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,sBAAsB,CAAC,iBAMzE;AAED,KAAK,yCAAyC,GAAG,WAAW,GAAG,aAAa,GAAG,UAAU,CAAC;AAO1F;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,IAAI,CAAC,sBAAsB,EAAE,yCAAyC,CAAM,GACpF,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAiBlC;AAgBD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,WAAW,CAAC,sBAAsB,CAAC,GAC3C,8BAA8B,CAuBhC;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,oBAAoB,EAAE,aAAa,GAAG,OAAO,CAAC;IAC9C,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC;IACxC,iBAAiB,EAAE,OAAO,CAAC;CAC5B"}
|
package/dist/src/openapi.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { compilerAssert, createDiagnosticCollector, emitFile, getAllTags, getAnyExtensionFromPath, getDoc, getFormat,
|
|
2
|
-
import { createAssetEmitter } from "@typespec/compiler/emitter-framework";
|
|
1
|
+
import { compilerAssert, createDiagnosticCollector, emitFile, getAllTags, getAnyExtensionFromPath, getDoc, getFormat, getMaxItems, getMaxLength, getMaxValue, getMaxValueExclusive, getMinItems, getMinLength, getMinValue, getMinValueExclusive, getNamespaceFullName, getPattern, getService, getSummary, ignoreDiagnostics, interpolatePath, isDeprecated, isGlobalNamespace, isNeverType, isSecret, isVoidType, listServices, navigateTypesInNamespace, resolvePath, } from "@typespec/compiler";
|
|
3
2
|
import { unsafe_mutateSubgraphWithNamespace, } from "@typespec/compiler/experimental";
|
|
4
|
-
import { createMetadataInfo, getHttpService, getServers, getStatusCodeDescription,
|
|
3
|
+
import { createMetadataInfo, getHttpService, getServers, getStatusCodeDescription, isOrExtendsHttpFile, isOverloadSameEndpoint, reportIfNoRoutes, resolveAuthentication, resolveRequestVisibility, Visibility, } from "@typespec/http";
|
|
5
4
|
import { getExtensions, getExternalDocs, getOpenAPITypeName, getParameterKey, getTagsMetadata, isReadonlyProperty, resolveOperationId, shouldInline, } from "@typespec/openapi";
|
|
6
|
-
import { getVersioningMutators } from "@typespec/versioning";
|
|
7
5
|
import { stringify } from "yaml";
|
|
8
6
|
import { getRef } from "./decorators.js";
|
|
9
7
|
import { getExampleOrExamples, resolveOperationExamples } from "./examples.js";
|
|
@@ -12,6 +10,7 @@ import { createDiagnostic } from "./lib.js";
|
|
|
12
10
|
import { getOpenApiSpecProps } from "./openapi-spec-mappings.js";
|
|
13
11
|
import { getOpenAPI3StatusCodes } from "./status-codes.js";
|
|
14
12
|
import { deepEquals, ensureValidComponentFixedFieldKey, getDefaultValue, isBytesKeptRaw, isSharedHttpOperation, } from "./util.js";
|
|
13
|
+
import { resolveVersioningModule } from "./versioning-module.js";
|
|
15
14
|
import { resolveVisibilityUsage } from "./visibility-usage.js";
|
|
16
15
|
import { resolveXmlModule } from "./xml-module.js";
|
|
17
16
|
const defaultFileType = "yaml";
|
|
@@ -43,9 +42,6 @@ export async function getOpenAPI3(program, options = {}) {
|
|
|
43
42
|
// this value doesn't matter for getting the OpenAPI3 objects
|
|
44
43
|
emitterOutputDir: "tsp-output",
|
|
45
44
|
options: options,
|
|
46
|
-
getAssetEmitter(TypeEmitterClass) {
|
|
47
|
-
return createAssetEmitter(program, TypeEmitterClass, this);
|
|
48
|
-
},
|
|
49
45
|
};
|
|
50
46
|
const resolvedOptions = resolveOptions(context);
|
|
51
47
|
const serviceRecords = [];
|
|
@@ -131,7 +127,7 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
131
127
|
program.reportDiagnostics(serviceRecord.diagnostics);
|
|
132
128
|
}
|
|
133
129
|
}
|
|
134
|
-
if (program.compilerOptions.
|
|
130
|
+
if (program.compilerOptions.dryRun || program.hasError()) {
|
|
135
131
|
return;
|
|
136
132
|
}
|
|
137
133
|
const multipleService = services.length > 1;
|
|
@@ -201,9 +197,7 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
201
197
|
case "String":
|
|
202
198
|
case "Union":
|
|
203
199
|
case "Scalar":
|
|
204
|
-
return ignoreDiagnostics(program.checker.isTypeAssignableTo(
|
|
205
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
206
|
-
type.projectionBase ?? type, program.checker.getStdType("string"), type));
|
|
200
|
+
return ignoreDiagnostics(program.checker.isTypeAssignableTo(type, program.checker.getStdType("string"), type));
|
|
207
201
|
case "Enum":
|
|
208
202
|
for (const member of type.members.values()) {
|
|
209
203
|
if (member.value && typeof member.value !== "string") {
|
|
@@ -259,13 +253,14 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
259
253
|
});
|
|
260
254
|
}
|
|
261
255
|
async function getOpenAPI() {
|
|
256
|
+
const versioningModule = await resolveVersioningModule();
|
|
262
257
|
const serviceRecords = [];
|
|
263
258
|
const services = listServices(program);
|
|
264
259
|
if (services.length === 0) {
|
|
265
260
|
services.push({ type: program.getGlobalNamespaceType() });
|
|
266
261
|
}
|
|
267
262
|
for (const service of services) {
|
|
268
|
-
const versions = getVersioningMutators(program, service.type);
|
|
263
|
+
const versions = versioningModule?.getVersioningMutators(program, service.type);
|
|
269
264
|
if (versions === undefined) {
|
|
270
265
|
const document = await getOpenApiFromVersion(service);
|
|
271
266
|
if (document === undefined) {
|
|
@@ -350,51 +345,54 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
350
345
|
* Validates that common parameters are consistent and returns the minimal set that describes the differences.
|
|
351
346
|
*/
|
|
352
347
|
function resolveSharedRouteParameters(ops) {
|
|
353
|
-
const
|
|
354
|
-
const
|
|
348
|
+
const finalProps = [];
|
|
349
|
+
const properties = new Map();
|
|
355
350
|
for (const op of ops) {
|
|
356
|
-
for (const
|
|
357
|
-
|
|
351
|
+
for (const property of op.parameters.properties) {
|
|
352
|
+
if (!isHttpParameterProperty(property)) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const existing = properties.get(property.options.name);
|
|
358
356
|
if (existing) {
|
|
359
|
-
existing.push(
|
|
357
|
+
existing.push(property);
|
|
360
358
|
}
|
|
361
359
|
else {
|
|
362
|
-
|
|
360
|
+
properties.set(property.options.name, [property]);
|
|
363
361
|
}
|
|
364
362
|
}
|
|
365
363
|
}
|
|
366
|
-
if (
|
|
364
|
+
if (properties.size === 0) {
|
|
367
365
|
return [];
|
|
368
366
|
}
|
|
369
|
-
for (const sharedParams of
|
|
367
|
+
for (const sharedParams of properties.values()) {
|
|
370
368
|
const reference = sharedParams[0];
|
|
371
369
|
const inAllOps = ops.length === sharedParams.length;
|
|
372
|
-
const sameLocations = sharedParams.every((p) => p.type === reference.type);
|
|
373
|
-
const sameOptionality = sharedParams.every((p) => p.
|
|
374
|
-
const sameTypeKind = sharedParams.every((p) => p.
|
|
375
|
-
const sameTypeValue = sharedParams.every((p) => p.
|
|
370
|
+
const sameLocations = sharedParams.every((p) => p.options.type === reference.options.type);
|
|
371
|
+
const sameOptionality = sharedParams.every((p) => p.property.optional === reference.property.optional);
|
|
372
|
+
const sameTypeKind = sharedParams.every((p) => p.property.type.kind === reference.property.type.kind);
|
|
373
|
+
const sameTypeValue = sharedParams.every((p) => p.property.type === reference.property.type);
|
|
376
374
|
if (inAllOps && sameLocations && sameOptionality && sameTypeKind && sameTypeValue) {
|
|
377
375
|
// param is consistent and in all shared operations. Only need one copy.
|
|
378
|
-
|
|
376
|
+
finalProps.push(reference);
|
|
379
377
|
}
|
|
380
378
|
else if (!inAllOps && sameLocations && sameOptionality && sameTypeKind && sameTypeValue) {
|
|
381
379
|
// param is consistent when used, but does not appear in all shared operations. Only need one copy, but it must be optional.
|
|
382
|
-
reference.
|
|
383
|
-
|
|
380
|
+
reference.property.optional = true;
|
|
381
|
+
finalProps.push(reference);
|
|
384
382
|
}
|
|
385
383
|
else if (inAllOps && !(sameLocations && sameOptionality && sameTypeKind)) {
|
|
386
384
|
// param is in all shared operations, but is not consistent. Need multiple copies, which must be optional.
|
|
387
385
|
// exception allowed when the params only differ by their value (e.g. string enum values)
|
|
388
386
|
sharedParams.forEach((p) => {
|
|
389
|
-
p.
|
|
387
|
+
p.property.optional = true;
|
|
390
388
|
});
|
|
391
|
-
|
|
389
|
+
finalProps.push(...sharedParams);
|
|
392
390
|
}
|
|
393
391
|
else {
|
|
394
|
-
|
|
392
|
+
finalProps.push(...sharedParams);
|
|
395
393
|
}
|
|
396
394
|
}
|
|
397
|
-
return
|
|
395
|
+
return finalProps;
|
|
398
396
|
}
|
|
399
397
|
function buildSharedOperation(operations) {
|
|
400
398
|
return {
|
|
@@ -565,7 +563,7 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
565
563
|
operationId: resolveOperationId(program, operation.operation),
|
|
566
564
|
summary: getSummary(program, operation.operation),
|
|
567
565
|
description: getDoc(program, operation.operation),
|
|
568
|
-
parameters: getEndpointParameters(parameters.
|
|
566
|
+
parameters: getEndpointParameters(parameters.properties, visibility),
|
|
569
567
|
responses: getResponses(operation, operation.responses, examples),
|
|
570
568
|
};
|
|
571
569
|
const currentTags = getAllTags(program, op);
|
|
@@ -866,13 +864,13 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
866
864
|
}
|
|
867
865
|
return false;
|
|
868
866
|
}
|
|
869
|
-
function getParameter(
|
|
867
|
+
function getParameter(httpProperty, visibility) {
|
|
870
868
|
const param = {
|
|
871
|
-
name:
|
|
872
|
-
in:
|
|
873
|
-
...getOpenAPIParameterBase(
|
|
869
|
+
name: httpProperty.options.name,
|
|
870
|
+
in: httpProperty.options.type,
|
|
871
|
+
...getOpenAPIParameterBase(httpProperty.property, visibility),
|
|
874
872
|
};
|
|
875
|
-
const attributes = getParameterAttributes(
|
|
873
|
+
const attributes = getParameterAttributes(httpProperty);
|
|
876
874
|
if (attributes === undefined) {
|
|
877
875
|
param.schema = {
|
|
878
876
|
type: "string",
|
|
@@ -881,23 +879,22 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
881
879
|
else {
|
|
882
880
|
Object.assign(param, attributes);
|
|
883
881
|
}
|
|
884
|
-
if (isDeprecated(program,
|
|
882
|
+
if (isDeprecated(program, httpProperty.property)) {
|
|
885
883
|
param.deprecated = true;
|
|
886
884
|
}
|
|
887
885
|
return param;
|
|
888
886
|
}
|
|
889
|
-
function getEndpointParameters(
|
|
887
|
+
function getEndpointParameters(properties, visibility) {
|
|
890
888
|
const result = [];
|
|
891
|
-
for (const
|
|
892
|
-
if (params.has(
|
|
893
|
-
result.push(params.get(
|
|
889
|
+
for (const httpProp of properties) {
|
|
890
|
+
if (params.has(httpProp.property)) {
|
|
891
|
+
result.push(params.get(httpProp.property));
|
|
894
892
|
continue;
|
|
895
893
|
}
|
|
896
|
-
|
|
897
|
-
if (httpOpParam.type === "header" && isContentTypeHeader(program, httpOpParam.param)) {
|
|
894
|
+
if (!isHttpParameterProperty(httpProp)) {
|
|
898
895
|
continue;
|
|
899
896
|
}
|
|
900
|
-
const param = getParameterOrRef(
|
|
897
|
+
const param = getParameterOrRef(httpProp, visibility);
|
|
901
898
|
if (param) {
|
|
902
899
|
const existing = result.find((x) => !("$ref" in param) && !("$ref" in x) && x.name === param.name && x.in === param.in);
|
|
903
900
|
if (existing && !("$ref" in param) && !("$ref" in existing)) {
|
|
@@ -951,12 +948,12 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
951
948
|
}
|
|
952
949
|
return requestBody;
|
|
953
950
|
}
|
|
954
|
-
function getParameterOrRef(
|
|
955
|
-
if (isNeverType(
|
|
951
|
+
function getParameterOrRef(httpProperty, visibility) {
|
|
952
|
+
if (isNeverType(httpProperty.property.type)) {
|
|
956
953
|
return undefined;
|
|
957
954
|
}
|
|
958
955
|
let spreadParam = false;
|
|
959
|
-
let property =
|
|
956
|
+
let property = httpProperty.property;
|
|
960
957
|
if (property.sourceProperty) {
|
|
961
958
|
// chase our sources all the way back to the first place this property
|
|
962
959
|
// was defined.
|
|
@@ -975,7 +972,7 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
975
972
|
if (params.has(property)) {
|
|
976
973
|
return params.get(property);
|
|
977
974
|
}
|
|
978
|
-
const param = getParameter(
|
|
975
|
+
const param = getParameter(httpProperty, visibility);
|
|
979
976
|
// only parameters inherited by spreading from non-inlined type are shared in #/components/parameters
|
|
980
977
|
if (spreadParam && property.model && !shouldInline(program, property.model)) {
|
|
981
978
|
params.set(property, param);
|
|
@@ -1015,32 +1012,32 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
1015
1012
|
}
|
|
1016
1013
|
return target;
|
|
1017
1014
|
}
|
|
1018
|
-
function getParameterAttributes(
|
|
1019
|
-
switch (
|
|
1015
|
+
function getParameterAttributes(httpProperty) {
|
|
1016
|
+
switch (httpProperty.kind) {
|
|
1020
1017
|
case "header":
|
|
1021
|
-
return getHeaderParameterAttributes(
|
|
1018
|
+
return getHeaderParameterAttributes(httpProperty);
|
|
1022
1019
|
case "cookie":
|
|
1023
1020
|
// style and explode options are omitted from cookies
|
|
1024
1021
|
// https://github.com/microsoft/typespec/pull/4761#discussion_r1803365689
|
|
1025
1022
|
return { explode: false };
|
|
1026
1023
|
case "query":
|
|
1027
|
-
return getQueryParameterAttributes(
|
|
1024
|
+
return getQueryParameterAttributes(httpProperty);
|
|
1028
1025
|
case "path":
|
|
1029
|
-
return getPathParameterAttributes(
|
|
1026
|
+
return getPathParameterAttributes(httpProperty);
|
|
1030
1027
|
}
|
|
1031
1028
|
}
|
|
1032
|
-
function getPathParameterAttributes(
|
|
1033
|
-
if (
|
|
1029
|
+
function getPathParameterAttributes(httpProperty) {
|
|
1030
|
+
if (httpProperty.options.allowReserved) {
|
|
1034
1031
|
diagnostics.add(createDiagnostic({
|
|
1035
1032
|
code: "path-reserved-expansion",
|
|
1036
|
-
target:
|
|
1033
|
+
target: httpProperty.property,
|
|
1037
1034
|
}));
|
|
1038
1035
|
}
|
|
1039
1036
|
const attributes = {};
|
|
1040
|
-
if (
|
|
1037
|
+
if (httpProperty.options.explode) {
|
|
1041
1038
|
attributes.explode = true;
|
|
1042
1039
|
}
|
|
1043
|
-
switch (
|
|
1040
|
+
switch (httpProperty.options.style) {
|
|
1044
1041
|
case "label":
|
|
1045
1042
|
attributes.style = "label";
|
|
1046
1043
|
break;
|
|
@@ -1052,70 +1049,26 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
1052
1049
|
default:
|
|
1053
1050
|
diagnostics.add(createDiagnostic({
|
|
1054
1051
|
code: "invalid-style",
|
|
1055
|
-
format: { style:
|
|
1056
|
-
target:
|
|
1052
|
+
format: { style: httpProperty.options.style, paramType: "path" },
|
|
1053
|
+
target: httpProperty.property,
|
|
1057
1054
|
}));
|
|
1058
1055
|
}
|
|
1059
1056
|
return attributes;
|
|
1060
1057
|
}
|
|
1061
|
-
function getQueryParameterAttributes(
|
|
1058
|
+
function getQueryParameterAttributes(httpProperty) {
|
|
1062
1059
|
const attributes = {};
|
|
1063
|
-
if (
|
|
1060
|
+
if (httpProperty.options.explode !== true) {
|
|
1064
1061
|
// For query parameters(style: form) the default is explode: true https://spec.openapis.org/oas/v3.0.2#fixed-fields-9
|
|
1065
1062
|
attributes.explode = false;
|
|
1066
1063
|
}
|
|
1067
|
-
|
|
1068
|
-
switch (parameter.format) {
|
|
1069
|
-
case "ssv":
|
|
1070
|
-
return { style: "spaceDelimited", explode: false };
|
|
1071
|
-
case "pipes":
|
|
1072
|
-
return { style: "pipeDelimited", explode: false };
|
|
1073
|
-
case "csv":
|
|
1074
|
-
case "simple":
|
|
1075
|
-
return { explode: false };
|
|
1076
|
-
case undefined:
|
|
1077
|
-
case "multi":
|
|
1078
|
-
case "form":
|
|
1079
|
-
return attributes;
|
|
1080
|
-
default:
|
|
1081
|
-
diagnostics.add(createDiagnostic({
|
|
1082
|
-
code: "invalid-format",
|
|
1083
|
-
format: {
|
|
1084
|
-
paramType: "query",
|
|
1085
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
1086
|
-
value: parameter.format,
|
|
1087
|
-
},
|
|
1088
|
-
target: parameter.param,
|
|
1089
|
-
}));
|
|
1090
|
-
return undefined;
|
|
1091
|
-
}
|
|
1064
|
+
return attributes;
|
|
1092
1065
|
}
|
|
1093
|
-
function getHeaderParameterAttributes(
|
|
1066
|
+
function getHeaderParameterAttributes(httpProperty) {
|
|
1094
1067
|
const attributes = {};
|
|
1095
|
-
if (
|
|
1068
|
+
if (httpProperty.options.explode) {
|
|
1096
1069
|
// The default for headers is false, so only need to specify when true https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema-0
|
|
1097
1070
|
attributes.explode = true;
|
|
1098
1071
|
}
|
|
1099
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
1100
|
-
switch (parameter.format) {
|
|
1101
|
-
case undefined:
|
|
1102
|
-
return attributes;
|
|
1103
|
-
case "csv":
|
|
1104
|
-
case "simple":
|
|
1105
|
-
attributes.style = "simple";
|
|
1106
|
-
break;
|
|
1107
|
-
default:
|
|
1108
|
-
diagnostics.add(createDiagnostic({
|
|
1109
|
-
code: "invalid-format",
|
|
1110
|
-
format: {
|
|
1111
|
-
paramType: "header",
|
|
1112
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
1113
|
-
value: parameter.format,
|
|
1114
|
-
},
|
|
1115
|
-
target: parameter.param,
|
|
1116
|
-
}));
|
|
1117
|
-
return undefined;
|
|
1118
|
-
}
|
|
1119
1072
|
return attributes;
|
|
1120
1073
|
}
|
|
1121
1074
|
function emitParameters() {
|
|
@@ -1240,12 +1193,6 @@ function createOAPIEmitter(context, options, specVersion = "3.0.0") {
|
|
|
1240
1193
|
if (title) {
|
|
1241
1194
|
newTarget.title = title;
|
|
1242
1195
|
}
|
|
1243
|
-
const values = getKnownValues(program, typespecType);
|
|
1244
|
-
if (values) {
|
|
1245
|
-
return {
|
|
1246
|
-
oneOf: [newTarget, callSchemaEmitter(values, Visibility.Read, false, "application/json")],
|
|
1247
|
-
};
|
|
1248
|
-
}
|
|
1249
1196
|
attachExtensions(program, typespecType, newTarget);
|
|
1250
1197
|
return newTarget;
|
|
1251
1198
|
}
|
|
@@ -1377,4 +1324,7 @@ function sortOpenAPIDocument(doc) {
|
|
|
1377
1324
|
doc.components.parameters = sortObjectByKeys(doc.components.parameters);
|
|
1378
1325
|
}
|
|
1379
1326
|
}
|
|
1327
|
+
function isHttpParameterProperty(httpProperty) {
|
|
1328
|
+
return ["header", "query", "path", "cookie"].includes(httpProperty.kind);
|
|
1329
|
+
}
|
|
1380
1330
|
//# sourceMappingURL=openapi.js.map
|