@@ -11,6 +11,7 @@ import {
11
11
SdkType ,
12
12
UsageFlags ,
13
13
} from "@azure-tools/typespec-client-generator-core" ;
14
+ import { NoTarget } from "@typespec/compiler" ;
14
15
import { NetEmitterOptions , resolveOptions } from "../options.js" ;
15
16
import { CodeModel } from "../type/code-model.js" ;
16
17
import { InputClient } from "../type/input-client.js" ;
@@ -20,6 +21,7 @@ import { InputEnumType, InputModelType, InputType } from "../type/input-type.js"
20
21
import { RequestLocation } from "../type/request-location.js" ;
21
22
import { SdkTypeMap } from "../type/sdk-type-map.js" ;
22
23
import { fromSdkType } from "./converter.js" ;
24
+ import { reportDiagnostic } from "./lib.js" ;
23
25
import { Logger } from "./logger.js" ;
24
26
import { navigateModels } from "./model.js" ;
25
27
import { fromSdkServiceMethod , getParameterDefaultValue } from "./operation-converter.js" ;
@@ -38,17 +40,19 @@ export function createModel(sdkContext: SdkContext<NetEmitterOptions>): CodeMode
38
40
39
41
const sdkApiVersionEnums = sdkPackage . enums . filter ( ( e ) => e . usage === UsageFlags . ApiVersionEnum ) ;
40
42
43
+ const rootClients = sdkPackage . clients . filter ( ( c ) => c . initialization . access === "public" ) ;
44
+ if ( rootClients . length === 0 ) {
45
+ reportDiagnostic ( sdkContext . program , { code : "no-root-client" , format : { } , target : NoTarget } ) ;
46
+ return { } as CodeModel ;
47
+ }
48
+
41
49
const rootApiVersions =
42
50
sdkApiVersionEnums . length > 0
43
51
? sdkApiVersionEnums [ 0 ] . values . map ( ( v ) => v . value as string ) . flat ( )
44
- : getRootApiVersions ( sdkPackage . clients ) ;
52
+ : rootClients [ 0 ] . apiVersions ;
45
53
46
54
const inputClients : InputClient [ ] = [ ] ;
47
- fromSdkClients (
48
- sdkPackage . clients . filter ( ( c ) => c . initialization . access === "public" ) ,
49
- inputClients ,
50
- [ ] ,
51
- ) ;
55
+ fromSdkClients ( rootClients , inputClients , [ ] ) ;
52
56
53
57
const clientModel : CodeModel = {
54
58
Name : sdkPackage . rootNamespace ,
@@ -177,14 +181,6 @@ export function createModel(sdkContext: SdkContext<NetEmitterOptions>): CodeMode
177
181
}
178
182
}
179
183
180
- function getRootApiVersions ( clients : SdkClientType < SdkHttpOperation > [ ] ) : string [ ] {
181
- // find any root client since they should have the same api versions
182
- const oneRootClient = clients . find ( ( c ) => c . initialization . access === "public" ) ;
183
- if ( ! oneRootClient ) throw new Error ( "Root client not found" ) ;
184
-
185
- return oneRootClient . apiVersions ;
186
- }
187
-
188
184
function getMethodUri ( p : SdkEndpointParameter | undefined ) : string {
189
185
if ( ! p ) return "" ;
190
186
0 commit comments