Skip to content

Commit 50c321a

Browse files
authored
docs: Update the specgen README.md file (#45)
1 parent a4ac675 commit 50c321a

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

tools/specgen/README.md

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SpecGen
22

3-
A tool that reflects the Docker client [engine-api](https://github.com/docker/engine-api) in order to generate C# classes that match its model for [Docker.DotNet Models](/src/Docker.DotNet/Models).
3+
A tool that reflects the Docker client [engine-api](https://github.com/docker/engine-api) in order to generate C# classes that match its model for [Docker.DotNet Models](../../src/Docker.DotNet/Models).
44

55
----
66

@@ -14,25 +14,19 @@ To update the source repositories please use the following from your `$GOPATH`:
1414

1515
Note: Since the docker library is not a go module the version go generates will look something like this v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible even though this is for v19.03.13. The commit hash bd33bbf0497b matches the commit hash of docker v 19.03.13
1616

17-
Once you have the latest engine-api. Calling:
18-
19-
```
20-
> update-generated-code.cmd
21-
```
22-
23-
Should result in changes to the Docker.DotNet/Models directory if any exist.
17+
Once you have the latest engine-api, call `update-generated-code.cmd` or `./update-generated-code.sh` (depending on your Operating System) to update the models in the [Docker.DotNet/Models](../../src/Docker.DotNet/Models) directory.
2418

2519
----
2620

2721
## About the structure of the tool:
2822

2923
Many of Docker's engine-api types are used for both the query string and json body. Because there is no way to attribute this on the engine-api types themselves we have broken the tool into a few specific areas:
3024

31-
`Csharptype.go`: Contains the translation/serialization code for writing the C# classes.
25+
`Csharptype.go` : Contains the translation/serialization code for writing the C# classes.
3226

3327
`Modeldefs.go` : Contains the parts of engine-api that are used as parameters or require custom serialization that needs to be explicitly handled differently.
3428

35-
`Specgen.go` : Contains the majority of the code that reflects the engine-api structs and converts them to the C# in-memory abstractions.
29+
`Specgen.go` : Contains the majority of the code that reflects the engine-api structs and converts them to the C# in-memory abstractions.
3630

3731
----
3832

@@ -41,63 +35,55 @@ Many of Docker's engine-api types are used for both the query string and json bo
4135
The resulting C# type contains both the `QueryString` parameters as well as the `JSON` body models in one object. This simplifies the calling API quite dramatically. For example:
4236

4337
```C#
44-
using System.Runtime.Serialization;
45-
4638
namespace Docker.DotNet.Models
4739
{
48-
[DataContract]
4940
public class ContainerAttachParameters // (main.ContainerAttachParameters)
5041
{
5142
[QueryStringParameter("stream", false, typeof(BoolQueryStringConverter))]
5243
public bool? Stream { get; set; }
5344

5445
[QueryStringParameter("stdin", false, typeof(BoolQueryStringConverter))]
5546
public bool? Stdin { get; set; }
47+
48+
// etc...
5649
}
5750
}
5851
```
5952

6053
What you are seeing here is that in order to interact with the remote API the query string allows `optional` `stream` and `stdin` boolean parameters. Because they are optional the generated code adds the `?` to signify the absence of the value versus passing a `false` as the value.
6154

6255
```C#
63-
using System.Collections.Generic;
64-
using System.Runtime.Serialization;
65-
6656
namespace Docker.DotNet.Models
6757
{
68-
[DataContract]
69-
public class Config // (container.Config)
58+
public class ContainerConfig // (container.Config)
7059
{
71-
[DataMember(Name = "Hostname", EmitDefaultValue = false)]
60+
[JsonPropertyName("Hostname")]
7261
public string Hostname { get; set; }
7362

74-
[DataMember(Name = "Domainname", EmitDefaultValue = false)]
63+
[JsonPropertyName("Domainname")]
7564
public string Domainname { get; set; }
7665

7766
// etc...
7867
}
7968
}
8069
```
8170

82-
Here you are actually seeing that the field values are marshalled in the request body based on the `DataMember` attribute. The resulting `JSON` will not contain the field if its value is equal to its default value in C#.
71+
Here you are actually seeing that the field values are marshalled in the request body based on the `JsonPropertyName` attribute. The resulting `JSON` will not contain the field if its value is equal to its default value in C#.
8372

84-
A few customizations are taken in order to simplify the API even more. Take for example [RestartPolicyKind.cs](https://github.com/ahmetalpbalkan/Docker.DotNet/blob/master/Docker.DotNet/Models/RestartPolicyKind.cs). You will see the generated model contains:
73+
A few customizations are taken in order to simplify the API even more. Take for example [RestartPolicyKind.cs](../../src/Docker.DotNet/Models/RestartPolicyKind.cs). You will see the generated model contains:
8574

8675
```C#
87-
using System.Runtime.Serialization;
88-
8976
namespace Docker.DotNet.Models
9077
{
91-
[DataContract]
9278
public class RestartPolicy // (container.RestartPolicy)
9379
{
94-
[DataMember(Name = "Name", EmitDefaultValue = false)]
80+
[JsonPropertyName("Name")]
9581
public RestartPolicyKind Name { get; set; }
9682

97-
[DataMember(Name = "MaximumRetryCount", EmitDefaultValue = false)]
83+
[JsonPropertyName("MaximumRetryCount")]
9884
public long MaximumRetryCount { get; set; }
9985
}
10086
}
10187
```
10288

103-
The property `Name` actually uses the enum value instead of its integer value. In order to do this because Go does not have enum values if you look at `specgen.go` you will see a `typeCustomizations` map where this field has been explicitly overridden in how its generated. You can use this model to accomplish more of the same where you see fit.
89+
The property `Name` actually uses the `EnumMember` value instead of its integer value. In order to do this because Go does not have enum values if you look at `specgen.go` you will see a `typeCustomizations` map where this field has been explicitly overridden in how its generated. You can use this model to accomplish more of the same where you see fit.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go build
2+
./specgen ../../src/Docker.DotNet/Models
3+
rm specgen

0 commit comments

Comments
 (0)