Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2137,9 +2137,6 @@ export class CodeModelBuilder {
}
if (discriminatorProperty) {
objectSchema.discriminator = new Discriminator(this.processModelProperty(discriminatorProperty));
// as we do not expose the discriminator property, its schema is fine to be just a string (and we do not want to generate an enum that not used anywhere)
// TODO: support enum schema, if we expose the discriminator property
objectSchema.discriminator.property.schema = this.stringSchema;
} else {
// fallback to property name, if cannot find the discriminator property
objectSchema.discriminator = new Discriminator(
Expand Down Expand Up @@ -2810,6 +2807,10 @@ export class CodeModelBuilder {

schema.children?.all?.forEach((c) => innerApplySchemaUsage(c, schemaUsage));
schema.children?.immediate?.forEach((c) => innerApplySchemaUsage(c, schemaUsage));

if (schema.discriminator?.property?.schema) {
innerApplySchemaUsage(schema.discriminator?.property?.schema, schemaUsage);
}
}

// Object.values(schema.discriminator?.all ?? {}).forEach((d) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class EnumDiscriminatorAsyncClient {
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -72,7 +72,7 @@ public Mono<Response<BinaryData>> getExtensibleModelWithResponse(RequestOptions
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -98,7 +98,7 @@ public Mono<Response<Void>> putExtensibleModelWithResponse(BinaryData input, Req
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -124,7 +124,7 @@ public Mono<Response<Void>> putExtensibleModelWithResponse(BinaryData input, Req
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -150,7 +150,7 @@ public Mono<Response<BinaryData>> getExtensibleModelWrongDiscriminatorWithRespon
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -176,7 +176,7 @@ public Mono<Response<BinaryData>> getFixedModelWithResponse(RequestOptions reque
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -202,7 +202,7 @@ public Mono<Response<Void>> putFixedModelWithResponse(BinaryData input, RequestO
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -227,7 +227,7 @@ public Mono<Response<BinaryData>> getFixedModelMissingDiscriminatorWithResponse(
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class EnumDiscriminatorClient {
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -69,7 +69,7 @@ public Response<BinaryData> getExtensibleModelWithResponse(RequestOptions reques
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -95,7 +95,7 @@ public Response<Void> putExtensibleModelWithResponse(BinaryData input, RequestOp
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -120,7 +120,7 @@ public Response<BinaryData> getExtensibleModelMissingDiscriminatorWithResponse(R
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -145,7 +145,7 @@ public Response<BinaryData> getExtensibleModelWrongDiscriminatorWithResponse(Req
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -170,7 +170,7 @@ public Response<BinaryData> getFixedModelWithResponse(RequestOptions requestOpti
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -196,7 +196,7 @@ public Response<Void> putFixedModelWithResponse(BinaryData input, RequestOptions
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -221,7 +221,7 @@ public Response<BinaryData> getFixedModelMissingDiscriminatorWithResponse(Reques
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Response<BinaryData> getFixedModelWrongDiscriminatorSync(@HeaderParam("accept")
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -284,7 +284,7 @@ public Mono<Response<BinaryData>> getExtensibleModelWithResponseAsync(RequestOpt
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -309,7 +309,7 @@ public Response<BinaryData> getExtensibleModelWithResponse(RequestOptions reques
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -335,7 +335,7 @@ public Mono<Response<Void>> putExtensibleModelWithResponseAsync(BinaryData input
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -361,7 +361,7 @@ public Response<Void> putExtensibleModelWithResponse(BinaryData input, RequestOp
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -388,7 +388,7 @@ public Response<Void> putExtensibleModelWithResponse(BinaryData input, RequestOp
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -413,7 +413,7 @@ public Response<BinaryData> getExtensibleModelMissingDiscriminatorWithResponse(R
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand Down Expand Up @@ -441,7 +441,7 @@ public Response<BinaryData> getExtensibleModelMissingDiscriminatorWithResponse(R
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(golden) (Optional)
* weight: int (Required)
* }
* }</pre>
Expand All @@ -466,7 +466,7 @@ public Response<BinaryData> getExtensibleModelWrongDiscriminatorWithResponse(Req
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -492,7 +492,7 @@ public Mono<Response<BinaryData>> getFixedModelWithResponseAsync(RequestOptions
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -517,7 +517,7 @@ public Response<BinaryData> getFixedModelWithResponse(RequestOptions requestOpti
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -543,7 +543,7 @@ public Mono<Response<Void>> putFixedModelWithResponseAsync(BinaryData input, Req
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -569,7 +569,7 @@ public Response<Void> putFixedModelWithResponse(BinaryData input, RequestOptions
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -596,7 +596,7 @@ public Response<Void> putFixedModelWithResponse(BinaryData input, RequestOptions
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -621,7 +621,7 @@ public Response<BinaryData> getFixedModelMissingDiscriminatorWithResponse(Reques
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand All @@ -648,7 +648,7 @@ public Mono<Response<BinaryData>> getFixedModelWrongDiscriminatorWithResponseAsy
* </p>
* <pre>{@code
* {
* kind: String (Optional)
* kind: String(cobra) (Optional)
* length: int (Required)
* }
* }</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public final class Cobra extends Snake {
@Generated
public Cobra(int length) {
super(length);
setKind("cobra");
setKind(SnakeKind.COBRA);
}

@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeIntField("length", getLength());
jsonWriter.writeStringField("kind", getKind());
jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString());
return jsonWriter.writeEndObject();
}

Expand All @@ -49,15 +49,15 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
public static Cobra fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
int length = 0;
String kind = "cobra";
SnakeKind kind = SnakeKind.COBRA;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();

if ("length".equals(fieldName)) {
length = reader.getInt();
} else if ("kind".equals(fieldName)) {
kind = reader.getString();
kind = SnakeKind.fromString(reader.getString());
} else {
reader.skipChildren();
}
Expand Down
Loading