@azure-tools/typespec-autorest 0.27.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 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,166 @@
1
+ # TypeSpec AutoRest Library
2
+
3
+ This is a TypeSpec library that will emit an enriched OpenAPI 2.0 specification that can be consumed by AutoRest.
4
+ The generated OpenAPI spec will have custom `x-ms-` extensions properties and conform to standards required by AutoRest to generate a more accurate SDK.
5
+
6
+ ## Getting started
7
+
8
+ 1. Include `@azure-tools/typespec-autorest` dependencies in package.json
9
+
10
+ ```json
11
+ {
12
+ ...
13
+ "dependencies": {
14
+ ...
15
+ "@azure-tools/typespec-autorest": "latest"
16
+ }
17
+ }
18
+ ```
19
+
20
+ 2. Run `npm install` to install the dependency
21
+ 3. Import `@azure-tools/typespec-autorest` in your `main.tsp` file
22
+
23
+ ```typespec
24
+ import "@azure-tools/typespec-autorest";
25
+ ```
26
+
27
+ 4. Run `tsp compile`. This will result in a `swagger.json` file crated in `./tsp-output/swagger.json`
28
+
29
+ ## Use in autorest
30
+
31
+ ### Manually
32
+
33
+ Generate the OpenAPI spec as shown above then run autorest cli directly on it.
34
+
35
+ ### Via Autorest
36
+
37
+ AutoRest provides a plugin that will directly take TypeSpec as input. Make sure to use `Autorest Core >=3.6.0`
38
+
39
+ ```bash
40
+ autorest --typespec --input-file=./main.tsp
41
+ ```
42
+
43
+ ## Configuration
44
+
45
+ ### Output path
46
+
47
+ Specify the `--output-path` option, this changes the directory where the OpenAPI specification (openapi.json) wil be omitted:
48
+
49
+ ```bash
50
+ tsp compile --output-path=`./custom`
51
+ ```
52
+
53
+ ### Emitter options:
54
+
55
+ Emitter options can be configured via the `tspconfig.yaml` configuration:
56
+
57
+ ```yaml
58
+ emitters:
59
+ '@azure-tools/typespec-autorest':
60
+ <optionName>: <value>
61
+
62
+
63
+ # For example
64
+ emitters:
65
+ '@azure-tools/typespec-autorest':
66
+ output-file: my-custom-swagger.json
67
+ ```
68
+
69
+ or via the command line with
70
+
71
+ ```bash
72
+ --option "@azure-tools/typespec-autorest.<optionName>=<value>"
73
+
74
+ # For example
75
+ --option "@azure-tools/typespec-autorest.output-file=my-custom-swagger.json"
76
+ ```
77
+
78
+ #### `output-dir`
79
+
80
+ Override the compiler default `output-dir`
81
+
82
+ #### `output-file`
83
+
84
+ Configure the name of the swagger output file relative to the `output-dir`.
85
+
86
+ #### `examples-directory`
87
+
88
+ Directory where the x-ms-examples are located so the emitter can automatically link.
89
+
90
+ #### `version`
91
+
92
+ Select which version should be emitted if the spec support versioning. By default all the version with be emitted in this format `<outputFileName>.<version>.json`
93
+
94
+ ### `new-line`
95
+
96
+ Set the newline character for emitting files. Can be either:
97
+
98
+ - `lf`(Default)
99
+ - `crlf`
100
+
101
+ ### `omit-unreachable-types`
102
+
103
+ Only include types referenced via an operation.
104
+
105
+ ## Decorators
106
+
107
+ - [@collectionFormat](#collectionformat)
108
+ - [@example](#example)
109
+ - [@useRef](#useref)
110
+
111
+ ### @collectionFormat
112
+
113
+ Syntax:
114
+
115
+ ```
116
+ @collectionFormat(formatString)
117
+ ```
118
+
119
+ `@collectionFormat` specifies array property type serialization format. Valid format strings are "csv", "multi", "ssv", "tsv", "pipes" though "csv" or "multi" are recommended.
120
+
121
+ `@collectionFormat` can only be specified on model properties that are arrays.
122
+
123
+ ### @example
124
+
125
+ Syntax:
126
+
127
+ ```
128
+ @example(pathOrUri, title)
129
+ ```
130
+
131
+ `@example` attaches example files to an operation. Multiple examples can be specified.
132
+
133
+ `@example` can only be specified on operations.
134
+
135
+ ### @useRef
136
+
137
+ Syntax:
138
+
139
+ ```
140
+ @useRef(urlString)
141
+ ```
142
+
143
+ `@useRef` is used to replace the TypeSpec model type in emitter output with a pre-existing named OpenAPI schema such as ARM common types.
144
+
145
+ ## How to
146
+
147
+ ### Include `x-ms-skip-url-encoding` in `x-ms-parmaeterized-host` parameter
148
+
149
+ Every parameter of type `uri` in `@server` will be marked with `x-ms-skip-url-encoding`.
150
+
151
+ ```typespec
152
+ @server("{endpoint}/v2", "Account endpoint", {endpoint: url})
153
+ ```
154
+
155
+ Result in
156
+
157
+ ```json5
158
+ {
159
+ in: "path",
160
+ name: "endpoint",
161
+ required: true,
162
+ type: "string",
163
+ format: "uri",
164
+ "x-ms-skip-url-encoding": true,
165
+ }
166
+ ```
@@ -0,0 +1,28 @@
1
+ import { DecoratorContext, ModelProperty, Program, Type } from "@typespec/compiler";
2
+ export declare const namespace = "Autorest";
3
+ export interface Example {
4
+ pathOrUri: string;
5
+ title: string;
6
+ }
7
+ /**
8
+ * `@example` - attaches example files to an operation. Multiple examples can be specified.
9
+ *
10
+ * @param {string} param pathOrUri - path or Uri to the example file.
11
+ * @param {string} param title - name or description of the example file.
12
+ *
13
+ * `@example` can be specified on Operations.
14
+ */
15
+ export declare function $example(context: DecoratorContext, entity: Type, pathOrUri: string, title: string): void;
16
+ export declare function getExamples(program: Program, entity: Type): Example[] | undefined;
17
+ /**
18
+ * `@useRef` - is used to replace the TypeSpec model type in emitter output with a pre-existing named OpenAPI schema such as ARM common types.
19
+ *
20
+ * @param {string} param jsonRef - path or Uri to an OpenAPI schema.
21
+ *
22
+ * `@useRef` can be specified on Models and ModelProperty.
23
+ */
24
+ export declare function $useRef(context: DecoratorContext, entity: Type, jsonRef: string): void;
25
+ export declare function getRef(program: Program, entity: Type): string | undefined;
26
+ export declare function $collectionFormat(context: DecoratorContext, entity: ModelProperty, format: string): void;
27
+ export declare function getCollectionFormat(program: Program, entity: Type): string | undefined;
28
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAGhB,aAAa,EACb,OAAO,EAEP,IAAI,EAGL,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,SAAS,aAAa,CAAC;AAEpC,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAGD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,IAAI,EACZ,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,QA2Bd;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,OAAO,EAAE,GAAG,SAAS,CAEjF;AAGD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAStF;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAEzE;AAQD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,QAuCf;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAEtF"}
@@ -0,0 +1,100 @@
1
+ import { createDecoratorDefinition, isArrayModelType, isStringType, reportDeprecated, validateDecoratorParamType, validateDecoratorTarget, } from "@typespec/compiler";
2
+ import { createStateSymbol, reportDiagnostic } from "./lib.js";
3
+ export const namespace = "Autorest";
4
+ const exampleKey = createStateSymbol("example");
5
+ /**
6
+ * `@example` - attaches example files to an operation. Multiple examples can be specified.
7
+ *
8
+ * @param {string} param pathOrUri - path or Uri to the example file.
9
+ * @param {string} param title - name or description of the example file.
10
+ *
11
+ * `@example` can be specified on Operations.
12
+ */
13
+ export function $example(context, entity, pathOrUri, title) {
14
+ const { program } = context;
15
+ if (!validateDecoratorTarget(context, entity, "@example", "Operation") ||
16
+ !validateDecoratorParamType(program, entity, pathOrUri, "String") ||
17
+ !validateDecoratorParamType(program, entity, title, "String")) {
18
+ return;
19
+ }
20
+ if (!program.stateMap(exampleKey).has(entity)) {
21
+ program.stateMap(exampleKey).set(entity, []);
22
+ }
23
+ else if (program
24
+ .stateMap(exampleKey)
25
+ .get(entity)
26
+ .find((e) => e.title === title || e.pathOrUri === pathOrUri)) {
27
+ reportDiagnostic(program, {
28
+ code: "duplicate-example",
29
+ target: entity,
30
+ });
31
+ }
32
+ program.stateMap(exampleKey).get(entity).push({
33
+ pathOrUri,
34
+ title,
35
+ });
36
+ }
37
+ export function getExamples(program, entity) {
38
+ return program.stateMap(exampleKey).get(entity);
39
+ }
40
+ const refTargetsKey = createStateSymbol("autorest.ref");
41
+ /**
42
+ * `@useRef` - is used to replace the TypeSpec model type in emitter output with a pre-existing named OpenAPI schema such as ARM common types.
43
+ *
44
+ * @param {string} param jsonRef - path or Uri to an OpenAPI schema.
45
+ *
46
+ * `@useRef` can be specified on Models and ModelProperty.
47
+ */
48
+ export function $useRef(context, entity, jsonRef) {
49
+ if (!validateDecoratorTarget(context, entity, "@useRef", ["Model", "ModelProperty"]) ||
50
+ !validateDecoratorParamType(context.program, entity, jsonRef, "String")) {
51
+ return;
52
+ }
53
+ context.program.stateMap(refTargetsKey).set(entity, jsonRef);
54
+ }
55
+ export function getRef(program, entity) {
56
+ return program.stateMap(refTargetsKey).get(entity);
57
+ }
58
+ const collectionFormatDecorator = createDecoratorDefinition({
59
+ name: "@collectionFormat",
60
+ target: "ModelProperty",
61
+ args: [{ kind: "String" }],
62
+ });
63
+ const collectionFormatKey = createStateSymbol("collectionFormat");
64
+ export function $collectionFormat(context, entity, format) {
65
+ // Deprecated 1/12/2023
66
+ reportDeprecated(context.program, "The @collectionFormat decorator is deprecated. Use `format` option in @query/@header decorators instead.", context.decoratorTarget);
67
+ if (!collectionFormatDecorator.validate(context, entity, [format])) {
68
+ return;
69
+ }
70
+ if (entity.type.kind !== "Model" ||
71
+ !isArrayModelType(context.program, entity.type) ||
72
+ (entity.type.templateArguments &&
73
+ !isStringType(context.program, entity.type.templateArguments[0]))) {
74
+ reportDiagnostic(context.program, {
75
+ code: "invalid-property-type-for-collection-format",
76
+ target: context.decoratorTarget,
77
+ });
78
+ return;
79
+ }
80
+ const knownFormats = ["csv", "ssv", "tsv", "pipes", "multi"];
81
+ if (!knownFormats.includes(format)) {
82
+ reportDiagnostic(context.program, {
83
+ code: "invalid-collection-format",
84
+ target: context.decoratorTarget,
85
+ });
86
+ return;
87
+ }
88
+ const recommendations = ["csv", "multi"];
89
+ if (!recommendations.includes(format)) {
90
+ reportDiagnostic(context.program, {
91
+ code: "non-recommended-collection-format",
92
+ target: context.decoratorTarget,
93
+ });
94
+ }
95
+ context.program.stateMap(collectionFormatKey).set(entity, format);
96
+ }
97
+ export function getCollectionFormat(program, entity) {
98
+ return program.stateMap(collectionFormatKey).get(entity);
99
+ }
100
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EAEzB,gBAAgB,EAChB,YAAY,EAGZ,gBAAgB,EAEhB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE/D,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC;AAOpC,MAAM,UAAU,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;AAChD;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAyB,EACzB,MAAY,EACZ,SAAiB,EACjB,KAAa;IAEb,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,IACE,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC;QAClE,CAAC,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC;QACjE,CAAC,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,EAC7D;QACA,OAAO;KACR;IACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;KAC9C;SAAM,IACL,OAAO;SACJ,QAAQ,CAAC,UAAU,CAAC;SACpB,GAAG,CAAC,MAAM,CAAC;SACX,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,IAAI,CAAC,CAAC,SAAS,KAAK,SAA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EAAE,OAAO,CAAC,eAAe;SAChC,CAAC,CAAC;KACJ;IACD,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,MAAY;IAChE,OAAO,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./decorators.js";
2
+ export { $lib } from "./lib.js";
3
+ export * from "./openapi.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./decorators.js";
2
+ export { $lib } from "./lib.js";
3
+ export * from "./openapi.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,179 @@
1
+ export interface AutorestEmitterOptions {
2
+ /**
3
+ * Override compiler output-dir
4
+ */
5
+ "output-dir"?: string;
6
+ "output-file"?: string;
7
+ "examples-directory"?: string;
8
+ version?: string;
9
+ "azure-resource-provider-folder"?: string;
10
+ /**
11
+ * Set the newline character for emitting files.
12
+ * @default lf
13
+ */
14
+ "new-line"?: "crlf" | "lf";
15
+ /**
16
+ * Omit unreachable types.
17
+ * 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.
18
+ */
19
+ "omit-unreachable-types"?: boolean;
20
+ }
21
+ export declare const $lib: import("@typespec/compiler").TypeSpecLibrary<{
22
+ "security-service-namespace": {
23
+ readonly default: "Cannot add security details to a namespace other than the service namespace.";
24
+ };
25
+ "resource-namespace": {
26
+ readonly default: "Resource goes on namespace";
27
+ };
28
+ "missing-path-param": {
29
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
30
+ };
31
+ "duplicate-body-types": {
32
+ readonly default: "Request has multiple body types";
33
+ };
34
+ "duplicate-header": {
35
+ readonly default: import("@typespec/compiler").CallableMessage<["header"]>;
36
+ };
37
+ "duplicate-example": {
38
+ readonly default: "Duplicate @example declarations on operation";
39
+ };
40
+ "invalid-schema": {
41
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
42
+ };
43
+ "union-null": {
44
+ readonly default: "Cannot have a union containing only null types.";
45
+ };
46
+ "union-unsupported": {
47
+ readonly default: "Unions cannot be emitted to OpenAPI v2 unless all options are literals of the same type.";
48
+ readonly null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.";
49
+ };
50
+ "invalid-default": {
51
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
52
+ };
53
+ "invalid-property-type-for-collection-format": {
54
+ readonly default: "The collectionFormat can only be applied to model property with type 'string[]'.";
55
+ };
56
+ "invalid-collection-format": {
57
+ readonly default: "The format should be one of 'csv','ssv','tsv','pipes' and 'multi'.";
58
+ };
59
+ "non-recommended-collection-format": {
60
+ readonly default: "The recommendation of collection format are 'csv' and 'multi'.";
61
+ };
62
+ "invalid-multi-collection-format": {
63
+ readonly default: "The 'multi' should be applied to parameter in 'query', 'header' or 'formData'.";
64
+ };
65
+ "inline-cycle": {
66
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
67
+ };
68
+ "example-loading": {
69
+ readonly default: import("@typespec/compiler").CallableMessage<["filename"]>;
70
+ readonly noDirectory: import("@typespec/compiler").CallableMessage<["directory"]>;
71
+ readonly noOperationId: import("@typespec/compiler").CallableMessage<["filename"]>;
72
+ };
73
+ }, AutorestEmitterOptions>;
74
+ export declare const reportDiagnostic: <C extends "security-service-namespace" | "resource-namespace" | "missing-path-param" | "duplicate-body-types" | "duplicate-header" | "duplicate-example" | "invalid-schema" | "union-null" | "union-unsupported" | "invalid-default" | "invalid-property-type-for-collection-format" | "invalid-collection-format" | "non-recommended-collection-format" | "invalid-multi-collection-format" | "inline-cycle" | "example-loading", M extends keyof {
75
+ "security-service-namespace": {
76
+ readonly default: "Cannot add security details to a namespace other than the service namespace.";
77
+ };
78
+ "resource-namespace": {
79
+ readonly default: "Resource goes on namespace";
80
+ };
81
+ "missing-path-param": {
82
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
83
+ };
84
+ "duplicate-body-types": {
85
+ readonly default: "Request has multiple body types";
86
+ };
87
+ "duplicate-header": {
88
+ readonly default: import("@typespec/compiler").CallableMessage<["header"]>;
89
+ };
90
+ "duplicate-example": {
91
+ readonly default: "Duplicate @example declarations on operation";
92
+ };
93
+ "invalid-schema": {
94
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
95
+ };
96
+ "union-null": {
97
+ readonly default: "Cannot have a union containing only null types.";
98
+ };
99
+ "union-unsupported": {
100
+ readonly default: "Unions cannot be emitted to OpenAPI v2 unless all options are literals of the same type.";
101
+ readonly null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.";
102
+ };
103
+ "invalid-default": {
104
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
105
+ };
106
+ "invalid-property-type-for-collection-format": {
107
+ readonly default: "The collectionFormat can only be applied to model property with type 'string[]'.";
108
+ };
109
+ "invalid-collection-format": {
110
+ readonly default: "The format should be one of 'csv','ssv','tsv','pipes' and 'multi'.";
111
+ };
112
+ "non-recommended-collection-format": {
113
+ readonly default: "The recommendation of collection format are 'csv' and 'multi'.";
114
+ };
115
+ "invalid-multi-collection-format": {
116
+ readonly default: "The 'multi' should be applied to parameter in 'query', 'header' or 'formData'.";
117
+ };
118
+ "inline-cycle": {
119
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
120
+ };
121
+ "example-loading": {
122
+ readonly default: import("@typespec/compiler").CallableMessage<["filename"]>;
123
+ readonly noDirectory: import("@typespec/compiler").CallableMessage<["directory"]>;
124
+ readonly noOperationId: import("@typespec/compiler").CallableMessage<["filename"]>;
125
+ };
126
+ }[C]>(program: import("@typespec/compiler").Program, diag: import("@typespec/compiler").DiagnosticReport<{
127
+ "security-service-namespace": {
128
+ readonly default: "Cannot add security details to a namespace other than the service namespace.";
129
+ };
130
+ "resource-namespace": {
131
+ readonly default: "Resource goes on namespace";
132
+ };
133
+ "missing-path-param": {
134
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
135
+ };
136
+ "duplicate-body-types": {
137
+ readonly default: "Request has multiple body types";
138
+ };
139
+ "duplicate-header": {
140
+ readonly default: import("@typespec/compiler").CallableMessage<["header"]>;
141
+ };
142
+ "duplicate-example": {
143
+ readonly default: "Duplicate @example declarations on operation";
144
+ };
145
+ "invalid-schema": {
146
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
147
+ };
148
+ "union-null": {
149
+ readonly default: "Cannot have a union containing only null types.";
150
+ };
151
+ "union-unsupported": {
152
+ readonly default: "Unions cannot be emitted to OpenAPI v2 unless all options are literals of the same type.";
153
+ readonly null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.";
154
+ };
155
+ "invalid-default": {
156
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
157
+ };
158
+ "invalid-property-type-for-collection-format": {
159
+ readonly default: "The collectionFormat can only be applied to model property with type 'string[]'.";
160
+ };
161
+ "invalid-collection-format": {
162
+ readonly default: "The format should be one of 'csv','ssv','tsv','pipes' and 'multi'.";
163
+ };
164
+ "non-recommended-collection-format": {
165
+ readonly default: "The recommendation of collection format are 'csv' and 'multi'.";
166
+ };
167
+ "invalid-multi-collection-format": {
168
+ readonly default: "The 'multi' should be applied to parameter in 'query', 'header' or 'formData'.";
169
+ };
170
+ "inline-cycle": {
171
+ readonly default: import("@typespec/compiler").CallableMessage<["type"]>;
172
+ };
173
+ "example-loading": {
174
+ readonly default: import("@typespec/compiler").CallableMessage<["filename"]>;
175
+ readonly noDirectory: import("@typespec/compiler").CallableMessage<["directory"]>;
176
+ readonly noOperationId: import("@typespec/compiler").CallableMessage<["filename"]>;
177
+ };
178
+ }, C, M>) => void, createStateSymbol: (name: string) => symbol, getTracer: (program: import("@typespec/compiler").Program) => import("@typespec/compiler").Tracer;
179
+ //# sourceMappingURL=lib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gCAAgC,CAAC,EAAE,MAAM,CAAC;IAE1C;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AA8HD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAgC,CAAC;AAClD,eAAO,MAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAE,iBAAiB,4BAAE,SAAS,wFAAS,CAAC"}
@@ -0,0 +1,125 @@
1
+ import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";
2
+ const EmitterOptionsSchema = {
3
+ type: "object",
4
+ additionalProperties: false,
5
+ properties: {
6
+ "output-dir": { type: "string", nullable: true },
7
+ "output-file": { type: "string", nullable: true },
8
+ "examples-directory": { type: "string", nullable: true },
9
+ version: { type: "string", nullable: true },
10
+ "azure-resource-provider-folder": { type: "string", nullable: true },
11
+ "new-line": { type: "string", enum: ["crlf", "lf"], nullable: true },
12
+ "omit-unreachable-types": { type: "boolean", nullable: true },
13
+ },
14
+ required: [],
15
+ };
16
+ const libDef = {
17
+ name: "@azure-tools/typespec-autorest",
18
+ diagnostics: {
19
+ "security-service-namespace": {
20
+ severity: "error",
21
+ messages: {
22
+ default: "Cannot add security details to a namespace other than the service namespace.",
23
+ },
24
+ },
25
+ "resource-namespace": {
26
+ severity: "error",
27
+ messages: {
28
+ default: "Resource goes on namespace",
29
+ },
30
+ },
31
+ "missing-path-param": {
32
+ severity: "error",
33
+ messages: {
34
+ default: paramMessage `Path contains parameter ${"param"} but wasn't found in given parameters`,
35
+ },
36
+ },
37
+ "duplicate-body-types": {
38
+ severity: "error",
39
+ messages: {
40
+ default: "Request has multiple body types",
41
+ },
42
+ },
43
+ "duplicate-header": {
44
+ severity: "error",
45
+ messages: {
46
+ default: paramMessage `The header ${"header"} is defined across multiple content types`,
47
+ },
48
+ },
49
+ "duplicate-example": {
50
+ severity: "error",
51
+ messages: {
52
+ default: "Duplicate @example declarations on operation",
53
+ },
54
+ },
55
+ "invalid-schema": {
56
+ severity: "error",
57
+ messages: {
58
+ default: paramMessage `Couldn't get schema for type ${"type"}`,
59
+ },
60
+ },
61
+ "union-null": {
62
+ severity: "error",
63
+ messages: {
64
+ default: "Cannot have a union containing only null types.",
65
+ },
66
+ },
67
+ "union-unsupported": {
68
+ severity: "warning",
69
+ messages: {
70
+ default: "Unions cannot be emitted to OpenAPI v2 unless all options are literals of the same type.",
71
+ null: "Unions containing multiple model types cannot be emitted to OpenAPI v2 unless the union is between one model type and 'null'.",
72
+ },
73
+ },
74
+ "invalid-default": {
75
+ severity: "error",
76
+ messages: {
77
+ default: paramMessage `Invalid type '${"type"}' for a default value`,
78
+ },
79
+ },
80
+ "invalid-property-type-for-collection-format": {
81
+ severity: "error",
82
+ messages: {
83
+ default: "The collectionFormat can only be applied to model property with type 'string[]'.",
84
+ },
85
+ },
86
+ "invalid-collection-format": {
87
+ severity: "error",
88
+ messages: {
89
+ default: "The format should be one of 'csv','ssv','tsv','pipes' and 'multi'.",
90
+ },
91
+ },
92
+ "non-recommended-collection-format": {
93
+ severity: "warning",
94
+ messages: {
95
+ default: "The recommendation of collection format are 'csv' and 'multi'.",
96
+ },
97
+ },
98
+ "invalid-multi-collection-format": {
99
+ severity: "error",
100
+ messages: {
101
+ default: "The 'multi' should be applied to parameter in 'query', 'header' or 'formData'.",
102
+ },
103
+ },
104
+ "inline-cycle": {
105
+ severity: "error",
106
+ messages: {
107
+ default: paramMessage `Cycle detected in '${"type"}'. Use @friendlyName decorator to assign an OpenAPI definition name and make it non-inline.`,
108
+ },
109
+ },
110
+ "example-loading": {
111
+ severity: "warning",
112
+ messages: {
113
+ default: paramMessage `Skipped loading invalid example file: ${"filename"}.`,
114
+ noDirectory: paramMessage `Skipping example loading from ${"directory"} because there was an error reading the directory.`,
115
+ noOperationId: paramMessage `Skipping example file ${"filename"} because it does not contain an operationId and/or title.`,
116
+ },
117
+ },
118
+ },
119
+ emitter: {
120
+ options: EmitterOptionsSchema,
121
+ },
122
+ };
123
+ export const $lib = createTypeSpecLibrary(libDef);
124
+ export const { reportDiagnostic, createStateSymbol, getTracer } = $lib;
125
+ //# sourceMappingURL=lib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAkB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA0BzF,MAAM,oBAAoB,GAA2C;IACnE,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,YAAY,EAAE,EAAE,IAAI,EAAE,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