@typespec/openapi3 0.58.0-dev.7 → 0.58.0-dev.9
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/cli/actions/convert/generators/generate-main.d.ts.map +1 -1
- package/dist/src/cli/actions/convert/generators/generate-main.js +5 -0
- package/dist/src/cli/actions/convert/generators/generate-main.js.map +1 -1
- package/dist/src/cli/actions/convert/generators/generate-namespace.d.ts +3 -0
- package/dist/src/cli/actions/convert/generators/generate-namespace.d.ts.map +1 -0
- package/dist/src/cli/actions/convert/generators/generate-namespace.js +14 -0
- package/dist/src/cli/actions/convert/generators/generate-namespace.js.map +1 -0
- package/dist/src/cli/actions/convert/generators/generate-operation.d.ts.map +1 -1
- package/dist/src/cli/actions/convert/generators/generate-operation.js +4 -23
- package/dist/src/cli/actions/convert/generators/generate-operation.js.map +1 -1
- package/dist/src/cli/actions/convert/generators/generate-types.d.ts.map +1 -1
- package/dist/src/cli/actions/convert/generators/generate-types.js +2 -2
- package/dist/src/cli/actions/convert/generators/generate-types.js.map +1 -1
- package/dist/src/cli/actions/convert/interfaces.d.ts +15 -6
- package/dist/src/cli/actions/convert/interfaces.d.ts.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transform-component-parameters.d.ts.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transform-component-parameters.js +29 -23
- package/dist/src/cli/actions/convert/transforms/transform-component-parameters.js.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transform-component-schemas.d.ts.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transform-component-schemas.js +18 -13
- package/dist/src/cli/actions/convert/transforms/transform-component-schemas.js.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transform-namespaces.d.ts +5 -0
- package/dist/src/cli/actions/convert/transforms/transform-namespaces.d.ts.map +1 -0
- package/dist/src/cli/actions/convert/transforms/transform-namespaces.js +51 -0
- package/dist/src/cli/actions/convert/transforms/transform-namespaces.js.map +1 -0
- package/dist/src/cli/actions/convert/transforms/transform-operation-responses.d.ts +4 -5
- package/dist/src/cli/actions/convert/transforms/transform-operation-responses.d.ts.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transform-operation-responses.js +14 -33
- package/dist/src/cli/actions/convert/transforms/transform-operation-responses.js.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transform-paths.d.ts +3 -2
- package/dist/src/cli/actions/convert/transforms/transform-paths.d.ts.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transform-paths.js +11 -4
- package/dist/src/cli/actions/convert/transforms/transform-paths.js.map +1 -1
- package/dist/src/cli/actions/convert/transforms/transforms.js +3 -5
- package/dist/src/cli/actions/convert/transforms/transforms.js.map +1 -1
- package/dist/src/cli/actions/convert/utils/get-scope-and-name.d.ts +9 -0
- package/dist/src/cli/actions/convert/utils/get-scope-and-name.d.ts.map +1 -0
- package/dist/src/cli/actions/convert/utils/get-scope-and-name.js +12 -0
- package/dist/src/cli/actions/convert/utils/get-scope-and-name.js.map +1 -0
- package/dist/src/openapi.d.ts.map +1 -1
- package/dist/src/openapi.js +83 -30
- package/dist/src/openapi.js.map +1 -1
- package/dist/src/schema-emitter.d.ts.map +1 -1
- package/dist/src/schema-emitter.js +9 -1
- package/dist/src/schema-emitter.js.map +1 -1
- package/dist/src/types.d.ts +8 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/util.d.ts +4 -0
- package/dist/src/util.d.ts.map +1 -1
- package/dist/src/util.js +6 -0
- package/dist/src/util.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-operation-responses.js","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/transforms/transform-operation-responses.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform-operation-responses.js","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/transforms/transform-operation-responses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;A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AE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SAC5D,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { OpenAPI3PathItem } from "../../../../types.js";
|
|
2
|
-
import { TypeSpecOperation } from "../interfaces.js";
|
|
2
|
+
import { TypeSpecModel, TypeSpecOperation } from "../interfaces.js";
|
|
3
3
|
/**
|
|
4
4
|
* Transforms each operation defined under #/paths/{route}/{httpMethod} into a TypeSpec operation.
|
|
5
|
+
* @params models - The array of models to populate with any new models generated from the operation.
|
|
5
6
|
* @param paths
|
|
6
7
|
* @returns
|
|
7
8
|
*/
|
|
8
|
-
export declare function transformPaths(paths: Record<string, OpenAPI3PathItem>): TypeSpecOperation[];
|
|
9
|
+
export declare function transformPaths(models: TypeSpecModel[], paths: Record<string, OpenAPI3PathItem>): TypeSpecOperation[];
|
|
9
10
|
//# sourceMappingURL=transform-paths.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-paths.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/transforms/transform-paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform-paths.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/transforms/transform-paths.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,gBAAgB,EAGjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EACb,iBAAiB,EAGlB,MAAM,kBAAkB,CAAC;AAM1B;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EAAE,EACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,GACtC,iBAAiB,EAAE,CAkCrB"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { printIdentifier } from "@typespec/compiler";
|
|
1
2
|
import { getExtensions, getParameterDecorators } from "../utils/decorators.js";
|
|
3
|
+
import { getScopeAndName } from "../utils/get-scope-and-name.js";
|
|
2
4
|
import { supportedHttpMethods } from "../utils/supported-http-methods.js";
|
|
5
|
+
import { collectOperationResponses } from "./transform-operation-responses.js";
|
|
3
6
|
/**
|
|
4
7
|
* Transforms each operation defined under #/paths/{route}/{httpMethod} into a TypeSpec operation.
|
|
8
|
+
* @params models - The array of models to populate with any new models generated from the operation.
|
|
5
9
|
* @param paths
|
|
6
10
|
* @returns
|
|
7
11
|
*/
|
|
8
|
-
export function transformPaths(paths) {
|
|
12
|
+
export function transformPaths(models, paths) {
|
|
9
13
|
const operations = [];
|
|
10
14
|
for (const route of Object.keys(paths)) {
|
|
11
15
|
const path = paths[route];
|
|
@@ -15,8 +19,11 @@ export function transformPaths(paths) {
|
|
|
15
19
|
continue;
|
|
16
20
|
const parameters = operation.parameters?.map(transformOperationParameter) ?? [];
|
|
17
21
|
const tags = operation.tags?.map((t) => t) ?? [];
|
|
22
|
+
const operationResponses = operation.responses ?? {};
|
|
23
|
+
const responseModels = collectOperationResponses(operation.operationId, operationResponses);
|
|
24
|
+
models.push(...responseModels);
|
|
18
25
|
operations.push({
|
|
19
|
-
|
|
26
|
+
...getScopeAndName(operation.operationId),
|
|
20
27
|
decorators: [
|
|
21
28
|
...getExtensions(operation),
|
|
22
29
|
{ name: "route", args: [route] },
|
|
@@ -26,7 +33,7 @@ export function transformPaths(paths) {
|
|
|
26
33
|
doc: operation.description,
|
|
27
34
|
operationId: operation.operationId,
|
|
28
35
|
requestBodies: transformRequestBodies(operation.requestBody),
|
|
29
|
-
|
|
36
|
+
responseTypes: responseModels.map((m) => m.name),
|
|
30
37
|
tags: tags,
|
|
31
38
|
});
|
|
32
39
|
}
|
|
@@ -38,7 +45,7 @@ function transformOperationParameter(parameter) {
|
|
|
38
45
|
return { $ref: parameter.$ref };
|
|
39
46
|
}
|
|
40
47
|
return {
|
|
41
|
-
name: parameter.name,
|
|
48
|
+
name: printIdentifier(parameter.name),
|
|
42
49
|
doc: parameter.description,
|
|
43
50
|
decorators: getParameterDecorators(parameter),
|
|
44
51
|
isOptional: !parameter.required,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-paths.js","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/transforms/transform-paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform-paths.js","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/transforms/transform-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAarD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAuB,EACvB,KAAuC;IAEvC,MAAM,UAAU,GAAwB,EAAE,CAAC;IAE3C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,KAAK,MAAM,IAAI,IAAI,oBAAoB,EAAE,CAAC;YACxC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,SAAS;gBAAE,SAAS;YAEzB,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,2BAA2B,CAAC,IAAI,EAAE,CAAC;YAChF,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAEjD,MAAM,kBAAkB,GAAG,SAAS,CAAC,SAAS,IAAI,EAAE,CAAC;YAC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AO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,cAAc,GAA0B,EAAE,CAAC;IACjD,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7D,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACvD,cAAc,CAAC,IAAI,CAAC;YAClB,WAAW;YACX,UAAU,EAAE,CAAC,aAAa,CAAC,QAAQ;YACnC,GAAG,EAAE,aAAa,CAAC,WAAW;YAC9B,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,MAAM,EAAE,WAAW,CAAC,MAAM;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { transformComponentParameters } from "./transform-component-parameters.js";
|
|
2
2
|
import { transformComponentSchemas } from "./transform-component-schemas.js";
|
|
3
|
-
import {
|
|
3
|
+
import { transformNamespaces } from "./transform-namespaces.js";
|
|
4
4
|
import { transformPaths } from "./transform-paths.js";
|
|
5
5
|
import { transformServiceInfo } from "./transform-service-info.js";
|
|
6
6
|
export function transform(openapi) {
|
|
7
7
|
const models = collectModels(openapi);
|
|
8
|
+
const operations = transformPaths(models, openapi.paths);
|
|
8
9
|
return {
|
|
9
10
|
serviceInfo: transformServiceInfo(openapi.info),
|
|
10
|
-
models,
|
|
11
|
+
...transformNamespaces(models, operations),
|
|
11
12
|
augmentations: [],
|
|
12
|
-
operations: transformPaths(openapi.paths),
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
function collectModels(document) {
|
|
@@ -19,8 +19,6 @@ function collectModels(document) {
|
|
|
19
19
|
transformComponentSchemas(models, components?.schemas);
|
|
20
20
|
// get models from `#/components/parameters
|
|
21
21
|
transformComponentParameters(models, components?.parameters);
|
|
22
|
-
// get models from #/paths/{route}/{httpMethod}/responses
|
|
23
|
-
transformAllOperationResponses(models, document);
|
|
24
22
|
return models;
|
|
25
23
|
}
|
|
26
24
|
//# sourceMappingURL=transforms.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transforms.js","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/transforms/transforms.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"transforms.js","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/transforms/transforms.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAEzD,OAAO;QACL,WAAW,EAAE,oBAAoB,CAAC,OAAO,CAAC,IAAI,CAAC;QAC/C,GAAG,mBAAmB,CAAC,MAAM,EAAE,UAAU,CAAC;QAC1C,aAAa,EAAE,EAAE;KAClB,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,QAA0B;IAC/C,MAAM,MAAM,GAAoB,EAAE,CAAC;IACnC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACvC,uCAAuC;IACvC,yBAAyB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IACvD,2CAA2C;IAC3C,4BAA4B,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE7D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type ScopeAndName = {
|
|
2
|
+
scope: string[];
|
|
3
|
+
name: string;
|
|
4
|
+
rawName: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function getScopeAndName(originalName: string): ScopeAndName;
|
|
7
|
+
export declare function scopesMatch(a: string[], b: string[]): boolean;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=get-scope-and-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-scope-and-name.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/utils/get-scope-and-name.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AACvE,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CAKlE;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAG7D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { printIdentifier } from "@typespec/compiler";
|
|
2
|
+
export function getScopeAndName(originalName) {
|
|
3
|
+
const path = originalName.split(".");
|
|
4
|
+
const name = path.pop();
|
|
5
|
+
return { scope: path.map(printIdentifier), name: printIdentifier(name), rawName: name };
|
|
6
|
+
}
|
|
7
|
+
export function scopesMatch(a, b) {
|
|
8
|
+
if (a.length !== b.length)
|
|
9
|
+
return false;
|
|
10
|
+
return a.every((scope, i) => scope === b[i]);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=get-scope-and-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-scope-and-name.js","sourceRoot":"","sources":["../../../../../../src/cli/actions/convert/utils/get-scope-and-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,UAAU,eAAe,CAAC,YAAoB;IAClD,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAG,CAAC;IAEzB,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAW,EAAE,CAAW;IAClD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,WAAW,
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,WAAW,EAiCX,OAAO,EAGP,OAAO,EASR,MAAM,oBAAoB,CAAC;AAkD5B,OAAO,EAAoB,QAAQ,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE9E,OAAO,EAeL,qBAAqB,EAItB,MAAM,YAAY,CAAC;AAYpB,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,sBAAsB,CAAC,iBAIzE;AAED,KAAK,yCAAyC,GAAG,WAAW,GAAG,aAAa,GAAG,UAAU,CAAC;AAE1F;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,IAAI,CAAC,sBAAsB,EAAE,yCAAyC,CAAM,GACpF,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAgBlC;AAgBD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,WAAW,CAAC,sBAAsB,CAAC,GAC3C,8BAA8B,CAgBhC;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,oBAAoB,EAAE,aAAa,GAAG,OAAO,CAAC;IAC9C,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC;CACzC"}
|
package/dist/src/openapi.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compilerAssert, createDiagnosticCollector, emitFile, getAllTags, getAnyExtensionFromPath, getDoc, getEncode, getFormat, getKnownValues, getMaxItems, getMaxLength, getMaxValue, getMaxValueExclusive, getMinItems, getMinLength, getMinValue, getMinValueExclusive, getNamespaceFullName, getPattern, getService, getSummary, ignoreDiagnostics, interpolatePath, isDeprecated, isGlobalNamespace, isNeverType, isSecret, isVoidType, listServices, navigateTypesInNamespace, projectProgram, resolvePath, } from "@typespec/compiler";
|
|
1
|
+
import { compilerAssert, createDiagnosticCollector, emitFile, getAllTags, getAnyExtensionFromPath, getDoc, getEncode, getFormat, getKnownValues, getMaxItems, getMaxLength, getMaxValue, getMaxValueExclusive, getMinItems, getMinLength, getMinValue, getMinValueExclusive, getNamespaceFullName, getOpExamples, getPattern, getService, getSummary, ignoreDiagnostics, interpolatePath, isDeprecated, isGlobalNamespace, isNeverType, isSecret, isVoidType, listServices, navigateTypesInNamespace, projectProgram, resolvePath, serializeValueAsJson, } from "@typespec/compiler";
|
|
2
2
|
import { createAssetEmitter } from "@typespec/compiler/emitter-framework";
|
|
3
3
|
import { createMetadataInfo, getHttpService, getServers, getStatusCodeDescription, isContentTypeHeader, isOrExtendsHttpFile, isOverloadSameEndpoint, reportIfNoRoutes, resolveAuthentication, resolveRequestVisibility, Visibility, } from "@typespec/http";
|
|
4
4
|
import { getExtensions, getExternalDocs, getOpenAPITypeName, getParameterKey, isDefaultResponse, isReadonlyProperty, resolveInfo, resolveOperationId, shouldInline, } from "@typespec/openapi";
|
|
@@ -7,7 +7,7 @@ import { stringify } from "yaml";
|
|
|
7
7
|
import { getRef } from "./decorators.js";
|
|
8
8
|
import { createDiagnostic } from "./lib.js";
|
|
9
9
|
import { getDefaultValue, isBytesKeptRaw, OpenAPI3SchemaEmitter } from "./schema-emitter.js";
|
|
10
|
-
import { deepEquals } from "./util.js";
|
|
10
|
+
import { deepEquals, isDefined } from "./util.js";
|
|
11
11
|
import { resolveVisibilityUsage } from "./visibility-usage.js";
|
|
12
12
|
const defaultFileType = "yaml";
|
|
13
13
|
const defaultOptions = {
|
|
@@ -616,13 +616,13 @@ function createOAPIEmitter(context, options) {
|
|
|
616
616
|
emitEndpointParameters(shared.parameters.parameters, visibility);
|
|
617
617
|
if (shared.bodies) {
|
|
618
618
|
if (shared.bodies.length === 1) {
|
|
619
|
-
emitRequestBody(shared.bodies[0], visibility);
|
|
619
|
+
emitRequestBody(shared, shared.bodies[0], visibility);
|
|
620
620
|
}
|
|
621
621
|
else if (shared.bodies.length > 1) {
|
|
622
|
-
emitMergedRequestBody(shared.bodies, visibility);
|
|
622
|
+
emitMergedRequestBody(shared, shared.bodies, visibility);
|
|
623
623
|
}
|
|
624
624
|
}
|
|
625
|
-
emitSharedResponses(shared.responses);
|
|
625
|
+
emitSharedResponses(shared, shared.responses);
|
|
626
626
|
for (const op of ops) {
|
|
627
627
|
if (isDeprecated(program, op)) {
|
|
628
628
|
currentEndpoint.deprecated = true;
|
|
@@ -665,8 +665,8 @@ function createOAPIEmitter(context, options) {
|
|
|
665
665
|
currentEndpoint.responses = {};
|
|
666
666
|
const visibility = resolveRequestVisibility(program, operation.operation, verb);
|
|
667
667
|
emitEndpointParameters(parameters.parameters, visibility);
|
|
668
|
-
emitRequestBody(parameters.body, visibility);
|
|
669
|
-
emitResponses(operation.responses);
|
|
668
|
+
emitRequestBody(operation, parameters.body, visibility);
|
|
669
|
+
emitResponses(operation, operation.responses);
|
|
670
670
|
if (authReference) {
|
|
671
671
|
emitEndpointSecurity(authReference);
|
|
672
672
|
}
|
|
@@ -675,20 +675,20 @@ function createOAPIEmitter(context, options) {
|
|
|
675
675
|
}
|
|
676
676
|
attachExtensions(program, op, currentEndpoint);
|
|
677
677
|
}
|
|
678
|
-
function emitSharedResponses(responses) {
|
|
678
|
+
function emitSharedResponses(operation, responses) {
|
|
679
679
|
for (const [statusCode, statusCodeResponses] of responses) {
|
|
680
680
|
if (statusCodeResponses.length === 1) {
|
|
681
|
-
emitResponseObject(statusCode, statusCodeResponses[0]);
|
|
681
|
+
emitResponseObject(operation, statusCode, statusCodeResponses[0]);
|
|
682
682
|
}
|
|
683
683
|
else {
|
|
684
|
-
emitMergedResponseObject(statusCode, statusCodeResponses);
|
|
684
|
+
emitMergedResponseObject(operation, statusCode, statusCodeResponses);
|
|
685
685
|
}
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
|
-
function emitResponses(responses) {
|
|
688
|
+
function emitResponses(operation, responses) {
|
|
689
689
|
for (const response of responses) {
|
|
690
690
|
for (const statusCode of getOpenAPI3StatusCodes(response.statusCodes, response.type)) {
|
|
691
|
-
emitResponseObject(statusCode, response);
|
|
691
|
+
emitResponseObject(operation, statusCode, response);
|
|
692
692
|
}
|
|
693
693
|
}
|
|
694
694
|
}
|
|
@@ -698,7 +698,7 @@ function createOAPIEmitter(context, options) {
|
|
|
698
698
|
contentType !== "application/json" &&
|
|
699
699
|
contentType !== "text/plain");
|
|
700
700
|
}
|
|
701
|
-
function emitMergedResponseObject(statusCode, responses) {
|
|
701
|
+
function emitMergedResponseObject(operation, statusCode, responses) {
|
|
702
702
|
const openApiResponse = {
|
|
703
703
|
description: undefined,
|
|
704
704
|
content: {},
|
|
@@ -711,19 +711,19 @@ function createOAPIEmitter(context, options) {
|
|
|
711
711
|
: response.description;
|
|
712
712
|
}
|
|
713
713
|
emitResponseHeaders(openApiResponse, response.responses, response.type);
|
|
714
|
-
emitResponseContent(openApiResponse, response.responses, schemaMap);
|
|
714
|
+
emitResponseContent(operation, openApiResponse, response.responses, schemaMap);
|
|
715
715
|
if (!openApiResponse.description) {
|
|
716
716
|
openApiResponse.description = getResponseDescriptionForStatusCode(statusCode);
|
|
717
717
|
}
|
|
718
718
|
currentEndpoint.responses[statusCode] = openApiResponse;
|
|
719
719
|
}
|
|
720
720
|
}
|
|
721
|
-
function emitResponseObject(statusCode, response) {
|
|
721
|
+
function emitResponseObject(operation, statusCode, response) {
|
|
722
722
|
const openApiResponse = currentEndpoint.responses[statusCode] ?? {
|
|
723
723
|
description: response.description ?? getResponseDescriptionForStatusCode(statusCode),
|
|
724
724
|
};
|
|
725
725
|
emitResponseHeaders(openApiResponse, response.responses, response.type);
|
|
726
|
-
emitResponseContent(openApiResponse, response.responses);
|
|
726
|
+
emitResponseContent(operation, openApiResponse, response.responses);
|
|
727
727
|
currentEndpoint.responses[statusCode] = openApiResponse;
|
|
728
728
|
}
|
|
729
729
|
function emitResponseHeaders(obj, responses, target) {
|
|
@@ -750,7 +750,7 @@ function createOAPIEmitter(context, options) {
|
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
752
|
}
|
|
753
|
-
function emitResponseContent(obj, responses, schemaMap = undefined) {
|
|
753
|
+
function emitResponseContent(operation, obj, responses, schemaMap = undefined) {
|
|
754
754
|
schemaMap ??= new Map();
|
|
755
755
|
for (const data of responses) {
|
|
756
756
|
if (data.body === undefined) {
|
|
@@ -758,21 +758,21 @@ function createOAPIEmitter(context, options) {
|
|
|
758
758
|
}
|
|
759
759
|
obj.content ??= {};
|
|
760
760
|
for (const contentType of data.body.contentTypes) {
|
|
761
|
-
const
|
|
761
|
+
const contents = getBodyContentEntry(operation, "response", data.body, Visibility.Read, contentType);
|
|
762
762
|
if (schemaMap.has(contentType)) {
|
|
763
|
-
schemaMap.get(contentType).push(
|
|
763
|
+
schemaMap.get(contentType).push(contents);
|
|
764
764
|
}
|
|
765
765
|
else {
|
|
766
|
-
schemaMap.set(contentType, [
|
|
766
|
+
schemaMap.set(contentType, [contents]);
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
|
-
for (const [contentType,
|
|
770
|
-
if (
|
|
771
|
-
obj.content[contentType] =
|
|
769
|
+
for (const [contentType, contents] of schemaMap) {
|
|
770
|
+
if (contents.length === 1) {
|
|
771
|
+
obj.content[contentType] = contents[0];
|
|
772
772
|
}
|
|
773
773
|
else {
|
|
774
774
|
obj.content[contentType] = {
|
|
775
|
-
schema: { anyOf: schema },
|
|
775
|
+
schema: { anyOf: contents.map((x) => x.schema) },
|
|
776
776
|
};
|
|
777
777
|
}
|
|
778
778
|
}
|
|
@@ -836,7 +836,56 @@ function createOAPIEmitter(context, options) {
|
|
|
836
836
|
},
|
|
837
837
|
});
|
|
838
838
|
}
|
|
839
|
-
function
|
|
839
|
+
function isSharedHttpOperation(operation) {
|
|
840
|
+
return operation.kind === "shared";
|
|
841
|
+
}
|
|
842
|
+
function findOperationExamples(operation) {
|
|
843
|
+
if (isSharedHttpOperation(operation)) {
|
|
844
|
+
return operation.operations.flatMap((op) => getOpExamples(program, op).map((x) => [op, x]));
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
return getOpExamples(program, operation.operation).map((x) => [operation.operation, x]);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
function getExamplesForBodyContentEntry(operation, target) {
|
|
851
|
+
const examples = findOperationExamples(operation);
|
|
852
|
+
if (examples.length === 0) {
|
|
853
|
+
return {};
|
|
854
|
+
}
|
|
855
|
+
const flattenedExamples = examples
|
|
856
|
+
.map(([op, example]) => {
|
|
857
|
+
const value = target === "request" ? example.parameters : example.returnType;
|
|
858
|
+
const type = target === "request" ? op.parameters : op.returnType;
|
|
859
|
+
return value
|
|
860
|
+
? [{ value, title: example.title, description: example.description }, type]
|
|
861
|
+
: undefined;
|
|
862
|
+
})
|
|
863
|
+
.filter(isDefined);
|
|
864
|
+
return getExampleOrExamples(flattenedExamples);
|
|
865
|
+
}
|
|
866
|
+
function getExampleOrExamples(examples) {
|
|
867
|
+
if (examples.length === 0) {
|
|
868
|
+
return {};
|
|
869
|
+
}
|
|
870
|
+
if (examples.length === 1 &&
|
|
871
|
+
examples[0][0].title === undefined &&
|
|
872
|
+
examples[0][0].description === undefined) {
|
|
873
|
+
const [example, type] = examples[0];
|
|
874
|
+
return { example: serializeValueAsJson(program, example.value, type) };
|
|
875
|
+
}
|
|
876
|
+
else {
|
|
877
|
+
const exampleObj = {};
|
|
878
|
+
for (const [index, [example, type]] of examples.entries()) {
|
|
879
|
+
exampleObj[example.title ?? `example${index}`] = {
|
|
880
|
+
summary: example.title,
|
|
881
|
+
description: example.description,
|
|
882
|
+
value: serializeValueAsJson(program, example.value, type),
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
return { examples: exampleObj };
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
function getBodyContentEntry(operation, target, body, visibility, contentType) {
|
|
840
889
|
const isBinary = isBinaryPayload(body.type, contentType);
|
|
841
890
|
if (isBinary) {
|
|
842
891
|
return { schema: { type: "string", format: "binary" } };
|
|
@@ -845,9 +894,13 @@ function createOAPIEmitter(context, options) {
|
|
|
845
894
|
case "single":
|
|
846
895
|
return {
|
|
847
896
|
schema: getSchemaForSingleBody(body.type, visibility, body.isExplicit && body.containsMetadataAnnotations, contentType.startsWith("multipart/") ? contentType : undefined),
|
|
897
|
+
...getExamplesForBodyContentEntry(operation, target),
|
|
848
898
|
};
|
|
849
899
|
case "multipart":
|
|
850
|
-
return
|
|
900
|
+
return {
|
|
901
|
+
...getBodyContentForMultipartBody(body, visibility, contentType),
|
|
902
|
+
...getExamplesForBodyContentEntry(operation, target),
|
|
903
|
+
};
|
|
851
904
|
}
|
|
852
905
|
}
|
|
853
906
|
function getSchemaForSingleBody(type, visibility, ignoreMetadataAnnotations, multipart) {
|
|
@@ -978,7 +1031,7 @@ function createOAPIEmitter(context, options) {
|
|
|
978
1031
|
emitParameter(httpOpParam, visibility);
|
|
979
1032
|
}
|
|
980
1033
|
}
|
|
981
|
-
function emitMergedRequestBody(bodies, visibility) {
|
|
1034
|
+
function emitMergedRequestBody(operation, bodies, visibility) {
|
|
982
1035
|
if (bodies === undefined) {
|
|
983
1036
|
return;
|
|
984
1037
|
}
|
|
@@ -996,7 +1049,7 @@ function createOAPIEmitter(context, options) {
|
|
|
996
1049
|
}
|
|
997
1050
|
const contentTypes = body.contentTypes.length > 0 ? body.contentTypes : ["application/json"];
|
|
998
1051
|
for (const contentType of contentTypes) {
|
|
999
|
-
const { schema: bodySchema } = getBodyContentEntry(body, visibility, contentType);
|
|
1052
|
+
const { schema: bodySchema } = getBodyContentEntry(operation, "request", body, visibility, contentType);
|
|
1000
1053
|
if (schemaMap.has(contentType)) {
|
|
1001
1054
|
schemaMap.get(contentType).push(bodySchema);
|
|
1002
1055
|
}
|
|
@@ -1019,7 +1072,7 @@ function createOAPIEmitter(context, options) {
|
|
|
1019
1072
|
requestBody.content = content;
|
|
1020
1073
|
currentEndpoint.requestBody = requestBody;
|
|
1021
1074
|
}
|
|
1022
|
-
function emitRequestBody(body, visibility) {
|
|
1075
|
+
function emitRequestBody(operation, body, visibility) {
|
|
1023
1076
|
if (body === undefined || isVoidType(body.type)) {
|
|
1024
1077
|
return;
|
|
1025
1078
|
}
|
|
@@ -1030,7 +1083,7 @@ function createOAPIEmitter(context, options) {
|
|
|
1030
1083
|
};
|
|
1031
1084
|
const contentTypes = body.contentTypes.length > 0 ? body.contentTypes : ["application/json"];
|
|
1032
1085
|
for (const contentType of contentTypes) {
|
|
1033
|
-
requestBody.content[contentType] = getBodyContentEntry(body, visibility, contentType);
|
|
1086
|
+
requestBody.content[contentType] = getBodyContentEntry(operation, "request", body, visibility, contentType);
|
|
1034
1087
|
}
|
|
1035
1088
|
currentEndpoint.requestBody = requestBody;
|
|
1036
1089
|
}
|