@team-supercharge/oasg 18.0.2 → 18.2.0
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 +222 -33
- package/bin/oasg +2 -0
- package/config.schema.yml +37 -0
- package/package.json +1 -1
- package/targets/dotnet/generate.sh +2 -11
- package/targets/dotnet/publish.sh +2 -17
- package/targets/dotnet/templates/Project.csproj.mustache +39 -0
- package/targets/dotnet-common.sh +48 -0
- package/targets/dotnet-system-text-json/generate.sh +6 -0
- package/targets/dotnet-system-text-json/generator-config.json +15 -0
- package/targets/dotnet-system-text-json/publish.sh +6 -0
- package/targets/dotnet-system-text-json/templates/netcore_project.mustache +85 -0
- package/targets/dotnet-webapi/generate.sh +2 -11
- package/targets/dotnet-webapi/publish.sh +2 -17
- package/targets/dotnet-webapi/templates/Project.csproj.mustache +61 -0
- package/targets/dotnet-webapi-system-text-json/README.md +241 -0
- package/targets/dotnet-webapi-system-text-json/generate.sh +33 -0
- package/targets/dotnet-webapi-system-text-json/generator-config.json +29 -0
- package/targets/dotnet-webapi-system-text-json/publish.sh +6 -0
- package/targets/dotnet-webapi-system-text-json/templates/Project.csproj.mustache +66 -0
- package/targets/dotnet-webapi-system-text-json/templates/controller.mustache +7 -0
- package/targets/dotnet-webapi-system-text-json/templates/endpointParam.mustache +1 -0
- package/targets/dotnet-webapi-system-text-json/templates/enumClass.mustache +24 -0
- package/targets/dotnet-webapi-system-text-json/templates/minimalEndpoints.mustache +120 -0
- package/targets/dotnet-webapi-system-text-json/templates/model.mustache +205 -0
- package/targets/dotnet-webapi-system-text-json/templates/paramType.mustache +1 -0
- package/targets/dotnet-webapi-system-text-json/templates/serviceCollectionExtensions.mustache +90 -0
- package/targets/dotnet-webapi-system-text-json/templates/typeConverter.mustache +11 -0
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
{{#useNewtonsoft}}
|
|
10
|
+
using Newtonsoft.Json;
|
|
11
|
+
{{/useNewtonsoft}}
|
|
12
|
+
{{^useNewtonsoft}}
|
|
13
|
+
using System.Text.Json;
|
|
14
|
+
using System.Text.Json.Serialization;
|
|
15
|
+
{{/useNewtonsoft}}
|
|
16
|
+
{{#models}}
|
|
17
|
+
{{#model}}
|
|
18
|
+
{{#discriminator}}
|
|
19
|
+
using JsonSubTypes;
|
|
20
|
+
{{#useSwashbuckle}}
|
|
21
|
+
using Swashbuckle.AspNetCore.Annotations;
|
|
22
|
+
{{/useSwashbuckle}}
|
|
23
|
+
{{/discriminator}}
|
|
24
|
+
{{/model}}
|
|
25
|
+
{{/models}}
|
|
26
|
+
|
|
27
|
+
{{#models}}
|
|
28
|
+
{{#model}}
|
|
29
|
+
namespace {{modelPackage}}
|
|
30
|
+
{ {{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}
|
|
31
|
+
/// <summary>
|
|
32
|
+
/// {{description}}
|
|
33
|
+
/// </summary>
|
|
34
|
+
[DataContract]
|
|
35
|
+
{{#discriminator}}
|
|
36
|
+
{{#useNewtonsoft}}
|
|
37
|
+
{{#mappedModels.size}}
|
|
38
|
+
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
|
|
39
|
+
{{/mappedModels.size}}
|
|
40
|
+
{{/useNewtonsoft}}
|
|
41
|
+
{{#useSwashbuckle}}
|
|
42
|
+
[SwaggerDiscriminator("{{{discriminatorName}}}")]
|
|
43
|
+
{{/useSwashbuckle}}
|
|
44
|
+
{{#mappedModels}}
|
|
45
|
+
[JsonSubtypes.KnownSubType(typeof({{{modelName}}}), "{{^vendorExtensions.x-discriminator-value}}{{{mappingName}}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{.}}}{{/vendorExtensions.x-discriminator-value}}")]
|
|
46
|
+
{{#useSwashbuckle}}
|
|
47
|
+
[SwaggerSubType(typeof({{{modelName}}}), DiscriminatorValue = "{{^vendorExtensions.x-discriminator-value}}{{{mappingName}}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{.}}}{{/vendorExtensions.x-discriminator-value}}")]
|
|
48
|
+
{{/useSwashbuckle}}
|
|
49
|
+
{{/mappedModels}}
|
|
50
|
+
{{/discriminator}}
|
|
51
|
+
public {{#modelClassModifier}}{{.}} {{/modelClassModifier}}class {{classname}} {{#parent}}: {{{.}}}{{^pocoModels}}, {{/pocoModels}}{{/parent}}{{^pocoModels}}{{^parent}}: {{/parent}}IEquatable<{{classname}}>{{/pocoModels}}
|
|
52
|
+
{
|
|
53
|
+
{{#vars}}
|
|
54
|
+
{{#items.isEnum}}
|
|
55
|
+
{{#items}}
|
|
56
|
+
{{^complexType}}
|
|
57
|
+
{{>enumClass}}
|
|
58
|
+
{{/complexType}}
|
|
59
|
+
{{/items}}
|
|
60
|
+
{{/items.isEnum}}
|
|
61
|
+
{{#isEnum}}
|
|
62
|
+
{{^complexType}}
|
|
63
|
+
{{>enumClass}}
|
|
64
|
+
{{/complexType}}
|
|
65
|
+
{{/isEnum}}
|
|
66
|
+
/// <summary>
|
|
67
|
+
/// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
|
68
|
+
/// </summary>{{#description}}
|
|
69
|
+
/// <value>{{.}}</value>{{/description}}{{#example}}
|
|
70
|
+
/* <example>{{.}}</example> */{{/example}}{{#required}}
|
|
71
|
+
[Required]{{/required}}{{#pattern}}
|
|
72
|
+
[RegularExpression("{{{.}}}")]{{/pattern}}{{#minLength}}{{#maxLength}}
|
|
73
|
+
[StringLength({{maxLength}}, MinimumLength={{minLength}})]{{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}}
|
|
74
|
+
[MinLength({{minLength}})]{{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}}
|
|
75
|
+
[MaxLength({{.}})]{{/maxLength}}{{/minLength}}{{#minimum}}{{#maximum}}
|
|
76
|
+
[Range({{minimum}}, {{maximum}})]{{/maximum}}{{/minimum}}
|
|
77
|
+
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}{{#vendorExtensions.x-is-value-type}}true{{/vendorExtensions.x-is-value-type}}{{^vendorExtensions.x-is-value-type}}false{{/vendorExtensions.x-is-value-type}}{{/isNullable}})]
|
|
78
|
+
{{#isEnum}}
|
|
79
|
+
public {{{datatypeWithEnum}}}{{#isNullable}}{{^required}}?{{/required}}{{/isNullable}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
|
80
|
+
{{/isEnum}}
|
|
81
|
+
{{^isEnum}}
|
|
82
|
+
public {{{dataType}}}{{#nullableReferenceTypes}}{{^isContainer}}{{^required}}{{^isNullable}}?{{/isNullable}}{{/required}}{{/isContainer}}{{/nullableReferenceTypes}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
|
83
|
+
{{/isEnum}}
|
|
84
|
+
{{^-last}}
|
|
85
|
+
|
|
86
|
+
{{/-last}}
|
|
87
|
+
{{/vars}}
|
|
88
|
+
|
|
89
|
+
{{^pocoModels}}
|
|
90
|
+
/// <summary>
|
|
91
|
+
/// Returns the string presentation of the object
|
|
92
|
+
/// </summary>
|
|
93
|
+
/// <returns>String presentation of the object</returns>
|
|
94
|
+
public override string ToString()
|
|
95
|
+
{
|
|
96
|
+
var sb = new StringBuilder();
|
|
97
|
+
sb.Append("class {{classname}} {\n");
|
|
98
|
+
{{#vars}}
|
|
99
|
+
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
|
100
|
+
{{/vars}}
|
|
101
|
+
sb.Append("}\n");
|
|
102
|
+
return sb.ToString();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/// <summary>
|
|
106
|
+
/// Returns the JSON string presentation of the object
|
|
107
|
+
/// </summary>
|
|
108
|
+
/// <returns>JSON string presentation of the object</returns>
|
|
109
|
+
public {{#parent}}{{^isMap}}{{^isArray}}new {{/isArray}}{{/isMap}}{{/parent}}string ToJson()
|
|
110
|
+
{
|
|
111
|
+
{{#useNewtonsoft}}
|
|
112
|
+
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
|
113
|
+
{{/useNewtonsoft}}
|
|
114
|
+
{{^useNewtonsoft}}
|
|
115
|
+
return JsonSerializer.Serialize(this, {{classname}}SerializationContext.Default.{{classname}});
|
|
116
|
+
{{/useNewtonsoft}}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// <summary>
|
|
120
|
+
/// Returns true if objects are equal
|
|
121
|
+
/// </summary>
|
|
122
|
+
/// <param name="obj">Object to be compared</param>
|
|
123
|
+
/// <returns>Boolean</returns>
|
|
124
|
+
public override bool Equals(object obj)
|
|
125
|
+
{
|
|
126
|
+
if (obj is null) return false;
|
|
127
|
+
if (ReferenceEquals(this, obj)) return true;
|
|
128
|
+
return obj.GetType() == GetType() && Equals(({{classname}})obj);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// <summary>
|
|
132
|
+
/// Returns true if {{classname}} instances are equal
|
|
133
|
+
/// </summary>
|
|
134
|
+
/// <param name="other">Instance of {{classname}} to be compared</param>
|
|
135
|
+
/// <returns>Boolean</returns>
|
|
136
|
+
public bool Equals({{classname}} other)
|
|
137
|
+
{
|
|
138
|
+
if (other is null) return false;
|
|
139
|
+
if (ReferenceEquals(this, other)) return true;
|
|
140
|
+
|
|
141
|
+
return {{#vars}}{{^isContainer}}
|
|
142
|
+
(
|
|
143
|
+
{{name}} == other.{{name}} ||
|
|
144
|
+
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&{{/vendorExtensions.x-is-value-type}}
|
|
145
|
+
{{name}}.Equals(other.{{name}})
|
|
146
|
+
){{^-last}} && {{/-last}}{{/isContainer}}{{#isContainer}}
|
|
147
|
+
(
|
|
148
|
+
{{name}} == other.{{name}} ||
|
|
149
|
+
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&
|
|
150
|
+
other.{{name}} != null &&
|
|
151
|
+
{{/vendorExtensions.x-is-value-type}}{{name}}.SequenceEqual(other.{{name}})
|
|
152
|
+
){{^-last}} && {{/-last}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/// <summary>
|
|
156
|
+
/// Gets the hash code
|
|
157
|
+
/// </summary>
|
|
158
|
+
/// <returns>Hash code</returns>
|
|
159
|
+
public override int GetHashCode()
|
|
160
|
+
{
|
|
161
|
+
unchecked // Overflow is fine, just wrap
|
|
162
|
+
{
|
|
163
|
+
var hashCode = 41;
|
|
164
|
+
// Suitable nullity checks etc, of course :)
|
|
165
|
+
{{#vars}}
|
|
166
|
+
{{^vendorExtensions.x-is-value-type}}if ({{name}} != null){{/vendorExtensions.x-is-value-type}}
|
|
167
|
+
hashCode = hashCode * 59 + {{name}}.GetHashCode();
|
|
168
|
+
{{/vars}}
|
|
169
|
+
return hashCode;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
#region Operators
|
|
174
|
+
#pragma warning disable 1591
|
|
175
|
+
|
|
176
|
+
public static bool operator ==({{classname}} left, {{classname}} right)
|
|
177
|
+
{
|
|
178
|
+
return Equals(left, right);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
public static bool operator !=({{classname}} left, {{classname}} right)
|
|
182
|
+
{
|
|
183
|
+
return !Equals(left, right);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#pragma warning restore 1591
|
|
187
|
+
#endregion Operators
|
|
188
|
+
{{/pocoModels}}
|
|
189
|
+
}
|
|
190
|
+
{{^useNewtonsoft}}
|
|
191
|
+
|
|
192
|
+
/// <summary>
|
|
193
|
+
/// System.Text.Json source-generation context for <see cref="{{classname}}" />.
|
|
194
|
+
/// Used by ToJson() so (de)serialization is trim- and AOT-safe.
|
|
195
|
+
/// </summary>
|
|
196
|
+
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
197
|
+
[JsonSerializable(typeof({{classname}}))]
|
|
198
|
+
internal partial class {{classname}}SerializationContext : JsonSerializerContext
|
|
199
|
+
{
|
|
200
|
+
}
|
|
201
|
+
{{/useNewtonsoft}}
|
|
202
|
+
{{/isEnum}}
|
|
203
|
+
{{/model}}
|
|
204
|
+
{{/models}}
|
|
205
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{#isQueryParam}}{{#isArray}}string[]{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isQueryParam}}{{^isQueryParam}}{{{dataType}}}{{/isQueryParam}}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// <auto-generated/>
|
|
2
|
+
#nullable enable
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using System.Text.Json.Serialization;
|
|
6
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
7
|
+
using {{packageName}}.Models;
|
|
8
|
+
|
|
9
|
+
namespace {{packageName}}
|
|
10
|
+
{
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// System.Text.Json source-generation context covering every type this package
|
|
13
|
+
/// (de)serializes through its minimal-API endpoints: each generated model, each
|
|
14
|
+
/// operation request/response type, and each inline enum. Registering it (see
|
|
15
|
+
/// <see cref="{{#lambda.pascalcase}}{{packageName}}{{/lambda.pascalcase}}ServiceCollectionExtensions" />)
|
|
16
|
+
/// lets the endpoints resolve JSON metadata via source generation, which is what
|
|
17
|
+
/// makes the package safe to trim and to publish with Native AOT — the pipeline
|
|
18
|
+
/// never falls back to reflection.
|
|
19
|
+
/// </summary>
|
|
20
|
+
/// <remarks>
|
|
21
|
+
/// Duplicate <c>[JsonSerializable]</c> entries are coalesced by the generator, so
|
|
22
|
+
/// request/response types that are also models are harmless. Inline enums are
|
|
23
|
+
/// registered with an explicit <c>TypeInfoPropertyName</c> because two models can
|
|
24
|
+
/// declare equally-named nested enums (e.g. <c>Order.StatusEnum</c> and
|
|
25
|
+
/// <c>Pet.StatusEnum</c>), which would otherwise collide under SYSLIB1031.
|
|
26
|
+
/// </remarks>
|
|
27
|
+
[JsonSerializable(typeof(string))]
|
|
28
|
+
{{#models}}
|
|
29
|
+
{{#model}}
|
|
30
|
+
[JsonSerializable(typeof({{classname}}))]
|
|
31
|
+
{{#vars}}
|
|
32
|
+
{{#isEnum}}
|
|
33
|
+
{{^complexType}}
|
|
34
|
+
[JsonSerializable(typeof({{classname}}.{{datatypeWithEnum}}), TypeInfoPropertyName = "{{classname}}{{datatypeWithEnum}}")]
|
|
35
|
+
{{/complexType}}
|
|
36
|
+
{{/isEnum}}
|
|
37
|
+
{{#items.isEnum}}
|
|
38
|
+
{{#items}}
|
|
39
|
+
{{^complexType}}
|
|
40
|
+
[JsonSerializable(typeof({{classname}}.{{datatypeWithEnum}}), TypeInfoPropertyName = "{{classname}}{{datatypeWithEnum}}")]
|
|
41
|
+
{{/complexType}}
|
|
42
|
+
{{/items}}
|
|
43
|
+
{{/items.isEnum}}
|
|
44
|
+
{{/vars}}
|
|
45
|
+
{{/model}}
|
|
46
|
+
{{/models}}
|
|
47
|
+
{{#apiInfo}}
|
|
48
|
+
{{#apis}}
|
|
49
|
+
{{#operations}}
|
|
50
|
+
{{#operation}}
|
|
51
|
+
{{^isResponseFile}}
|
|
52
|
+
{{#returnType}}
|
|
53
|
+
[JsonSerializable(typeof({{{returnType}}}))]
|
|
54
|
+
{{/returnType}}
|
|
55
|
+
{{/isResponseFile}}
|
|
56
|
+
{{#bodyParam}}
|
|
57
|
+
{{^isBinary}}
|
|
58
|
+
[JsonSerializable(typeof({{#isArray}}List<{{{items.dataType}}}>{{/isArray}}{{^isArray}}{{{baseType}}}{{/isArray}}))]
|
|
59
|
+
{{/isBinary}}
|
|
60
|
+
{{/bodyParam}}
|
|
61
|
+
{{/operation}}
|
|
62
|
+
{{/operations}}
|
|
63
|
+
{{/apis}}
|
|
64
|
+
{{/apiInfo}}
|
|
65
|
+
public partial class {{#lambda.pascalcase}}{{packageName}}{{/lambda.pascalcase}}JsonSerializerContext : JsonSerializerContext
|
|
66
|
+
{
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// <summary>
|
|
70
|
+
/// Registers the System.Text.Json source-generation context for this generated
|
|
71
|
+
/// package. Call <c>builder.Services.Add{{#lambda.pascalcase}}{{packageName}}{{/lambda.pascalcase}}JsonOptions()</c>
|
|
72
|
+
/// in Program.cs so the minimal-API endpoints resolve JSON metadata via source
|
|
73
|
+
/// generation — required when the host is published with Native AOT, harmless
|
|
74
|
+
/// (a no-op the reflection resolver already covers) for a JIT host.
|
|
75
|
+
/// </summary>
|
|
76
|
+
public static class {{#lambda.pascalcase}}{{packageName}}{{/lambda.pascalcase}}ServiceCollectionExtensions
|
|
77
|
+
{
|
|
78
|
+
/// <summary>
|
|
79
|
+
/// Inserts <see cref="{{#lambda.pascalcase}}{{packageName}}{{/lambda.pascalcase}}JsonSerializerContext" />
|
|
80
|
+
/// at the front of the minimal-API JSON type-info resolver chain.
|
|
81
|
+
/// </summary>
|
|
82
|
+
public static IServiceCollection Add{{#lambda.pascalcase}}{{packageName}}{{/lambda.pascalcase}}JsonOptions(this IServiceCollection services)
|
|
83
|
+
{
|
|
84
|
+
services.ConfigureHttpJsonOptions(options =>
|
|
85
|
+
options.SerializerOptions.TypeInfoResolverChain.Insert(
|
|
86
|
+
0, {{#lambda.pascalcase}}{{packageName}}{{/lambda.pascalcase}}JsonSerializerContext.Default));
|
|
87
|
+
return services;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// <auto-generated/>
|
|
2
|
+
//
|
|
3
|
+
// Intentionally empty for the System.Text.Json / Native-AOT target.
|
|
4
|
+
//
|
|
5
|
+
// The default aspnetcore template emits an MVC `CustomEnumConverter<T>`
|
|
6
|
+
// (a TypeConverter whose body calls the reflection-based
|
|
7
|
+
// JsonSerializer.Deserialize<T>, which raises IL2026/IL3050 under the AOT
|
|
8
|
+
// analyzer). This target suppresses MVC controllers and (de)serializes enums
|
|
9
|
+
// via [JsonConverter(typeof(JsonStringEnumConverter<T>))] + [JsonStringEnumMemberName]
|
|
10
|
+
// on each generated enum, so the converter is unused — and is omitted here to
|
|
11
|
+
// keep the package AOT-clean.
|