-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathoptions.ts
More file actions
52 lines (46 loc) · 1.57 KB
/
Copy pathoptions.ts
File metadata and controls
52 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { JSONSchemaType } from "@typespec/compiler";
export type MetadataOutputFormat = "yaml" | "json";
export interface MetadataEmitterOptions {
/**
* Relative path of the emitted metadata file. When omitted, the emitter picks an extension based on the format.
*/
outputFile?: string;
/**
* Serialization format for the metadata snapshot.
*/
format?: MetadataOutputFormat;
/**
* API version configuration passed through to TCGC for version resolution.
* Can be "all", a specific version string, or a per-service map.
*/
"api-version"?: string;
}
export interface NormalizedMetadataEmitterOptions {
outputFile: string;
format: MetadataOutputFormat;
}
const DEFAULT_FORMAT: MetadataOutputFormat = "yaml";
const FALLBACK_FILENAMES: Record<MetadataOutputFormat, string> = {
json: "typespec-metadata.json",
yaml: "typespec-metadata.yaml",
};
export const metadataEmitterOptionsSchema: JSONSchemaType<MetadataEmitterOptions> = {
type: "object",
additionalProperties: false,
properties: {
outputFile: { type: "string", nullable: true },
format: { type: "string", enum: ["yaml", "json"], nullable: true },
"api-version": { type: "string", nullable: true },
},
};
export function normalizeOptions(
rawOptions: MetadataEmitterOptions | undefined,
): NormalizedMetadataEmitterOptions {
const format = rawOptions?.format ?? DEFAULT_FORMAT;
const sanitizedOutput = rawOptions?.outputFile?.trim();
return {
format,
outputFile:
sanitizedOutput && sanitizedOutput.length > 0 ? sanitizedOutput : FALLBACK_FILENAMES[format],
};
}