@@ -17,7 +17,14 @@ import {
17
17
isService ,
18
18
resolveEncodedName ,
19
19
} from "@typespec/compiler" ;
20
- import { HttpOperation , getHttpOperation , getHttpPart , isMetadata } from "@typespec/http" ;
20
+ import {
21
+ HttpOperation ,
22
+ Visibility ,
23
+ getHttpOperation ,
24
+ getHttpPart ,
25
+ isMetadata ,
26
+ isVisible ,
27
+ } from "@typespec/http" ;
21
28
import { Version , getVersions } from "@typespec/versioning" ;
22
29
import { pascalCase } from "change-case" ;
23
30
import pluralize from "pluralize" ;
@@ -112,15 +119,20 @@ export function getClientNamespaceString(context: TCGCContext): string | undefin
112
119
}
113
120
114
121
/**
115
- * If the given type is an anonymous model and all of its properties excluding
116
- * header/query/path/status-code are sourced from a named model, returns that original named model.
117
- * Otherwise the given type is returned unchanged.
122
+ * If the given type is an anonymous model, returns a named model with same shape.
123
+ * The finding logic will ignore all the properties of header/query/path/status-code metadata,
124
+ * as well as the properties that are not visible in the given visibility if provided.
125
+ * If the model found is also anonymous, the input type is returned unchanged.
118
126
*
119
127
* @param context
120
128
* @param type
121
129
* @returns
122
130
*/
123
- export function getEffectivePayloadType ( context : TCGCContext , type : Model ) : Model {
131
+ export function getEffectivePayloadType (
132
+ context : TCGCContext ,
133
+ type : Model ,
134
+ visibility ?: Visibility ,
135
+ ) : Model {
124
136
const program = context . program ;
125
137
126
138
// if a type has name, we should resolve the name
@@ -135,7 +147,10 @@ export function getEffectivePayloadType(context: TCGCContext, type: Model): Mode
135
147
const effective = getEffectiveModelType (
136
148
program ,
137
149
type ,
138
- ( t ) => ! isMetadata ( context . program , t ) && ! hasNoneVisibility ( context , t ) ,
150
+ ( t ) =>
151
+ ! isMetadata ( context . program , t ) &&
152
+ ! hasNoneVisibility ( context , t ) &&
153
+ ( visibility === undefined || isVisible ( program , t , visibility ) ) ,
139
154
) ;
140
155
if ( effective . name ) {
141
156
return effective ;
0 commit comments