@team-supercharge/oasg 19.0.0 → 19.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1195,6 +1195,26 @@ Validations from OpenAPI spec:
|
|
|
1195
1195
|
| apiKey | Api key of nuget source (If not specified, provide the CI_JOB_TOKEN) | N | - |
|
|
1196
1196
|
| generatorCustomArgs | Custom arguments of the generator (--global-property, --additional-properties) | N | - |
|
|
1197
1197
|
|
|
1198
|
+
> **Nullable object/enum references.** A property spec'd nullable as a
|
|
1199
|
+
> reference to a named schema — `nullable: true` alongside a `$ref` (OpenAPI
|
|
1200
|
+
> 3.0, typically via an `allOf` wrapper) or `oneOf: [$ref, {type: 'null'}]`
|
|
1201
|
+
> (OpenAPI 3.1) — now generates a nullable C# type (`Category?`), matching the
|
|
1202
|
+
> TypeScript targets' `Category | null`, regardless of whether the property is
|
|
1203
|
+
> `required`: `required` only governs presence of the key, never nullness of
|
|
1204
|
+
> the value. Previously only *optional, non-nullable* references got a `?`;
|
|
1205
|
+
> nullable references (required or not) silently generated a non-nullable
|
|
1206
|
+
> type, forcing consumers to suppress with `null!` and losing the compiler's
|
|
1207
|
+
> null-reference warnings at the point of use.
|
|
1208
|
+
>
|
|
1209
|
+
> Nullable **containers** (arrays, maps) are unaffected by this change and
|
|
1210
|
+
> still generate a non-nullable collection type.
|
|
1211
|
+
>
|
|
1212
|
+
> This applies to the `dotnet`, `dotnet-webapi` and
|
|
1213
|
+
> `dotnet-webapi-system-text-json` targets. `dotnet-system-text-json`
|
|
1214
|
+
> (`generichost`) already handled this correctly. To opt out entirely, disable
|
|
1215
|
+
> nullable reference types via `generatorCustomArgs`:
|
|
1216
|
+
> `--additional-properties=nullableReferenceTypes=false`.
|
|
1217
|
+
|
|
1198
1218
|
#### `dotnet-system-text-json`
|
|
1199
1219
|
|
|
1200
1220
|
An AOT-oriented C# **client library**. Unlike `dotnet` (which uses the
|
package/package.json
CHANGED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
{{>partial_header}}
|
|
2
|
+
using System;
|
|
3
|
+
using System.Linq;
|
|
4
|
+
using System.Text;
|
|
5
|
+
using System.Collections.Generic;
|
|
6
|
+
using System.ComponentModel;
|
|
7
|
+
using System.ComponentModel.DataAnnotations;
|
|
8
|
+
using System.Runtime.Serialization;
|
|
9
|
+
using Newtonsoft.Json;
|
|
10
|
+
using {{packageName}}.Converters;
|
|
11
|
+
{{#models}}
|
|
12
|
+
{{#model}}
|
|
13
|
+
{{/model}}
|
|
14
|
+
{{/models}}
|
|
15
|
+
|
|
16
|
+
{{#models}}
|
|
17
|
+
{{#model}}
|
|
18
|
+
namespace {{modelPackage}}
|
|
19
|
+
{ {{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}
|
|
20
|
+
/// <summary>
|
|
21
|
+
/// {{description}}
|
|
22
|
+
/// </summary>
|
|
23
|
+
[DataContract]
|
|
24
|
+
public {{#modelClassModifier}}{{.}} {{/modelClassModifier}}class {{classname}} : {{#parent}}{{{.}}}, {{/parent}}IEquatable<{{classname}}>
|
|
25
|
+
{
|
|
26
|
+
{{#vars}}
|
|
27
|
+
{{#items.isEnum}}
|
|
28
|
+
{{#items}}
|
|
29
|
+
{{^complexType}}
|
|
30
|
+
{{>enumClass}}
|
|
31
|
+
{{/complexType}}
|
|
32
|
+
{{/items}}
|
|
33
|
+
{{/items.isEnum}}
|
|
34
|
+
{{^items.isEnum}}
|
|
35
|
+
{{#isEnum}}
|
|
36
|
+
{{^complexType}}
|
|
37
|
+
{{>enumClass}}
|
|
38
|
+
{{/complexType}}
|
|
39
|
+
{{/isEnum}}
|
|
40
|
+
{{/items.isEnum}}
|
|
41
|
+
/// <summary>
|
|
42
|
+
/// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
|
43
|
+
/// </summary>{{#description}}
|
|
44
|
+
/// <value>{{.}}</value>{{/description}}{{#required}}
|
|
45
|
+
[Required]{{/required}}{{#pattern}}
|
|
46
|
+
[RegularExpression("{{{.}}}")]{{/pattern}}{{#minLength}}{{#maxLength}}
|
|
47
|
+
[StringLength({{maxLength}}, MinimumLength={{minLength}})]{{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}}
|
|
48
|
+
[MinLength({{minLength}})]{{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}}
|
|
49
|
+
[MaxLength({{.}})]{{/maxLength}}{{/minLength}}{{#minimum}}{{#maximum}}
|
|
50
|
+
[Range({{minimum}}, {{maximum}})]{{/maximum}}{{/minimum}}
|
|
51
|
+
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}})]
|
|
52
|
+
{{#isEnum}}
|
|
53
|
+
public {{{datatypeWithEnum}}}{{#isNullable}}?{{/isNullable}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
|
54
|
+
{{/isEnum}}
|
|
55
|
+
{{^isEnum}}
|
|
56
|
+
{{! this generator never appends a question mark to dataType for a nullable object/model
|
|
57
|
+
ref (only for primitives in its hardcoded nullable-type list), so the isModel-guarded
|
|
58
|
+
branch below adds it back. isModel is never set for a primitive, so this cannot
|
|
59
|
+
produce a double question mark. Nullable containers are intentionally left non-null
|
|
60
|
+
(out of scope), matching the other .NET targets in this repo. }}
|
|
61
|
+
public {{{dataType}}}{{#nullableReferenceTypes}}{{#isNullable}}{{#isModel}}?{{/isModel}}{{/isNullable}}{{/nullableReferenceTypes}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
|
62
|
+
{{/isEnum}}
|
|
63
|
+
{{^-last}}
|
|
64
|
+
|
|
65
|
+
{{/-last}}
|
|
66
|
+
{{/vars}}
|
|
67
|
+
|
|
68
|
+
/// <summary>
|
|
69
|
+
/// Returns the string presentation of the object
|
|
70
|
+
/// </summary>
|
|
71
|
+
/// <returns>String presentation of the object</returns>
|
|
72
|
+
public override string ToString()
|
|
73
|
+
{
|
|
74
|
+
var sb = new StringBuilder();
|
|
75
|
+
sb.Append("class {{classname}} {\n");
|
|
76
|
+
{{#vars}}
|
|
77
|
+
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
|
78
|
+
{{/vars}}
|
|
79
|
+
sb.Append("}\n");
|
|
80
|
+
return sb.ToString();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// <summary>
|
|
84
|
+
/// Returns the JSON string presentation of the object
|
|
85
|
+
/// </summary>
|
|
86
|
+
/// <returns>JSON string presentation of the object</returns>
|
|
87
|
+
public {{#parent}}{{^isMap}}{{^isArray}}new {{/isArray}}{{/isMap}}{{/parent}}string ToJson()
|
|
88
|
+
{
|
|
89
|
+
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// <summary>
|
|
93
|
+
/// Returns true if objects are equal
|
|
94
|
+
/// </summary>
|
|
95
|
+
/// <param name="obj">Object to be compared</param>
|
|
96
|
+
/// <returns>Boolean</returns>
|
|
97
|
+
public override bool Equals(object obj)
|
|
98
|
+
{
|
|
99
|
+
if (obj is null) return false;
|
|
100
|
+
if (ReferenceEquals(this, obj)) return true;
|
|
101
|
+
return obj.GetType() == GetType() && Equals(({{classname}})obj);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/// <summary>
|
|
105
|
+
/// Returns true if {{classname}} instances are equal
|
|
106
|
+
/// </summary>
|
|
107
|
+
/// <param name="other">Instance of {{classname}} to be compared</param>
|
|
108
|
+
/// <returns>Boolean</returns>
|
|
109
|
+
public bool Equals({{classname}} other)
|
|
110
|
+
{
|
|
111
|
+
if (other is null) return false;
|
|
112
|
+
if (ReferenceEquals(this, other)) return true;
|
|
113
|
+
|
|
114
|
+
return {{#vars}}{{^isContainer}}
|
|
115
|
+
(
|
|
116
|
+
{{name}} == other.{{name}} ||
|
|
117
|
+
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&{{/vendorExtensions.x-is-value-type}}
|
|
118
|
+
{{name}}.Equals(other.{{name}})
|
|
119
|
+
){{^-last}} && {{/-last}}{{/isContainer}}{{#isContainer}}
|
|
120
|
+
(
|
|
121
|
+
{{name}} == other.{{name}} ||
|
|
122
|
+
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&
|
|
123
|
+
other.{{name}} != null &&
|
|
124
|
+
{{/vendorExtensions.x-is-value-type}}{{name}}.SequenceEqual(other.{{name}})
|
|
125
|
+
){{^-last}} && {{/-last}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// <summary>
|
|
129
|
+
/// Gets the hash code
|
|
130
|
+
/// </summary>
|
|
131
|
+
/// <returns>Hash code</returns>
|
|
132
|
+
public override int GetHashCode()
|
|
133
|
+
{
|
|
134
|
+
unchecked // Overflow is fine, just wrap
|
|
135
|
+
{
|
|
136
|
+
var hashCode = 41;
|
|
137
|
+
// Suitable nullity checks etc, of course :)
|
|
138
|
+
{{#vars}}
|
|
139
|
+
{{^vendorExtensions.x-is-value-type}}if ({{name}} != null){{/vendorExtensions.x-is-value-type}}
|
|
140
|
+
hashCode = hashCode * 59 + {{name}}.GetHashCode();
|
|
141
|
+
{{/vars}}
|
|
142
|
+
return hashCode;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#region Operators
|
|
147
|
+
#pragma warning disable 1591
|
|
148
|
+
|
|
149
|
+
public static bool operator ==({{classname}} left, {{classname}} right)
|
|
150
|
+
{
|
|
151
|
+
return Equals(left, right);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public static bool operator !=({{classname}} left, {{classname}} right)
|
|
155
|
+
{
|
|
156
|
+
return !Equals(left, right);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#pragma warning restore 1591
|
|
160
|
+
#endregion Operators
|
|
161
|
+
}
|
|
162
|
+
{{/isEnum}}
|
|
163
|
+
{{/model}}
|
|
164
|
+
{{/models}}
|
|
165
|
+
}
|
|
@@ -79,7 +79,12 @@ namespace {{modelPackage}}
|
|
|
79
79
|
public {{{datatypeWithEnum}}}{{#isNullable}}{{^required}}?{{/required}}{{/isNullable}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
|
80
80
|
{{/isEnum}}
|
|
81
81
|
{{^isEnum}}
|
|
82
|
-
|
|
82
|
+
{{! nullable object/model refs get no question mark from the generator's dataType, unlike
|
|
83
|
+
primitives whose dataType already carries one -- so the isModel-guarded branch below
|
|
84
|
+
adds it back for those. isModel is only set for refs to named schemas, never for a
|
|
85
|
+
primitive whose dataType is already nullable, so this cannot produce a double question
|
|
86
|
+
mark. Nullable containers are intentionally left non-nullable (out of scope). }}
|
|
87
|
+
public {{{dataType}}}{{#nullableReferenceTypes}}{{^isContainer}}{{^required}}{{^isNullable}}?{{/isNullable}}{{/required}}{{#isNullable}}{{#isModel}}?{{/isModel}}{{/isNullable}}{{/isContainer}}{{/nullableReferenceTypes}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
|
83
88
|
{{/isEnum}}
|
|
84
89
|
{{^-last}}
|
|
85
90
|
|
|
@@ -79,7 +79,12 @@ namespace {{modelPackage}}
|
|
|
79
79
|
public {{{datatypeWithEnum}}}{{#isNullable}}{{^required}}?{{/required}}{{/isNullable}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
|
80
80
|
{{/isEnum}}
|
|
81
81
|
{{^isEnum}}
|
|
82
|
-
|
|
82
|
+
{{! nullable object/model refs get no question mark from the generator's dataType, unlike
|
|
83
|
+
primitives whose dataType already carries one -- so the isModel-guarded branch below
|
|
84
|
+
adds it back for those. isModel is only set for refs to named schemas, never for a
|
|
85
|
+
primitive whose dataType is already nullable, so this cannot produce a double question
|
|
86
|
+
mark. Nullable containers are intentionally left non-nullable (out of scope). }}
|
|
87
|
+
public {{{dataType}}}{{#nullableReferenceTypes}}{{^isContainer}}{{^required}}{{^isNullable}}?{{/isNullable}}{{/required}}{{#isNullable}}{{#isModel}}?{{/isModel}}{{/isNullable}}{{/isContainer}}{{/nullableReferenceTypes}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
|
83
88
|
{{/isEnum}}
|
|
84
89
|
{{^-last}}
|
|
85
90
|
|