-
Notifications
You must be signed in to change notification settings - Fork 173
Serialize configuration and tspCodeModel from swagger #5289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cd7b119
7525fe6
52054ac
b8bd696
61f45e2
396a04c
9826b6f
ec493e6
41295f8
ce508f5
8fed7e9
ad45ace
42a3b3d
9644c07
4247cf4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
namespace AutoRest.CSharp.Common.Input; | ||
|
||
internal record InputEnumTypeValue(string Name, object Value, string? Summary, string? Doc) | ||
internal abstract record InputEnumTypeValue(string Name, object Value, string? Summary, string? Doc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think we should take this change to MTG to avoid instantiation of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep - this part is done in a really messy way, as well as in MTG. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and to clarify, I think "using the input library from MTG" should not be part of our plan - it will be a huge change and we might encounter various of issues. At least in short time, we do not need to consider to use the types from MTG - having these types defined in this library actually has its advantages. |
||
{ | ||
public virtual string GetJsonValueString() => GetValueString(); | ||
public string GetValueString() => (Value.ToString() ?? string.Empty); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,15 @@ | |
using System.Collections.Generic; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using AutoRest.CSharp.Utilities; | ||
|
||
namespace AutoRest.CSharp.Common.Input | ||
{ | ||
internal class TypeSpecInputDateTimeTypeConverter : JsonConverter<InputDateTimeType> | ||
{ | ||
internal const string UtcDateTimeKind = "utcDateTime"; | ||
internal const string OffsetDateTimeKind = "offsetDateTime"; | ||
|
||
private readonly TypeSpecReferenceHandler _referenceHandler; | ||
public TypeSpecInputDateTimeTypeConverter(TypeSpecReferenceHandler referenceHandler) | ||
{ | ||
|
@@ -19,9 +23,6 @@ public TypeSpecInputDateTimeTypeConverter(TypeSpecReferenceHandler referenceHand | |
public override InputDateTimeType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
=> reader.ReadReferenceAndResolve<InputDateTimeType>(_referenceHandler.CurrentResolver) ?? CreateDateTimeType(ref reader, null, null, options, _referenceHandler.CurrentResolver); | ||
|
||
public override void Write(Utf8JsonWriter writer, InputDateTimeType value, JsonSerializerOptions options) | ||
=> throw new NotSupportedException("Writing not supported"); | ||
|
||
public static InputDateTimeType CreateDateTimeType(ref Utf8JsonReader reader, string? id, string? name, JsonSerializerOptions options, ReferenceResolver resolver) | ||
{ | ||
var isFirstProperty = id == null; | ||
|
@@ -65,5 +66,26 @@ public static InputDateTimeType CreateDateTimeType(ref Utf8JsonReader reader, st | |
} | ||
return dateTimeType; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, InputDateTimeType value, JsonSerializerOptions options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add a tracking item to consider using the MTG.Input library instead of having its own. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here: #5292 |
||
=> writer.WriteObjectOrReference<InputDateTimeType>(value, options, _referenceHandler.CurrentResolver, WriteInputDateTimeType); | ||
|
||
private static void WriteInputDateTimeType(Utf8JsonWriter writer, InputDateTimeType value, JsonSerializerOptions options) | ||
{ | ||
// kind | ||
writer.WriteString("kind", UtcDateTimeKind); // TODO -- currently the two different kinds have exactly the same properties, therefore here we no longer have the ability to distinguish | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the plan for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is possible that we make this class abstract, and make UtcDateTimeType and OffsetDateTimeType to derive from it, like what we have done for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I think we should also do the same in MTG. |
||
// name | ||
writer.WriteString("name", value.Name); | ||
// encode | ||
writer.WriteString("encode", value.Encode.ToString().FirstCharToLowerCase()); | ||
// wireType | ||
writer.WriteObject("wireType", value.WireType, options); | ||
// crossLanguageDefinitionId | ||
writer.WriteString("crossLanguageDefinitionId", value.CrossLanguageDefinitionId); | ||
// baseType | ||
writer.WriteObjectIfPresent("baseType", value.BaseType, options); | ||
// decorators | ||
writer.WriteArray("decorators", value.Decorators, options); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets consider making this a singleton
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created this issue to track: #5295