Skip to content

Commit b597268

Browse files
include path/query in output as readOnly
1 parent 45768ce commit b597268

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/http-client-java/emitter/src/code-model-builder.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {
6868
SdkServiceMethod,
6969
SdkType,
7070
SdkUnionType,
71+
UsageFlags,
7172
createSdkContext,
7273
getAllModels,
7374
getClientNameOverride,
@@ -100,6 +101,8 @@ import {
100101
HttpStatusCodesEntry,
101102
Visibility,
102103
getAuthentication,
104+
isPathParam,
105+
isQueryParam,
103106
} from "@typespec/http";
104107
import { getSegment } from "@typespec/rest";
105108
import { getAddedOnVersions } from "@typespec/versioning";
@@ -2696,8 +2699,17 @@ export class CodeModelBuilder {
26962699
}
26972700

26982701
// properties
2702+
const modelUsedInOutput = type.usage & UsageFlags.Output;
26992703
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) {
27012713
objectSchema.addProperty(this.processModelProperty(prop));
27022714
}
27032715
}
@@ -2953,6 +2965,9 @@ export class CodeModelBuilder {
29532965
const segment = target.__raw ? getSegment(this.program, target.__raw) !== undefined : false;
29542966
if (segment) {
29552967
return true;
2968+
} else if (isHttpMetadata(this.sdkContext, target)) {
2969+
// metadata (path/query) is always read-only
2970+
return true;
29562971
} else {
29572972
const visibility = target.visibility;
29582973
if (visibility) {

0 commit comments

Comments
 (0)