@azure-tools/typespec-autorest-canonical 0.1.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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -0
  3. package/dist/src/autorest-canonical-openapi-schema.d.ts +3 -0
  4. package/dist/src/autorest-canonical-openapi-schema.d.ts.map +1 -0
  5. package/dist/src/autorest-canonical-openapi-schema.js +12 -0
  6. package/dist/src/autorest-canonical-openapi-schema.js.map +1 -0
  7. package/dist/src/index.d.ts +3 -0
  8. package/dist/src/index.d.ts.map +1 -0
  9. package/dist/src/index.js +3 -0
  10. package/dist/src/index.js.map +1 -0
  11. package/dist/src/json-schema-sorter/sorter.d.ts +30 -0
  12. package/dist/src/json-schema-sorter/sorter.d.ts.map +1 -0
  13. package/dist/src/json-schema-sorter/sorter.js +175 -0
  14. package/dist/src/json-schema-sorter/sorter.js.map +1 -0
  15. package/dist/src/lib.d.ts +188 -0
  16. package/dist/src/lib.d.ts.map +1 -0
  17. package/dist/src/lib.js +150 -0
  18. package/dist/src/lib.js.map +1 -0
  19. package/dist/src/openapi.d.ts +31 -0
  20. package/dist/src/openapi.d.ts.map +1 -0
  21. package/dist/src/openapi.js +1684 -0
  22. package/dist/src/openapi.js.map +1 -0
  23. package/dist/src/testing/index.d.ts +3 -0
  24. package/dist/src/testing/index.d.ts.map +1 -0
  25. package/dist/src/testing/index.js +6 -0
  26. package/dist/src/testing/index.js.map +1 -0
  27. package/dist/src/types.d.ts +475 -0
  28. package/dist/src/types.d.ts.map +1 -0
  29. package/dist/src/types.js +2 -0
  30. package/dist/src/types.js.map +1 -0
  31. package/dist/src/utils.d.ts +42 -0
  32. package/dist/src/utils.d.ts.map +1 -0
  33. package/dist/src/utils.js +79 -0
  34. package/dist/src/utils.js.map +1 -0
  35. package/lib/autorest-canonical.tsp +1 -0
  36. package/package.json +84 -0
  37. package/schema/dist/schema.js +3 -0
