Skip to content

Commit ba85c69

Browse files
committed
avoid generating json serialize attributes for query string parameters
1 parent 5911a04 commit ba85c69

4 files changed

Lines changed: 12 additions & 53 deletions

File tree

src/Docker.DotNet/JsonSerializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ private static bool TryParseJson(ref ReadOnlySequence<byte> buffer, out JsonDocu
105105
}
106106

107107
// extended types that are not generated by source generator
108-
[JsonSerializable(typeof(Dictionary<string, string>[]))]
108+
[JsonSerializable(typeof(IDictionary<string, string>[]))]
109+
[JsonSerializable(typeof(IDictionary<string, IDictionary<string, bool>>))]
109110
[JsonSerializable(typeof(ImagesListResponse[]))]
110111
[JsonSerializable(typeof(ContainerListResponse[]))]
111112
[JsonSerializable(typeof(SwarmService[]))]

src/Docker.DotNet/Models/DockerModelsJsonSerializerContext.Generated.cs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,32 @@ namespace Docker.DotNet.Models
1414
[JsonSerializable(typeof(CPUUsage))]
1515
[JsonSerializable(typeof(CapacityRange))]
1616
[JsonSerializable(typeof(ClusterInfo))]
17-
[JsonSerializable(typeof(ClusterOptions))]
1817
[JsonSerializable(typeof(ClusterVolume))]
1918
[JsonSerializable(typeof(ClusterVolumeSpec))]
2019
[JsonSerializable(typeof(Commit))]
21-
[JsonSerializable(typeof(CommitContainerChangesParameters))]
2220
[JsonSerializable(typeof(CommitContainerChangesResponse))]
2321
[JsonSerializable(typeof(ComponentVersion))]
2422
[JsonSerializable(typeof(ConfigReference))]
2523
[JsonSerializable(typeof(ConfigReferenceFileTarget))]
26-
[JsonSerializable(typeof(ConfigReferenceRuntimeTarget))]
2724
[JsonSerializable(typeof(ConsoleSize))]
28-
[JsonSerializable(typeof(ContainerAttachParameters))]
2925
[JsonSerializable(typeof(ContainerConfig))]
30-
[JsonSerializable(typeof(ContainerEventsParameters))]
3126
[JsonSerializable(typeof(ContainerExecCreateParameters))]
3227
[JsonSerializable(typeof(ContainerExecCreateResponse))]
3328
[JsonSerializable(typeof(ContainerExecInspectResponse))]
3429
[JsonSerializable(typeof(ContainerExecStartParameters))]
3530
[JsonSerializable(typeof(ContainerFileSystemChangeResponse))]
36-
[JsonSerializable(typeof(ContainerInspectParameters))]
3731
[JsonSerializable(typeof(ContainerInspectResponse))]
38-
[JsonSerializable(typeof(ContainerKillParameters))]
39-
[JsonSerializable(typeof(ContainerListProcessesParameters))]
4032
[JsonSerializable(typeof(ContainerListResponse))]
41-
[JsonSerializable(typeof(ContainerLogsParameters))]
42-
[JsonSerializable(typeof(ContainerPathStatParameters))]
4333
[JsonSerializable(typeof(ContainerPathStatResponse))]
4434
[JsonSerializable(typeof(ContainerProcessesResponse))]
45-
[JsonSerializable(typeof(ContainerRemoveParameters))]
46-
[JsonSerializable(typeof(ContainerRenameParameters))]
47-
[JsonSerializable(typeof(ContainerResizeParameters))]
48-
[JsonSerializable(typeof(ContainerRestartParameters))]
4935
[JsonSerializable(typeof(ContainerSpec))]
50-
[JsonSerializable(typeof(ContainerStartParameters))]
51-
[JsonSerializable(typeof(ContainerStatsParameters))]
5236
[JsonSerializable(typeof(ContainerStatsResponse))]
5337
[JsonSerializable(typeof(ContainerStatus))]
54-
[JsonSerializable(typeof(ContainerStopParameters))]
55-
[JsonSerializable(typeof(ContainerUpdateParameters))]
5638
[JsonSerializable(typeof(ContainerUpdateResponse))]
5739
[JsonSerializable(typeof(ContainerWaitResponse))]
5840
[JsonSerializable(typeof(ContainerdInfo))]
5941
[JsonSerializable(typeof(ContainerdNamespaces))]
60-
[JsonSerializable(typeof(ContainersListParameters))]
61-
[JsonSerializable(typeof(ContainersPruneParameters))]
6242
[JsonSerializable(typeof(ContainersPruneResponse))]
63-
[JsonSerializable(typeof(CopyToContainerParameters))]
6443
[JsonSerializable(typeof(CreateContainerParameters))]
6544
[JsonSerializable(typeof(CreateContainerResponse))]
6645
[JsonSerializable(typeof(CredentialSpec))]
@@ -71,7 +50,6 @@ namespace Docker.DotNet.Models
7150
[JsonSerializable(typeof(DeviceRequest))]
7251
[JsonSerializable(typeof(DiscreteGenericResource))]
7352
[JsonSerializable(typeof(DispatcherConfig))]
74-
[JsonSerializable(typeof(DockerOCIImageConfig))]
7553
[JsonSerializable(typeof(DockerOCIImageConfigExt))]
7654
[JsonSerializable(typeof(Driver))]
7755
[JsonSerializable(typeof(DriverData))]
@@ -87,8 +65,6 @@ namespace Docker.DotNet.Models
8765
[JsonSerializable(typeof(ExternalCA))]
8866
[JsonSerializable(typeof(FirewallInfo))]
8967
[JsonSerializable(typeof(GenericResource))]
90-
[JsonSerializable(typeof(GlobalJob))]
91-
[JsonSerializable(typeof(GlobalService))]
9268
[JsonSerializable(typeof(Health))]
9369
[JsonSerializable(typeof(HealthSummary))]
9470
[JsonSerializable(typeof(HealthcheckConfig))]
@@ -101,24 +77,17 @@ namespace Docker.DotNet.Models
10177
[JsonSerializable(typeof(ImageBuildParameters))]
10278
[JsonSerializable(typeof(ImageBuildResult))]
10379
[JsonSerializable(typeof(ImageConfig))]
104-
[JsonSerializable(typeof(ImageDeleteParameters))]
10580
[JsonSerializable(typeof(ImageDeleteResponse))]
10681
[JsonSerializable(typeof(ImageHistoryResponse))]
10782
[JsonSerializable(typeof(ImageInspectResponse))]
108-
[JsonSerializable(typeof(ImageLoadParameters))]
10983
[JsonSerializable(typeof(ImageOptions))]
11084
[JsonSerializable(typeof(ImageProperties))]
11185
[JsonSerializable(typeof(ImagePropertiesSize))]
11286
[JsonSerializable(typeof(ImagePushParameters))]
11387
[JsonSerializable(typeof(ImageSearchResponse))]
114-
[JsonSerializable(typeof(ImageTagParameters))]
11588
[JsonSerializable(typeof(ImagesCreateParameters))]
116-
[JsonSerializable(typeof(ImagesListParameters))]
11789
[JsonSerializable(typeof(ImagesListResponse))]
118-
[JsonSerializable(typeof(ImagesLoadResponse))]
119-
[JsonSerializable(typeof(ImagesPruneParameters))]
12090
[JsonSerializable(typeof(ImagesPruneResponse))]
121-
[JsonSerializable(typeof(ImagesSearchParameters))]
12291
[JsonSerializable(typeof(IndexInfo))]
12392
[JsonSerializable(typeof(Info))]
12493
[JsonSerializable(typeof(JSONError))]
@@ -153,13 +122,10 @@ namespace Docker.DotNet.Models
153122
[JsonSerializable(typeof(NetworkingConfig))]
154123
[JsonSerializable(typeof(NetworksCreateParameters))]
155124
[JsonSerializable(typeof(NetworksCreateResponse))]
156-
[JsonSerializable(typeof(NetworksDeleteUnusedParameters))]
157-
[JsonSerializable(typeof(NetworksListParameters))]
158125
[JsonSerializable(typeof(NetworksPruneResponse))]
159126
[JsonSerializable(typeof(NodeCSIInfo))]
160127
[JsonSerializable(typeof(NodeDescription))]
161128
[JsonSerializable(typeof(NodeListResponse))]
162-
[JsonSerializable(typeof(NodeRemoveParameters))]
163129
[JsonSerializable(typeof(NodeStatus))]
164130
[JsonSerializable(typeof(NodeUpdateParameters))]
165131
[JsonSerializable(typeof(OrchestrationConfig))]
@@ -175,21 +141,15 @@ namespace Docker.DotNet.Models
175141
[JsonSerializable(typeof(PluginCapabilityID))]
176142
[JsonSerializable(typeof(PluginConfig))]
177143
[JsonSerializable(typeof(PluginConfigureParameters))]
178-
[JsonSerializable(typeof(PluginCreateParameters))]
179144
[JsonSerializable(typeof(PluginDescription))]
180145
[JsonSerializable(typeof(PluginDevice))]
181-
[JsonSerializable(typeof(PluginDisableParameters))]
182-
[JsonSerializable(typeof(PluginEnableParameters))]
183146
[JsonSerializable(typeof(PluginEnv))]
184-
[JsonSerializable(typeof(PluginGetPrivilegeParameters))]
185147
[JsonSerializable(typeof(PluginInstallParameters))]
186148
[JsonSerializable(typeof(PluginInterface))]
187149
[JsonSerializable(typeof(PluginLinuxConfig))]
188-
[JsonSerializable(typeof(PluginListParameters))]
189150
[JsonSerializable(typeof(PluginMount))]
190151
[JsonSerializable(typeof(PluginNetworkConfig))]
191152
[JsonSerializable(typeof(PluginPrivilege))]
192-
[JsonSerializable(typeof(PluginRemoveParameters))]
193153
[JsonSerializable(typeof(PluginRootFS))]
194154
[JsonSerializable(typeof(PluginSettings))]
195155
[JsonSerializable(typeof(PluginUpgradeParameters))]
@@ -223,8 +183,6 @@ namespace Docker.DotNet.Models
223183
[JsonSerializable(typeof(ServiceCreateParameters))]
224184
[JsonSerializable(typeof(ServiceCreateResponse))]
225185
[JsonSerializable(typeof(ServiceInfo))]
226-
[JsonSerializable(typeof(ServiceListParameters))]
227-
[JsonSerializable(typeof(ServiceLogsParameters))]
228186
[JsonSerializable(typeof(ServiceMode))]
229187
[JsonSerializable(typeof(ServiceSpec))]
230188
[JsonSerializable(typeof(ServiceStatus))]
@@ -248,7 +206,6 @@ namespace Docker.DotNet.Models
248206
[JsonSerializable(typeof(SwarmInitParameters))]
249207
[JsonSerializable(typeof(SwarmInspectResponse))]
250208
[JsonSerializable(typeof(SwarmJoinParameters))]
251-
[JsonSerializable(typeof(SwarmLeaveParameters))]
252209
[JsonSerializable(typeof(SwarmLimit))]
253210
[JsonSerializable(typeof(SwarmNetwork))]
254211
[JsonSerializable(typeof(SwarmPlatform))]
@@ -268,13 +225,11 @@ namespace Docker.DotNet.Models
268225
[JsonSerializable(typeof(TaskResponse))]
269226
[JsonSerializable(typeof(TaskSpec))]
270227
[JsonSerializable(typeof(TaskStatus))]
271-
[JsonSerializable(typeof(TasksListParameters))]
272228
[JsonSerializable(typeof(ThrottleDevice))]
273229
[JsonSerializable(typeof(ThrottlingData))]
274230
[JsonSerializable(typeof(TmpfsOptions))]
275231
[JsonSerializable(typeof(Topology))]
276232
[JsonSerializable(typeof(TopologyRequirement))]
277-
[JsonSerializable(typeof(TypeBlock))]
278233
[JsonSerializable(typeof(TypeMount))]
279234
[JsonSerializable(typeof(Ulimit))]
280235
[JsonSerializable(typeof(UpdateConfig))]
@@ -290,9 +245,7 @@ namespace Docker.DotNet.Models
290245
[JsonSerializable(typeof(VolumeSecret))]
291246
[JsonSerializable(typeof(VolumeTopology))]
292247
[JsonSerializable(typeof(VolumesCreateParameters))]
293-
[JsonSerializable(typeof(VolumesListParameters))]
294248
[JsonSerializable(typeof(VolumesListResponse))]
295-
[JsonSerializable(typeof(VolumesPruneParameters))]
296249
[JsonSerializable(typeof(VolumesPruneResponse))]
297250
[JsonSerializable(typeof(WaitExitError))]
298251
[JsonSerializable(typeof(WeightDevice))]

