Skip to content

Commit

Permalink
change the default of use-write-core to true for typespec mgmt specs (#…
Browse files Browse the repository at this point in the history
…5093)

* change the default of use-write-core to true for mgmt and typespec

* fix format

* regen
  • Loading branch information
ArcturusZhang authored Oct 8, 2024
1 parent 1e93f14 commit 53d2e57
Show file tree
Hide file tree
Showing 23 changed files with 178 additions and 303 deletions.
4 changes: 3 additions & 1 deletion src/TypeSpec.Extension/Emitter.Csharp/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export async function $onEmit(context: EmitContext<AzureNetEmitterOptions>) {
);
configurations["azure-arm"] =
sdkContext.arm === false ? undefined : sdkContext.arm;
configurations["use-write-core"] = options["use-write-core"];
configurations["use-write-core"] =
options["use-write-core"] ??
(configurations["azure-arm"] ? true : undefined);
await program.host.writeFile(
resolvePath(outputFolder, configurationFileName),
prettierOutput(JSON.stringify(configurations, null, 2))
Expand Down
2 changes: 1 addition & 1 deletion src/TypeSpec.Extension/Emitter.Csharp/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const AzureNetEmitterOptionsSchema: JSONSchemaType<AzureNetEmitterOptions
},
"use-write-core": {
type: "boolean",
default: false
nullable: true
}
},
required: []
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ internal partial class ManagedIdentityTrackedResourceProperties : IUtf8JsonSeria
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<ManagedIdentityTrackedResourceProperties>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<ManagedIdentityTrackedResourceProperties>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<ManagedIdentityTrackedResourceProperties>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(ManagedIdentityTrackedResourceProperties)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (options.Format != "W")
{
writer.WritePropertyName("provisioningState"u8);
Expand All @@ -46,7 +54,6 @@ void IJsonModel<ManagedIdentityTrackedResourceProperties>.Write(Utf8JsonWriter w
#endif
}
}
writer.WriteEndObject();
}

ManagedIdentityTrackedResourceProperties IJsonModel<ManagedIdentityTrackedResourceProperties>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ internal partial class NestedProxyResourceListResult : IUtf8JsonSerializable, IJ
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<NestedProxyResourceListResult>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<NestedProxyResourceListResult>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<NestedProxyResourceListResult>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(NestedProxyResourceListResult)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("value"u8);
writer.WriteStartArray();
foreach (var item in Value)
Expand Down Expand Up @@ -53,7 +61,6 @@ void IJsonModel<NestedProxyResourceListResult>.Write(Utf8JsonWriter writer, Mode
#endif
}
}
writer.WriteEndObject();
}

NestedProxyResourceListResult IJsonModel<NestedProxyResourceListResult>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ public partial class NestedProxyResourceProperties : IUtf8JsonSerializable, IJso
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<NestedProxyResourceProperties>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<NestedProxyResourceProperties>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<NestedProxyResourceProperties>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(NestedProxyResourceProperties)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (options.Format != "W" && Optional.IsDefined(ProvisioningState))
{
writer.WritePropertyName("provisioningState"u8);
Expand All @@ -51,7 +59,6 @@ void IJsonModel<NestedProxyResourceProperties>.Write(Utf8JsonWriter writer, Mode
#endif
}
}
writer.WriteEndObject();
}

NestedProxyResourceProperties IJsonModel<NestedProxyResourceProperties>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ public partial class NotificationDetails : IUtf8JsonSerializable, IJsonModel<Not
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<NotificationDetails>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<NotificationDetails>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<NotificationDetails>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(NotificationDetails)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("message"u8);
writer.WriteStringValue(Message);
writer.WritePropertyName("urgent"u8);
Expand All @@ -45,7 +53,6 @@ void IJsonModel<NotificationDetails>.Write(Utf8JsonWriter writer, ModelReaderWri
#endif
}
}
writer.WriteEndObject();
}

NotificationDetails IJsonModel<NotificationDetails>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ internal partial class SingletonTrackedResourceListResult : IUtf8JsonSerializabl
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<SingletonTrackedResourceListResult>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<SingletonTrackedResourceListResult>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<SingletonTrackedResourceListResult>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(SingletonTrackedResourceListResult)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("value"u8);
writer.WriteStartArray();
foreach (var item in Value)
Expand Down Expand Up @@ -53,7 +61,6 @@ void IJsonModel<SingletonTrackedResourceListResult>.Write(Utf8JsonWriter writer,
#endif
}
}
writer.WriteEndObject();
}

SingletonTrackedResourceListResult IJsonModel<SingletonTrackedResourceListResult>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ public partial class SingletonTrackedResourceProperties : IUtf8JsonSerializable,
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<SingletonTrackedResourceProperties>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<SingletonTrackedResourceProperties>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<SingletonTrackedResourceProperties>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(SingletonTrackedResourceProperties)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (options.Format != "W" && Optional.IsDefined(ProvisioningState))
{
writer.WritePropertyName("provisioningState"u8);
Expand All @@ -51,7 +59,6 @@ void IJsonModel<SingletonTrackedResourceProperties>.Write(Utf8JsonWriter writer,
#endif
}
}
writer.WriteEndObject();
}

SingletonTrackedResourceProperties IJsonModel<SingletonTrackedResourceProperties>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ internal partial class TopLevelTrackedResourceListResult : IUtf8JsonSerializable
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<TopLevelTrackedResourceListResult>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<TopLevelTrackedResourceListResult>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<TopLevelTrackedResourceListResult>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(TopLevelTrackedResourceListResult)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("value"u8);
writer.WriteStartArray();
foreach (var item in Value)
Expand Down Expand Up @@ -53,7 +61,6 @@ void IJsonModel<TopLevelTrackedResourceListResult>.Write(Utf8JsonWriter writer,
#endif
}
}
writer.WriteEndObject();
}

TopLevelTrackedResourceListResult IJsonModel<TopLevelTrackedResourceListResult>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ public partial class TopLevelTrackedResourceProperties : IUtf8JsonSerializable,
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<TopLevelTrackedResourceProperties>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<TopLevelTrackedResourceProperties>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<TopLevelTrackedResourceProperties>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(TopLevelTrackedResourceProperties)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (options.Format != "W" && Optional.IsDefined(ProvisioningState))
{
writer.WritePropertyName("provisioningState"u8);
Expand All @@ -51,7 +59,6 @@ void IJsonModel<TopLevelTrackedResourceProperties>.Write(Utf8JsonWriter writer,
#endif
}
}
writer.WriteEndObject();
}

TopLevelTrackedResourceProperties IJsonModel<TopLevelTrackedResourceProperties>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Loading

0 comments on commit 53d2e57

Please sign in to comment.