@@ -68,6 +68,7 @@ import {
68
68
SdkServiceMethod ,
69
69
SdkType ,
70
70
SdkUnionType ,
71
+ UsageFlags ,
71
72
createSdkContext ,
72
73
getAllModels ,
73
74
getClientNameOverride ,
@@ -100,6 +101,8 @@ import {
100
101
HttpStatusCodesEntry ,
101
102
Visibility ,
102
103
getAuthentication ,
104
+ isPathParam ,
105
+ isQueryParam ,
103
106
} from "@typespec/http" ;
104
107
import { getSegment } from "@typespec/rest" ;
105
108
import { getAddedOnVersions } from "@typespec/versioning" ;
@@ -2696,8 +2699,17 @@ export class CodeModelBuilder {
2696
2699
}
2697
2700
2698
2701
// properties
2702
+ const modelUsedInOutput = type . usage & UsageFlags . Output ;
2699
2703
for ( const prop of type . properties ) {
2700
- if ( ! isHttpMetadata ( this . sdkContext , prop ) && ! prop . discriminator ) {
2704
+ const isMetadata = ! isHttpMetadata ( this . sdkContext , prop ) ;
2705
+ const propertyHasRead = prop . visibility ?. includes ( Visibility . Read ) ;
2706
+ const includeMetadata =
2707
+ modelUsedInOutput &&
2708
+ propertyHasRead &&
2709
+ isMetadata &&
2710
+ prop . __raw &&
2711
+ ( isPathParam ( this . program , prop . __raw ) || isQueryParam ( this . program , prop . __raw ) ) ;
2712
+ if ( ( ! isMetadata || includeMetadata ) && ! prop . discriminator ) {
2701
2713
objectSchema . addProperty ( this . processModelProperty ( prop ) ) ;
2702
2714
}
2703
2715
}
@@ -2953,6 +2965,9 @@ export class CodeModelBuilder {
2953
2965
const segment = target . __raw ? getSegment ( this . program , target . __raw ) !== undefined : false ;
2954
2966
if ( segment ) {
2955
2967
return true ;
2968
+ } else if ( isHttpMetadata ( this . sdkContext , target ) ) {
2969
+ // metadata (path/query) is always read-only
2970
+ return true ;
2956
2971
} else {
2957
2972
const visibility = target . visibility ;
2958
2973
if ( visibility ) {
0 commit comments