tools/specgen/csharptype.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ type CSModelType struct {
190190
// yet. it is possible that given the recursive nature that it not be
191191
// completed but as long as this is true we will not attempt to generate the
192192
// type more than once.
193-
IsStarted bool
193+
IsStarted bool
194+
HasJsonSerializableProperties bool
194195
}
195196

196197
// NewModel creates a new model type with valid slices

tools/specgen/specgen.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ func reflectTypeMembers(t reflect.Type, m *CSModelType) {
771771
a.Arguments = append(a.Arguments, CSArgument{jsonName, CSInboxTypesMap[reflect.String]})
772772
csProp.IsOpt = omitEmpty || f.Type.Kind() == reflect.Ptr
773773
csProp.Attributes = append(csProp.Attributes, a)
774+
775+
m.HasJsonSerializableProperties = true
774776
}
775777

776778
if hasTypeCustomizations {
@@ -857,7 +859,7 @@ func main() {
857859
reflectType(t)
858860
}
859861

860-
names := make([]string, 0, len(reflectedTypes))
862+
jsonSerializableNames := make([]string, 0, len(reflectedTypes))
861863

862864
for k, v := range reflectedTypes {
863865
if _, e := os.Stat(path.Join(sourcePath, v.Name+".Generated.cs")); e == nil {
@@ -882,10 +884,12 @@ func main() {
882884
f.Close()
883885
os.Rename(f.Name(), path.Join(sourcePath, v.Name+".Generated.cs"))
884886

885-
names = append(names, v.Name)
887+
if v.HasJsonSerializableProperties {
888+
jsonSerializableNames = append(jsonSerializableNames, v.Name)
889+
}
886890
}
887891

888-
slices.Sort(names)
892+
slices.Sort(jsonSerializableNames)
889893

890894
jscf, err := os.Create(path.Join(sourcePath, "DockerModelsJsonSerializerContext.Generated.cs"))
891895
if err != nil {
@@ -898,7 +902,7 @@ func main() {
898902

899903
fmt.Fprintln(jscb, "namespace Docker.DotNet.Models")
900904
fmt.Fprintln(jscb, "{")
901-
for _, name := range names {
905+
for _, name := range jsonSerializableNames {
902906
fmt.Fprintf(jscb, " [JsonSerializable(typeof(%s))]\n", name)
903907
}
904908
fmt.Fprintln(jscb, " internal sealed partial class DockerModelsJsonSerializerContext : JsonSerializerContext { }")

0 commit comments

Comments
 (0)