@@ -0,0 +1,150 @@
1
+ import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";
2
+ const EmitterOptionsSchema = {
3
+ type: "object",
4
+ additionalProperties: false,
5
+ properties: {
6
+ "output-file": {
7
+ type: "string",
8
+ nullable: true,
9
+ description: [
10
+ "Name of the output file.",
11
+ "Output file will interpolate the following values:",
12
+ " - service-name: Name of the service if multiple",
13
+ " - azure-resource-provider-folder: Value of the azure-resource-provider-folder option",
14
+ "",
15
+ "Default: `{azure-resource-provider-folder}/{service-name}/{version}/openapi.json`",
16
+ "",
17
+ "",
18
+ "Example: Single service",
19
+ " - `canonical.openapi.json`",
20
+ "",
21
+ "Example: Multiple services",
22
+ " - `Service1.canonical.openapi.json`",
23
+ " - `Service2.canonical.openapi.json`",
24
+ ].join("\n"),
25
+ },
26
+ "azure-resource-provider-folder": { type: "string", nullable: true },
27
+ "new-line": {
28
+ type: "string",
29
+ enum: ["crlf", "lf"],
30
+ nullable: true,
31
+ default: "lf",
32
+ description: "Set the newline character for emitting files.",
33
+ },
34
+ "omit-unreachable-types": {
35
+ type: "boolean",
36
+ nullable: true,
37
+ description: "Omit unreachable types. 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.",
38
+ },
39
+ "include-x-typespec-name": {
40
+ type: "string",
41
+ enum: ["inline-only", "never"],
42
+ nullable: true,
43
+ default: "never",
44
+ description: "If the generated openapi types should have the `x-typespec-name` extension set with the name of the TypeSpec type that created it.\nThis extension is meant for debugging and should not be depended on.",
45
+ },
46
+ },
47
+ required: [],
48
+ };
49
+ const libDef = {
50
+ name: "@azure-tools/typespec-autorest-canonical",
51
+ diagnostics: {
52
+ "duplicate-body-types": {
53
+ severity: "error",
54
+ messages: {
55
+ default: "Request has multiple body types",
56
+ },
57
+ },
58
+ "invalid-schema": {
59
+ severity: "error",
60
+ messages: {
61
+ default: paramMessage `Couldn't get schema for type ${"type"}`,
62
+ },
63
+ },
64
+ "union-null": {
65
+ severity: "error",
66
+ messages: {
67
+ default: "Cannot have a union containing only null types.",
68
+ },
69
+ },
70
+ "union-unsupported": {
71
+ severity: "warning",
72
+ messages: {
73
+ default: "Unions cannot be emitted to OpenAPI v2 unless all options are literals of the same type.",
74
+ empty: "Empty unions are not supported for OpenAPI v2 - enums must have at least one value.",
75
+ },
76
+ },
77
+ "invalid-default": {
78
+ severity: "error",
79
+ messages: {
80
+ default: paramMessage `Invalid type '${"type"}' for a default value`,
81
+ },
82
+ },
83
+ "invalid-multi-collection-format": {
84
+ severity: "error",
85
+ messages: {
86
+ default: "The 'multi' should be applied to parameter in 'query', 'header' or 'formData'.",
87
+ },
88
+ },
89
+ "inline-cycle": {
90
+ severity: "error",
91
+ messages: {
92
+ default: paramMessage `Cycle detected in '${"type"}'. Use @friendlyName decorator to assign an OpenAPI definition name and make it non-inline.`,
93
+ },
94
+ },
95
+ "nonspecific-scalar": {
96
+ severity: "warning",
97
+ messages: {
98
+ default: paramMessage `Scalar type '${"type"}' is not specific enough. The more specific type '${"chosenType"}' has been chosen.`,
99
+ },
100
+ },
101
+ "unsupported-http-auth-scheme": {
102
+ severity: "warning",
103
+ messages: {
104
+ default: paramMessage `The specified HTTP authentication scheme is not supported by this emitter: ${"scheme"}.`,
105
+ },
106
+ },
107
+ "unsupported-status-code-range": {
108
+ severity: "error",
109
+ messages: {
110
+ default: paramMessage `Status code range '${"start"} to '${"end"}' is not supported. OpenAPI 2.0 can only represent range 1XX, 2XX, 3XX, 4XX and 5XX. Example: \`@minValue(400) @maxValue(499)\` for 4XX.`,
111
+ },
112
+ },
113
+ "unsupported-multipart-type": {
114
+ severity: "warning",
115
+ messages: {
116
+ default: paramMessage `Multipart parts can only be represented as primitive types in swagger 2.0. Information is lost for part '${"part"}'.`,
117
+ },
118
+ },
119
+ "unsupported-param-type": {
120
+ severity: "warning",
121
+ messages: {
122
+ default: paramMessage `Parameter can only be represented as primitive types in swagger 2.0. Information is lost for part '${"part"}'.`,
123
+ },
124
+ },
125
+ "invalid-format": {
126
+ severity: "warning",
127
+ messages: {
128
+ default: paramMessage `'${"schema"}' format '${"format"}' is not supported in AutorestCanonical. It will not be emitted.`,
129
+ },
130
+ },
131
+ "unsupported-auth": {
132
+ severity: "warning",
133
+ messages: {
134
+ default: paramMessage `Authentication "${"authType"}" is not a known authentication by the AutorestCanonical emitter, it will be ignored.`,
135
+ },
136
+ },
137
+ "unsupported-versioning-decorator": {
138
+ severity: "warning",
139
+ messages: {
140
+ default: paramMessage `Decorator @${"decorator"} is not supported in AutorestCanonical.`,
141
+ },
142
+ },
143
+ },
144
+ emitter: {
145
+ options: EmitterOptionsSchema,
146
+ },
147
+ };
148
+ export const $lib = createTypeSpecLibrary(libDef);
149
+ export const { reportDiagnostic, createStateSymbol, getTracer } = $lib;
150
+ //# 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;AAmDzF,MAAM,oBAAoB,GAAoD;IAC5E,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,aAAa,EAAE;YACb,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE;gBACX,0BAA0B;gBAC1B,oDAAoD;gBACpD,kDAAkD;gBAClD,uFAAuF;gBACvF,EAAE;gBACF,mFAAmF;gBACnF,EAAE;gBACF,EAAE;gBACF,yBAAyB;gBACzB,6BAA6B;gBAC7B,EAAE;gBACF,4BAA4B;gBAC5B,sCAAsC;gBACtC,sCAAsC;aACvC,CAAC,IAAI,CAAC,IAAI,CAAC;SACb;QACD,gCAAgC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;QACpE,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC;YACpB,QAAQ,EAAE,IAA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AAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { EmitContext } from "@typespec/compiler";
2
+ import { AutorestCanonicalEmitterOptions } from "./lib.js";
3
+ import { OpenAPI2Document } from "./types.js";
4
+ export declare const namespace = "AutorestCanonical";
5
+ export declare const canonicalVersion = "canonical";
6
+ export declare function $onEmit(context: EmitContext<AutorestCanonicalEmitterOptions>): Promise<void>;
7
+ export interface ResolvedAutorestCanonicalEmitterOptions {
8
+ outputDir: string;
9
+ outputFile: string;
10
+ azureResourceProviderFolder?: string;
11
+ /**
12
+ * Set the newline character for emitting files.
13
+ * @default lf
14
+ */
15
+ newLine?: "crlf" | "lf";
16
+ /**
17
+ * Omit unreachable types.
18
+ * 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.
19
+ */
20
+ omitUnreachableTypes?: boolean;
21
+ /**
22
+ * If the x-typespec-name extension should be included
23
+ */
24
+ includeXTypeSpecName: "inline-only" | "never";
25
+ /**
26
+ * Arm types dir
27
+ */
28
+ armTypesDir: string;
29
+ }
30
+ export declare function sortOpenAPIDocument(doc: OpenAPI2Document): OpenAPI2Document;
31
+ //# sourceMappingURL=openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/openapi.ts"],"names":[],"mappings":"AAeA,OAAO,EAIL,WAAW,EAkEZ,MAAM,oBAAoB,CAAC;AA2C5B,OAAO,EAAE,+BAA+B,EAA+B,MAAM,UAAU,CAAC;AACxF,OAAO,EACL,gBAAgB,EAgBjB,MAAM,YAAY,CAAC;AAepB,eAAO,MAAM,SAAS,sBAAsB,CAAC;AAC7C,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,+BAA+B,CAAC,iBAmBlF;AAUD,MAAM,WAAW,uCAAuC;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,2BAA2B,CAAC,EAAE,MAAM,CAAC;IAErC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;OAEG;IACH,oBAAoB,EAAE,aAAa,GAAG,OAAO,CAAC;IAE9C;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAo5DD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,gBAAgB,CAS3E"}