@typespec/http-server-csharp 0.58.0-alpha.11 → 0.58.0-alpha.12-dev.1
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/README.md +56 -6
- package/dist/src/cli/cli.js +76 -37
- package/dist/src/cli/cli.js.map +1 -1
- package/dist/src/lib/doc.d.ts +5 -0
- package/dist/src/lib/doc.d.ts.map +1 -0
- package/dist/src/lib/doc.js +237 -0
- package/dist/src/lib/doc.js.map +1 -0
- package/dist/src/lib/interfaces.d.ts +4 -1
- package/dist/src/lib/interfaces.d.ts.map +1 -1
- package/dist/src/lib/interfaces.js +7 -3
- package/dist/src/lib/interfaces.js.map +1 -1
- package/dist/src/lib/lib.d.ts +10 -2
- package/dist/src/lib/lib.d.ts.map +1 -1
- package/dist/src/lib/lib.js +24 -2
- package/dist/src/lib/lib.js.map +1 -1
- package/dist/src/lib/project.d.ts +5 -0
- package/dist/src/lib/project.d.ts.map +1 -0
- package/dist/src/lib/project.js +101 -0
- package/dist/src/lib/project.js.map +1 -0
- package/dist/src/lib/scaffolding.d.ts +2 -1
- package/dist/src/lib/scaffolding.d.ts.map +1 -1
- package/dist/src/lib/scaffolding.js +10 -6
- package/dist/src/lib/scaffolding.js.map +1 -1
- package/dist/src/lib/service.d.ts.map +1 -1
- package/dist/src/lib/service.js +64 -22
- package/dist/src/lib/service.js.map +1 -1
- package/dist/src/lib/utils.d.ts +10 -0
- package/dist/src/lib/utils.d.ts.map +1 -1
- package/dist/src/lib/utils.js +51 -1
- package/dist/src/lib/utils.js.map +1 -1
- package/package.json +15 -14
package/dist/src/lib/lib.d.ts
CHANGED
|
@@ -3,12 +3,20 @@ export interface CSharpServiceEmitterOptions {
|
|
|
3
3
|
"skip-format"?: boolean;
|
|
4
4
|
/** Choose which service artifacts to emit. Default is 'all'.*/
|
|
5
5
|
"output-type"?: "models" | "all";
|
|
6
|
-
/** Emit mock implementations of business logic and
|
|
7
|
-
"emit-mocks"?: "none" | "
|
|
6
|
+
/** Emit mock implementations of business logic, setup code, and project files. Allows the service to respond to requests with mock responses.*/
|
|
7
|
+
"emit-mocks"?: "none" | "mocks-only" | "mocks-and-project-files";
|
|
8
8
|
/** Configure a Swagger UI endpoint in the development configuration. */
|
|
9
9
|
"use-swaggerui"?: boolean;
|
|
10
10
|
/** Use openapi at the given path for generating SwaggerUI endpoints. By default, this will be 'openapi/openapi.yaml' if the 'use-swaggerui' option is enabled. */
|
|
11
11
|
"openapi-path"?: string;
|
|
12
|
+
/** When generating mock files, overwrite any existing files with the same name. */
|
|
13
|
+
overwrite?: boolean;
|
|
14
|
+
/** The generated project name. */
|
|
15
|
+
"project-name"?: string;
|
|
16
|
+
/** The http port number to use when hosting the service locally */
|
|
17
|
+
"http-port"?: number;
|
|
18
|
+
/** The https port number to use when hosting the service locally */
|
|
19
|
+
"https-port"?: number;
|
|
12
20
|
}
|
|
13
21
|
export declare const $lib: import("@typespec/compiler").TypeSpecLibrary<{
|
|
14
22
|
"invalid-identifier": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../../src/lib/lib.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B;IAC1C,yFAAyF;IACzF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gEAAgE;IAChE,aAAa,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACjC,
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../../src/lib/lib.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B;IAC1C,yFAAyF;IACzF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gEAAgE;IAChE,aAAa,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACjC,gJAAgJ;IAChJ,YAAY,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,yBAAyB,CAAC;IACjE,wEAAwE;IACxE,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kKAAkK;IAClK,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mFAAmF;IACnF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kCAAkC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAoED,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;sCA0Df,CAAC;AAEH,eAAO,MAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAE,iBAAiB,4BAAE,SAAS,wFAAS,CAAC;AAEvE,MAAM,MAAM,oBAAoB,GAAG,OAAO,IAAI,CAAC"}
|
package/dist/src/lib/lib.js
CHANGED
|
@@ -17,10 +17,10 @@ const EmitterOptionsSchema = {
|
|
|
17
17
|
},
|
|
18
18
|
"emit-mocks": {
|
|
19
19
|
type: "string",
|
|
20
|
-
enum: ["
|
|
20
|
+
enum: ["mocks-and-project-files", "mocks-only", "none"],
|
|
21
21
|
nullable: true,
|
|
22
22
|
default: "none",
|
|
23
|
-
description: "Emits mock implementations of business logic, enabling the service to respond to requests before a real implementation is provided",
|
|
23
|
+
description: "Emits mock implementations of business logic, setup code, and project files, enabling the service to respond to requests before a real implementation is provided",
|
|
24
24
|
},
|
|
25
25
|
"use-swaggerui": {
|
|
26
26
|
type: "boolean",
|
|
@@ -34,6 +34,28 @@ const EmitterOptionsSchema = {
|
|
|
34
34
|
default: null,
|
|
35
35
|
description: "Use openapi at the given path for generating SwaggerUI endpoints. By default, this will be 'openapi/openapi.yaml' if the 'use-swaggerui' option is enabled. ",
|
|
36
36
|
},
|
|
37
|
+
overwrite: {
|
|
38
|
+
type: "boolean",
|
|
39
|
+
nullable: true,
|
|
40
|
+
default: false,
|
|
41
|
+
description: "When generating mock and project files, overwrite any existing files with the same name.",
|
|
42
|
+
},
|
|
43
|
+
"project-name": {
|
|
44
|
+
type: "string",
|
|
45
|
+
nullable: true,
|
|
46
|
+
default: "ServiceProject",
|
|
47
|
+
description: "The name of the generated project.",
|
|
48
|
+
},
|
|
49
|
+
"http-port": {
|
|
50
|
+
type: "number",
|
|
51
|
+
nullable: true,
|
|
52
|
+
description: "The service http port when hosting the project locally.",
|
|
53
|
+
},
|
|
54
|
+
"https-port": {
|
|
55
|
+
type: "number",
|
|
56
|
+
nullable: true,
|
|
57
|
+
description: "The service https port when hosting the project locally.",
|
|
58
|
+
},
|
|
37
59
|
},
|
|
38
60
|
required: [],
|
|
39
61
|
};
|
package/dist/src/lib/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../../src/lib/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAkB,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../../src/lib/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAkB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAuBzF,MAAM,oBAAoB,GAAgD;IACxE,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,aAAa,EAAE;YACb,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,oGAAoG;SACvG;QACD,aAAa,EAAE;YACb,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC;YACvB,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,KAAK;YACd,WAAW,EACT,uFAAuF;SAC1F;QACD,YAAY,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,yBAAyB,EAAE,YAAY,EAAE,MAAM,CAAC;YACvD,QAAQ,EAAE,IAAI;YACd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gBACR,OAAO,EAAE,YAAY,CAAA,uBAAuB,MAAM,IAAI,MAAM,GAAG;aAChE;SACF;QACD,YAAY,EAAE;YACZ,QAAQ,EAAE,SAAS;YACnB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,SAAS,YAAY,sFAAsF,YAAY,yGAAyG;aACtP;SACF;QACD,qBAAqB,EAAE;YACrB,QAAQ,EAAE,SAAS;YACnB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,eAAe,UAAU,iFAAiF;aAChI;SACF;QACD,mBAAmB,EAAE;YACnB,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,kBAAkB,UAAU,8FAA8F;aAChJ;SACF;QACD,uBAAuB,EAAE;YACvB,QAAQ,EAAE,SAAS;YACnB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,oNAAoN;aAC1O;SACF;QACD,kBAAkB,EAAE;YAClB,QAAQ,EAAE,SAAS;YACnB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,oLAAoL;aAC1M;SACF;KACF;IACD,OAAO,EAAE;QACP,OAAO,EAAE,oBAAmE;KAC7E;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AssetEmitter } from "@typespec/asset-emitter";
|
|
2
|
+
import { LibrarySourceFile } from "./interfaces.js";
|
|
3
|
+
import { CSharpServiceEmitterOptions } from "./lib.js";
|
|
4
|
+
export declare function getProjectHelpers(emitter: AssetEmitter<string, CSharpServiceEmitterOptions>, projectName: string, useSwaggerUI: boolean, httpPort: number, httpsPort: number): LibrarySourceFile[];
|
|
5
|
+
//# sourceMappingURL=project.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/lib/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAEvD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,2BAA2B,CAAC,EAC1D,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,iBAAiB,EAAE,CAgCrB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { LibrarySourceFile } from "./interfaces.js";
|
|
2
|
+
export function getProjectHelpers(emitter, projectName, useSwaggerUI, httpPort, httpsPort) {
|
|
3
|
+
const result = [
|
|
4
|
+
new LibrarySourceFile({
|
|
5
|
+
filename: `${projectName}.csproj`,
|
|
6
|
+
emitter: emitter,
|
|
7
|
+
getContents: () => getProjectFile(useSwaggerUI),
|
|
8
|
+
path: "..",
|
|
9
|
+
conditional: true,
|
|
10
|
+
}),
|
|
11
|
+
new LibrarySourceFile({
|
|
12
|
+
filename: "appsettings.json",
|
|
13
|
+
emitter: emitter,
|
|
14
|
+
getContents: getAppSettings,
|
|
15
|
+
path: "..",
|
|
16
|
+
conditional: true,
|
|
17
|
+
}),
|
|
18
|
+
new LibrarySourceFile({
|
|
19
|
+
filename: "appsettings.Development.json",
|
|
20
|
+
emitter: emitter,
|
|
21
|
+
getContents: getDeveloperAppSettings,
|
|
22
|
+
path: "..",
|
|
23
|
+
conditional: true,
|
|
24
|
+
}),
|
|
25
|
+
new LibrarySourceFile({
|
|
26
|
+
filename: "launchSettings.json",
|
|
27
|
+
emitter: emitter,
|
|
28
|
+
getContents: () => getLaunchSettings(httpPort, httpsPort),
|
|
29
|
+
path: "../Properties",
|
|
30
|
+
conditional: true,
|
|
31
|
+
}),
|
|
32
|
+
];
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function getProjectFile(useSwaggerUI) {
|
|
36
|
+
return `<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
37
|
+
|
|
38
|
+
<PropertyGroup>
|
|
39
|
+
<TargetFramework>net9.0</TargetFramework>
|
|
40
|
+
<Nullable>enable</Nullable>
|
|
41
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
42
|
+
</PropertyGroup>
|
|
43
|
+
|
|
44
|
+
${useSwaggerUI
|
|
45
|
+
? ` <ItemGroup>
|
|
46
|
+
<PackageReference Include="SwashBuckle.AspNetCore" Version="7.3.1" />
|
|
47
|
+
</ItemGroup>`
|
|
48
|
+
: ""}
|
|
49
|
+
|
|
50
|
+
</Project>
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
function getAppSettings() {
|
|
54
|
+
return `{
|
|
55
|
+
"Logging": {
|
|
56
|
+
"LogLevel": {
|
|
57
|
+
"Default": "Information",
|
|
58
|
+
"Microsoft.AspNetCore": "Warning"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"AllowedHosts": "*"
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
function getDeveloperAppSettings() {
|
|
66
|
+
return `{
|
|
67
|
+
"Logging": {
|
|
68
|
+
"LogLevel": {
|
|
69
|
+
"Default": "Information",
|
|
70
|
+
"Microsoft.AspNetCore": "Warning"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
function getLaunchSettings(httpPort, httpsPort) {
|
|
77
|
+
return `{
|
|
78
|
+
"$schema": "https://json.schemastore.org/launchsettings.json",
|
|
79
|
+
"profiles": {
|
|
80
|
+
"https": {
|
|
81
|
+
"commandName": "Project",
|
|
82
|
+
"dotnetRunMessages": true,
|
|
83
|
+
"launchBrowser": true,
|
|
84
|
+
"applicationUrl": "https://localhost:${httpsPort};http://localhost:${httpPort}",
|
|
85
|
+
"environmentVariables": {
|
|
86
|
+
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"http": {
|
|
90
|
+
"commandName": "Project",
|
|
91
|
+
"dotnetRunMessages": true,
|
|
92
|
+
"launchBrowser": true,
|
|
93
|
+
"applicationUrl": "http://localhost:${httpPort}",
|
|
94
|
+
"environmentVariables": {
|
|
95
|
+
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}`;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../src/lib/project.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM,UAAU,iBAAiB,CAC/B,OAA0D,EAC1D,WAAmB,EACnB,YAAqB,EACrB,QAAgB,EAChB,SAAiB;IAEjB,MAAM,MAAM,GAAwB;QAClC,IAAI,iBAAiB,CAAC;YACpB,QAAQ,EAAE,GAAG,WAAW,SAAS;YACjC,OAAO,EAAE,OAAO;YAChB,WAAW,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC;YAC/C,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,IAAI;SAClB,CAAC;QACF,IAAI,iBAAiB,CAAC;YACpB,QAAQ,EAAE,kBAAkB;YAC5B,OAAO,EAAE,OAAO;YAChB,WAAW,EAAE,cAAc;YAC3B,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,IAAI;SAClB,CAAC;QACF,IAAI,iBAAiB,CAAC;YACpB,QAAQ,EAAE,8BAA8B;YACxC,OAAO,EAAE,OAAO;YAChB,WAAW,EAAE,uBAAuB;YACpC,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,IAAI;SAClB,CAAC;QACF,IAAI,iBAAiB,CAAC;YACpB,QAAQ,EAAE,qBAAqB;YAC/B,OAAO,EAAE,OAAO;YAChB,WAAW,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC;YACzD,IAAI,EAAE,eAAe;YACrB,WAAW,EAAE,IAAI;SAClB,CAAC;KACH,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AACD,SAAS,cAAc,CAAC,YAAqB;IAC3C,OAAO;;;;;;;;EASP,YAAY;QACV,CAAC,CAAC;;eAES;QACX,CAAC,CAAC,EACN;;;CAGC,CAAC;AACF,CAAC;AACD,SAAS,cAAc;IACrB,OAAO;;;;;;;;;CASR,CAAC;AACF,CAAC;AAED,SAAS,uBAAuB;IAC9B,OAAO;;;;;;;;CAQR,CAAC;AACF,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAgB,EAAE,SAAiB;IAC5D,OAAO;;;;;;;+CAOsC,SAAS,qBAAqB,QAAQ;;;;;;;;;8CASvC,QAAQ;;;;;;IAMlD,CAAC;AACL,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AssetEmitter } from "@typespec/asset-emitter";
|
|
2
2
|
import { CSharpType, LibrarySourceFile } from "./interfaces.js";
|
|
3
|
+
import { CSharpServiceEmitterOptions } from "./lib.js";
|
|
3
4
|
export interface BusinessLogicImplementation {
|
|
4
5
|
namespace: string;
|
|
5
6
|
interfaceName: string;
|
|
@@ -16,6 +17,6 @@ export interface BusinessLogicMethod {
|
|
|
16
17
|
}
|
|
17
18
|
export type BusinessLogicRegistrations = Map<string, BusinessLogicImplementation>;
|
|
18
19
|
export type BusinessLogicRegistration = [string, BusinessLogicImplementation];
|
|
19
|
-
export declare function getScaffoldingHelpers(emitter: AssetEmitter<string,
|
|
20
|
+
export declare function getScaffoldingHelpers(emitter: AssetEmitter<string, CSharpServiceEmitterOptions>, useSwagger: boolean, openApiPath: string, hasMockRegistration: boolean): LibrarySourceFile[];
|
|
20
21
|
export declare function getBusinessLogicImplementations(emitter: AssetEmitter<string, Record<string, never>>, registrations: BusinessLogicRegistrations, useSwagger: boolean, openApiPath: string): LibrarySourceFile[];
|
|
21
22
|
//# sourceMappingURL=scaffolding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffolding.d.ts","sourceRoot":"","sources":["../../../src/lib/scaffolding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAQ,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"scaffolding.d.ts","sourceRoot":"","sources":["../../../src/lib/scaffolding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAQ,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAEvD,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,mBAAmB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;IACvB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,MAAM,0BAA0B,GAAG,GAAG,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;AAClF,MAAM,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;AAE9E,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,2BAA2B,CAAC,EAC1D,UAAU,EAAE,OAAO,EACnB,WAAW,EAAE,MAAM,EACnB,mBAAmB,EAAE,OAAO,GAC3B,iBAAiB,EAAE,CA8BrB;AAED,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EACpD,aAAa,EAAE,0BAA0B,EACzC,UAAU,EAAE,OAAO,EACnB,WAAW,EAAE,MAAM,GAClB,iBAAiB,EAAE,CA4BrB"}
|
|
@@ -7,7 +7,8 @@ export function getScaffoldingHelpers(emitter, useSwagger, openApiPath, hasMockR
|
|
|
7
7
|
filename: "Program.cs",
|
|
8
8
|
emitter: emitter,
|
|
9
9
|
getContents: () => getProjectStartup(useSwagger, openApiPath, hasMockRegistration),
|
|
10
|
-
path: "
|
|
10
|
+
path: "..",
|
|
11
|
+
conditional: true,
|
|
11
12
|
}),
|
|
12
13
|
];
|
|
13
14
|
if (hasMockRegistration) {
|
|
@@ -15,12 +16,14 @@ export function getScaffoldingHelpers(emitter, useSwagger, openApiPath, hasMockR
|
|
|
15
16
|
filename: "IInitializer.cs",
|
|
16
17
|
emitter: emitter,
|
|
17
18
|
getContents: getInitializerInterface,
|
|
18
|
-
path: "../mocks
|
|
19
|
+
path: "../mocks",
|
|
20
|
+
conditional: true,
|
|
19
21
|
}), new LibrarySourceFile({
|
|
20
22
|
filename: "Initializer.cs",
|
|
21
23
|
emitter: emitter,
|
|
22
24
|
getContents: getInitializerImplementation,
|
|
23
|
-
path: "../mocks
|
|
25
|
+
path: "../mocks",
|
|
26
|
+
conditional: true,
|
|
24
27
|
}));
|
|
25
28
|
}
|
|
26
29
|
return sourceFiles;
|
|
@@ -33,7 +36,8 @@ export function getBusinessLogicImplementations(emitter, registrations, useSwagg
|
|
|
33
36
|
filename: `${impl.className}.cs`,
|
|
34
37
|
emitter: emitter,
|
|
35
38
|
getContents: () => getBusinessLogicImplementation(impl),
|
|
36
|
-
path: "../mocks
|
|
39
|
+
path: "../mocks",
|
|
40
|
+
conditional: true,
|
|
37
41
|
}));
|
|
38
42
|
mocks.push(impl);
|
|
39
43
|
}
|
|
@@ -42,10 +46,10 @@ export function getBusinessLogicImplementations(emitter, registrations, useSwagg
|
|
|
42
46
|
filename: "MockRegistration.cs",
|
|
43
47
|
emitter: emitter,
|
|
44
48
|
getContents: () => getMockRegistration(mocks),
|
|
45
|
-
path: "../mocks
|
|
49
|
+
path: "../mocks",
|
|
50
|
+
conditional: true,
|
|
46
51
|
}));
|
|
47
52
|
}
|
|
48
|
-
sourceFiles.push(...getScaffoldingHelpers(emitter, useSwagger, openApiPath, mocks.length > 0));
|
|
49
53
|
return sourceFiles;
|
|
50
54
|
}
|
|
51
55
|
function getReturnStatement(returnType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffolding.js","sourceRoot":"","sources":["../../../src/lib/scaffolding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAc,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"scaffolding.js","sourceRoot":"","sources":["../../../src/lib/scaffolding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAc,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAsBhE,MAAM,UAAU,qBAAqB,CACnC,OAA0D,EAC1D,UAAmB,EACnB,WAAmB,EACnB,mBAA4B;IAE5B,MAAM,WAAW,GAAwB;QACvC,IAAI,iBAAiB,CAAC;YACpB,QAAQ,EAAE,YAAY;YACtB,OAAO,EAAE,OAAO;YAChB,WAAW,EAAE,GAAG,EAAE,CAAC,iBAAiB,CA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EAAE,CAAC,0CAA0C,CAAC,CAAC,aAAa,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;EAShH,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,UAAmB,EAAE,WAAmB,EAAE,QAAiB;IACpF,OAAO,GAAG,+BAA+B;;;;;;;;;EASzC,UAAU,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC,CAAC,EAAE;EACrD,QAAQ,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;EAYrD,UAAU;QACR,CAAC,CAAC,IAAI,CAAA;;;;;;;;IAQN;QACA,CAAC,CAAC,EACN;;;;;;;;;EAUE,UAAU;QACR,CAAC,CAAC,IAAI,CAAA;;;8BAGoB,WAAW;;;;;;;;;MASnC;QACF,CAAC,CAAC,EACN;;;;;;;;;;;;WAYW,CAAC;AACZ,CAAC;AAED,SAAS,uBAAuB;IAC9B,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;CAwB1C,CAAC;AACF,CAAC;AAED,SAAS,4BAA4B;IACnC,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiK1C,CAAC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/lib/service.ts"],"names":[],"mappings":"AAcA,OAAO,EAEL,WAAW,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/lib/service.ts"],"names":[],"mappings":"AAcA,OAAO,EAEL,WAAW,EA2BZ,MAAM,oBAAoB,CAAC;AA2B5B,OAAO,EAAE,2BAA2B,EAAoB,MAAM,UAAU,CAAC;AAwCzE,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,2BAA2B,CAAC,iBA2rC9E"}
|
package/dist/src/lib/service.js
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
import { CodeTypeEmitter, StringBuilder, code, createAssetEmitter, } from "@typespec/asset-emitter";
|
|
2
|
-
import { getDoc, getNamespaceFullName, getService, isErrorModel, isNeverType, isNullType, isTemplateDeclaration, isVoidType, serializeValueAsJson, } from "@typespec/compiler";
|
|
2
|
+
import { getDoc, getNamespaceFullName, getService, isErrorModel, isNeverType, isNullType, isTemplateDeclaration, isVoidType, resolvePath, serializeValueAsJson, } from "@typespec/compiler";
|
|
3
3
|
import { createRekeyableMap } from "@typespec/compiler/utils";
|
|
4
4
|
import { getHttpOperation, getHttpPart, isStatusCode, } from "@typespec/http";
|
|
5
5
|
import { getResourceOperation } from "@typespec/rest";
|
|
6
6
|
import { execFile } from "child_process";
|
|
7
|
+
import path from "path";
|
|
7
8
|
import { getEncodedNameAttribute } from "./attributes.js";
|
|
8
9
|
import { GeneratedFileHeader, GeneratedFileHeaderWithNullable, getSerializationSourceFiles, } from "./boilerplate.js";
|
|
10
|
+
import { getProjectDocs } from "./doc.js";
|
|
9
11
|
import { CSharpSourceType, CSharpType, NameCasingType, } from "./interfaces.js";
|
|
10
12
|
import { reportDiagnostic } from "./lib.js";
|
|
11
|
-
import {
|
|
13
|
+
import { getProjectHelpers } from "./project.js";
|
|
14
|
+
import { getBusinessLogicImplementations, getScaffoldingHelpers, } from "./scaffolding.js";
|
|
12
15
|
import { getRecordType, isKnownReferenceType } from "./type-helpers.js";
|
|
13
|
-
import { CSharpOperationHelpers, HttpMetadata, UnknownType, coalesceTypes, coalesceUnionTypes, ensureCSharpIdentifier, ensureCleanDirectory, formatComment, getBusinessLogicCallParameters, getBusinessLogicDeclParameters, getCSharpIdentifier, getCSharpStatusCode, getCSharpType, getCSharpTypeForIntrinsic, getCSharpTypeForScalar, getHttpDeclParameters, getModelAttributes, getModelDeclarationName, getModelInstantiationName, getOperationVerbDecorator, isEmptyResponseModel, isValueType, } from "./utils.js";
|
|
16
|
+
import { CSharpOperationHelpers, HttpMetadata, UnknownType, coalesceTypes, coalesceUnionTypes, ensureCSharpIdentifier, ensureCleanDirectory, formatComment, getBusinessLogicCallParameters, getBusinessLogicDeclParameters, getCSharpIdentifier, getCSharpStatusCode, getCSharpType, getCSharpTypeForIntrinsic, getCSharpTypeForScalar, getFreePort, getHttpDeclParameters, getModelAttributes, getModelDeclarationName, getModelInstantiationName, getOpenApiConfig, getOperationVerbDecorator, isEmptyResponseModel, isValueType, } from "./utils.js";
|
|
14
17
|
export async function $onEmit(context) {
|
|
15
18
|
let _unionCounter = 0;
|
|
16
19
|
const controllers = new Map();
|
|
17
20
|
const NoResourceContext = "RPCOperations";
|
|
18
21
|
const doNotEmit = context.program.compilerOptions.dryRun || false;
|
|
22
|
+
function getFileWriter(program) {
|
|
23
|
+
return async (path) => !!(await program.host.stat(resolvePath(path)).catch((_) => false));
|
|
24
|
+
}
|
|
19
25
|
class CSharpCodeEmitter extends CodeTypeEmitter {
|
|
20
26
|
#metadateMap = new Map();
|
|
21
27
|
#generatedFileHeaderWithNullable = GeneratedFileHeaderWithNullable;
|
|
22
28
|
#generatedFileHeader = GeneratedFileHeader;
|
|
23
29
|
#sourceTypeKey = "sourceType";
|
|
24
|
-
#libraryFiles = getSerializationSourceFiles(this.emitter);
|
|
25
30
|
#baseNamespace = undefined;
|
|
26
31
|
#emitterOutputType = context.options["output-type"];
|
|
27
32
|
#emitMocks = context.options["emit-mocks"];
|
|
28
33
|
#useSwagger = context.options["use-swaggerui"] || false;
|
|
29
34
|
#openapiPath = context.options["openapi-path"] || "openapi/openapi.yaml";
|
|
30
35
|
#mockRegistrations = new Map();
|
|
31
|
-
#mockFiles = [];
|
|
32
36
|
#opHelpers = new CSharpOperationHelpers(this.emitter);
|
|
37
|
+
#fileExists = getFileWriter(this.emitter.getProgram());
|
|
33
38
|
arrayDeclaration(array, name, elementType) {
|
|
34
39
|
return this.emitter.result.declaration(ensureCSharpIdentifier(this.emitter.getProgram(), array, name), code `${this.emitter.emitTypeReference(elementType)}[]`);
|
|
35
40
|
}
|
|
@@ -700,15 +705,8 @@ export async function $onEmit(context) {
|
|
|
700
705
|
return scalarType.getTypeReference(this.emitter.getContext().scope);
|
|
701
706
|
}
|
|
702
707
|
sourceFile(sourceFile) {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return libFile.emitted;
|
|
706
|
-
}
|
|
707
|
-
if (this.#mockFiles.length > 0) {
|
|
708
|
-
for (const mock of this.#mockFiles) {
|
|
709
|
-
if (sourceFile === mock.source)
|
|
710
|
-
return mock.emitted;
|
|
711
|
-
}
|
|
708
|
+
if (sourceFile.meta.emitted) {
|
|
709
|
+
return sourceFile.meta.emitted;
|
|
712
710
|
}
|
|
713
711
|
const emittedSourceFile = {
|
|
714
712
|
path: sourceFile.path,
|
|
@@ -799,17 +797,18 @@ export async function $onEmit(context) {
|
|
|
799
797
|
return params.reduce();
|
|
800
798
|
return "";
|
|
801
799
|
}
|
|
802
|
-
writeOutput(sourceFiles) {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
if (this.#emitMocks === "all") {
|
|
800
|
+
async writeOutput(sourceFiles) {
|
|
801
|
+
sourceFiles.push(...getSerializationSourceFiles(this.emitter).flatMap((l) => l.source));
|
|
802
|
+
sourceFiles.push(...getProjectDocs(this.emitter, this.#useSwagger, this.#mockRegistrations).flatMap((l) => l.source));
|
|
803
|
+
if (this.#emitMocks === "mocks-and-project-files" || this.#emitMocks === "mocks-only") {
|
|
807
804
|
if (this.#mockRegistrations.size > 0) {
|
|
808
805
|
const mocks = getBusinessLogicImplementations(this.emitter, this.#mockRegistrations, this.#useSwagger, this.#openapiPath);
|
|
809
|
-
this.#mockFiles.push(...mocks);
|
|
810
806
|
sourceFiles.push(...mocks.flatMap((l) => l.source));
|
|
811
807
|
}
|
|
812
808
|
}
|
|
809
|
+
async function shouldWrite(source, exists) {
|
|
810
|
+
return (!source.meta.conditional || options.overwrite === true || !(await exists(source.path)));
|
|
811
|
+
}
|
|
813
812
|
const emittedSourceFiles = [];
|
|
814
813
|
for (const source of sourceFiles) {
|
|
815
814
|
switch (this.#emitterOutputType) {
|
|
@@ -820,13 +819,17 @@ export async function $onEmit(context) {
|
|
|
820
819
|
// do nothing
|
|
821
820
|
break;
|
|
822
821
|
default:
|
|
823
|
-
|
|
822
|
+
if (await shouldWrite(source, this.#fileExists)) {
|
|
823
|
+
emittedSourceFiles.push(source);
|
|
824
|
+
}
|
|
824
825
|
break;
|
|
825
826
|
}
|
|
826
827
|
}
|
|
827
828
|
break;
|
|
828
829
|
default:
|
|
829
|
-
|
|
830
|
+
if (await shouldWrite(source, this.#fileExists)) {
|
|
831
|
+
emittedSourceFiles.push(source);
|
|
832
|
+
}
|
|
830
833
|
break;
|
|
831
834
|
}
|
|
832
835
|
}
|
|
@@ -914,7 +917,46 @@ export async function $onEmit(context) {
|
|
|
914
917
|
processNameSpace(context.program, ns);
|
|
915
918
|
if (!doNotEmit) {
|
|
916
919
|
await ensureCleanDirectory(context.program, options.emitterOutputDir);
|
|
920
|
+
function normalizeSlashes(path) {
|
|
921
|
+
return path.replaceAll("\\", "/");
|
|
922
|
+
}
|
|
923
|
+
async function getOpenApiPath() {
|
|
924
|
+
if (options["openapi-path"])
|
|
925
|
+
return options["openapi-path"];
|
|
926
|
+
const openApiSettings = await getOpenApiConfig(context.program);
|
|
927
|
+
const projectDir = resolvePath(context.program.projectRoot, options.emitterOutputDir, "..");
|
|
928
|
+
if (openApiSettings.outputDir) {
|
|
929
|
+
const openApiPath = resolvePath(openApiSettings.outputDir, openApiSettings.fileName || "openapi.yaml");
|
|
930
|
+
return normalizeSlashes(path.relative(projectDir, openApiPath));
|
|
931
|
+
}
|
|
932
|
+
if (openApiSettings.emitted) {
|
|
933
|
+
const baseDir = context.program.compilerOptions.outputDir ||
|
|
934
|
+
resolvePath(context.program.projectRoot, "tsp-output");
|
|
935
|
+
const openApiPath = resolvePath(baseDir, "@typespec", "openapi3", openApiSettings.fileName || "openapi.yaml");
|
|
936
|
+
return normalizeSlashes(path.relative(projectDir, openApiPath));
|
|
937
|
+
}
|
|
938
|
+
return "";
|
|
939
|
+
}
|
|
940
|
+
const openApiPath = await getOpenApiPath();
|
|
941
|
+
const UseSwaggerUI = openApiPath !== "" && options["use-swaggerui"] === true;
|
|
942
|
+
let httpPort;
|
|
943
|
+
let httpsPort;
|
|
944
|
+
if (options["emit-mocks"] !== "none") {
|
|
945
|
+
getScaffoldingHelpers(emitter, UseSwaggerUI, openApiPath, true);
|
|
946
|
+
}
|
|
947
|
+
if (options["emit-mocks"] === "mocks-and-project-files") {
|
|
948
|
+
httpPort = options["http-port"] || (await getFreePort(5000, 5999));
|
|
949
|
+
httpsPort = options["https-port"] || (await getFreePort(7000, 7999));
|
|
950
|
+
getProjectHelpers(emitter, options["project-name"] || "ServiceProject", options["use-swaggerui"] || false, httpPort, httpsPort);
|
|
951
|
+
}
|
|
917
952
|
await emitter.writeOutput();
|
|
953
|
+
const projectDir = normalizeSlashes(path.relative(process.cwd(), resolvePath(options.emitterOutputDir, "..")));
|
|
954
|
+
const traceId = "http-server-csharp";
|
|
955
|
+
context.program.trace(traceId, `Your project was successfully created at "${projectDir}"`);
|
|
956
|
+
context.program.trace(traceId, `You can build and start the project using 'dotnet run --project "${projectDir}"'`);
|
|
957
|
+
if (options["use-swaggerui"] === true && httpsPort) {
|
|
958
|
+
context.program.trace(traceId, `You can browse the swagger UI to test your service using 'start https://localhost:${httpsPort}/swagger/' `);
|
|
959
|
+
}
|
|
918
960
|
if (options["skip-format"] === undefined || options["skip-format"] === false) {
|
|
919
961
|
await execFile("dotnet", [
|
|
920
962
|
"format",
|