haveapi-go-client 0.29.9 → 0.30.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +5 -0
- data/docs/documentation.md +171 -0
- data/haveapi-go-client.gemspec +1 -1
- data/lib/haveapi/go_client/documentation.rb +516 -0
- data/lib/haveapi/go_client/generator.rb +16 -3
- data/lib/haveapi/go_client/version.rb +1 -1
- data/spec/documentation.Gemfile +6 -0
- data/spec/documentation_acceptance.rb +271 -0
- data/spec/documentation_build_check.rb +31 -0
- data/spec/documentation_wire_check.rb +94 -0
- data/spec/support/documentation_fixture.rb +70 -0
- data/spec/support/test_server.rb +1 -1
- data/spec/unit/documentation_spec.rb +286 -0
- metadata +11 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 890df2231c3212cf60786444dca1049aaa7fa74a7b7d3b354aecefebc41d8972
|
|
4
|
+
data.tar.gz: 5fe100b28f13414663f0cef2c382040c612c512d6f1caefcc2744519d637fa15
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 430d52e49783ab4b0699ce1ea03dbadc64a446ee1d29f71c114837e9013d1de60e17d70a9a41a149e258ad641858b0a7e3d1e50cb0fb220aa0d23b5685fabc5c
|
|
7
|
+
data.tar.gz: a2b472cd256d13b824540947f1d708bfd09ace1c2a2814f1b882ca8325fb05882e75fd2086dee07443a308249860829ac1931557fa5e44a69512e902c7b34e4c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -78,3 +78,8 @@ The value is sent in `Accept-Language` by default. Use
|
|
|
78
78
|
`SetLanguageHeader("X-Language")` when the API is configured with a custom
|
|
79
79
|
language header. Read the configured values with `GetLanguage()` and
|
|
80
80
|
`GetLanguageHeader()`.
|
|
81
|
+
|
|
82
|
+
## API documentation examples
|
|
83
|
+
|
|
84
|
+
The Ruby server can render examples against a configured generated Go SDK.
|
|
85
|
+
See [profile configuration, supported samples and verification](docs/documentation.md).
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Generated API documentation examples
|
|
2
|
+
|
|
3
|
+
The Ruby server can show Go examples for a configured generated SDK. The SDK's
|
|
4
|
+
module version is independent of the HaveAPI gem version and API version.
|
|
5
|
+
Install the `haveapi-go-client` gem at the exact generator version used for the
|
|
6
|
+
SDK, alongside the server gem. Configure the profile before mounting the API:
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
api.documentation_clients(
|
|
10
|
+
'7',
|
|
11
|
+
go: {
|
|
12
|
+
import_path: 'example.org/widget-sdk/v2/client',
|
|
13
|
+
module_version: 'v2.3.4',
|
|
14
|
+
description_path: '/etc/widget-api/sdk-v7.json',
|
|
15
|
+
generator_version: '0.30.0'
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`import_path` identifies the published SDK package, including its package
|
|
21
|
+
subdirectory. Examples import it with the explicit alias `client`. The local
|
|
22
|
+
absolute JSON file must contain the complete description used to generate that
|
|
23
|
+
SDK, including sibling resources, aliases and authentication descriptions.
|
|
24
|
+
Retain this file with the SDK release; do not create it from a filtered public
|
|
25
|
+
documentation page. The Go description has no API-version field. The configuration's version key
|
|
26
|
+
binds the retained description to that API version.
|
|
27
|
+
Keep the description private because it can include privileged API information.
|
|
28
|
+
|
|
29
|
+
A missing profile hides the Go overview entry and all Go example panels. An
|
|
30
|
+
invalid profile or a missing or mismatched generator gem fails configuration.
|
|
31
|
+
The server loads the file and constructs the adapter during configuration. HTML
|
|
32
|
+
requests do not read files, fetch API descriptions, generate source, invoke Go
|
|
33
|
+
or write an SDK. Removing the profile disables Go examples without changing API
|
|
34
|
+
behavior or existing clients.
|
|
35
|
+
|
|
36
|
+
## Mapping and supported samples
|
|
37
|
+
|
|
38
|
+
`HaveAPI::GoClient::Documentation` constructs the generator's `ApiVersion` from
|
|
39
|
+
the full saved description. Resource and action members, including aliases and
|
|
40
|
+
collision suffixes, come from the generator's existing name allocator. The
|
|
41
|
+
current user's filtered server description controls which samples and fields
|
|
42
|
+
can appear. A saved SDK can lag unrelated server additions. Each rendered sample
|
|
43
|
+
must still match its route, input and output layouts, and supplied field contracts.
|
|
44
|
+
Unsupported or stale samples show a short limitation instead of incomplete code.
|
|
45
|
+
|
|
46
|
+
Programs initialize the client with the API origin. Saved action paths include
|
|
47
|
+
the mounted root and selected `/vVERSION/` segment. Ordered sample path arguments
|
|
48
|
+
become the generated `SetPathParamInt` or `SetPathParamString` calls. Object/hash input uses
|
|
49
|
+
`NewInput().SelectParameters()` before setters; this preserves omitted fields,
|
|
50
|
+
explicit zero, false and empty strings. Nullable fields use `SetFIELDNil(true)`.
|
|
51
|
+
An empty request selects no fields. A missing request leaves input unallocated.
|
|
52
|
+
|
|
53
|
+
List input and general Custom fields are unsupported by the generator and show
|
|
54
|
+
limitations. Global input metadata has the existing `includes` Custom exception:
|
|
55
|
+
its generated setter accepts a string. Metadata guidance only names methods
|
|
56
|
+
advertised by the filtered description. It shows `NewMetaInput().SelectParameters()`
|
|
57
|
+
before setters without inventing a metadata payload for an action sample.
|
|
58
|
+
Samples requiring global or object input metadata show a limitation because the
|
|
59
|
+
example DSL cannot supply metadata values.
|
|
60
|
+
|
|
61
|
+
Object/hash and list outputs are supported. Examples access only fields present
|
|
62
|
+
in the sample, iterate list output and guard optional objects. Associated values
|
|
63
|
+
must be objects or null; nested fields require a matching visible associated
|
|
64
|
+
`show` action. Scalar Go output fields cannot distinguish null from their zero
|
|
65
|
+
value, so samples requiring that distinction show a limitation.
|
|
66
|
+
|
|
67
|
+
Transport or validation errors and unsuccessful API responses have separate
|
|
68
|
+
branches. Basic authentication and existing token/OAuth2 authentication use
|
|
69
|
+
environment variables for credentials. OAuth2 access-token acquisition happens
|
|
70
|
+
through the provider before running the example. A blocking action can show
|
|
71
|
+
`IsBlocking` and `OperationStatus` only when the visible action-state route,
|
|
72
|
+
metadata and the generated helper's fixed member names match. Request success
|
|
73
|
+
does not establish operation completion.
|
|
74
|
+
|
|
75
|
+
## Pure adapter and offline generation
|
|
76
|
+
|
|
77
|
+
The documentation adapter accepts loaded data and returns frozen plain results:
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
adapter = HaveAPI::GoClient::Documentation.new(
|
|
81
|
+
description: saved_description,
|
|
82
|
+
import_path: 'example.org/widget-sdk/v2/client',
|
|
83
|
+
module_version: 'v2.3.4'
|
|
84
|
+
)
|
|
85
|
+
resolved = adapter.resolve(resource_path: %w[widget], action_name: 'update')
|
|
86
|
+
result = adapter.render(kind: :example, context: context, mode: :sync)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The context uses readers defined by the server's documentation context. The
|
|
90
|
+
adapter does not depend on the server gem. Results have either
|
|
91
|
+
`{status: :code, code: source}` or `{status: :limitation, reason: text}`. Renderers
|
|
92
|
+
return source/plain text; the server template escapes HTML once.
|
|
93
|
+
|
|
94
|
+
For SDK fixtures or an already captured schema, use the offline constructor. It preserves the ordinary URL constructor's generation options:
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
generator = HaveAPI::GoClient::Generator.from_description(
|
|
98
|
+
saved_description,
|
|
99
|
+
destination,
|
|
100
|
+
module: 'example.org/widget-sdk/v2',
|
|
101
|
+
package: 'client'
|
|
102
|
+
)
|
|
103
|
+
generator.generate
|
|
104
|
+
generator.go_fmt
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Construction performs no discovery or writes. Generation and formatting are
|
|
108
|
+
explicit operations; the documentation adapter never calls them.
|
|
109
|
+
|
|
110
|
+
## Verification
|
|
111
|
+
|
|
112
|
+
From the repository root, with the Go and Ruby server bundles prepared:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
HAVEAPI_RELEASE_TOOLS_ONLY=1 nix develop -c bash -c \
|
|
116
|
+
'BUNDLE_GEMFILE="$PWD/clients/go/Gemfile" bundle exec rspec \
|
|
117
|
+
-I clients/go/lib clients/go/spec/unit/documentation_spec.rb'
|
|
118
|
+
HAVEAPI_RELEASE_TOOLS_ONLY=1 nix develop -c bash -c \
|
|
119
|
+
'BUNDLE_GEMFILE="$PWD/servers/ruby/Gemfile" bundle exec rspec \
|
|
120
|
+
-I servers/ruby/lib servers/ruby/spec/client_examples/go_spec.rb'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
These pure checks cover canonical names, aliases, collisions, visibility,
|
|
124
|
+
input/output fidelity, source escaping and unsupported capabilities. They do not
|
|
125
|
+
start a server or compile Go. The separate acceptance harness uses its own bundle
|
|
126
|
+
so both the server and optional generator gems are activated, along with WEBrick:
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
HAVEAPI_RELEASE_TOOLS_ONLY=1 nix develop -c bash -c \
|
|
130
|
+
'BUNDLE_GEMFILE="$PWD/clients/go/spec/documentation.Gemfile" bundle check'
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
If dependencies need installation, run `bundle install` with that same
|
|
134
|
+
`BUNDLE_GEMFILE` in the Nix shell. Check profile loading without starting a server
|
|
135
|
+
or compiling Go:
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
HAVEAPI_RELEASE_TOOLS_ONLY=1 nix develop -c bash -c \
|
|
139
|
+
'BUNDLE_GEMFILE="$PWD/clients/go/spec/documentation.Gemfile" bundle exec ruby \
|
|
140
|
+
clients/go/spec/documentation_acceptance.rb --check-environment'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The temporary consumer has no repository history. Its build uses
|
|
144
|
+
`-buildvcs=false` so an ancestor Git directory cannot supply unrelated metadata
|
|
145
|
+
or prevent compilation. This setting applies only to the disposable documentation
|
|
146
|
+
consumer. Record the tested source and retained artifacts in verification receipts.
|
|
147
|
+
|
|
148
|
+
Check the build command with an owned invalid Git ancestor, without running a
|
|
149
|
+
compiler or listener:
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
HAVEAPI_RELEASE_TOOLS_ONLY=1 nix develop -c bash -c \
|
|
153
|
+
'BUNDLE_GEMFILE="$PWD/clients/go/spec/documentation.Gemfile" bundle exec ruby \
|
|
154
|
+
clients/go/spec/documentation_build_check.rb'
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Run the complete acceptance harness:
|
|
158
|
+
|
|
159
|
+
```sh
|
|
160
|
+
HAVEAPI_RELEASE_TOOLS_ONLY=1 nix develop -c bash -c \
|
|
161
|
+
'BUNDLE_GEMFILE="$PWD/clients/go/spec/documentation.Gemfile" bundle exec ruby \
|
|
162
|
+
clients/go/spec/documentation_acceptance.rb'
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The harness saves a local schema fixture, generates its SDK, loads the matching
|
|
166
|
+
profile and writes the complete programs returned by the actual server renderer.
|
|
167
|
+
It formats, compiles and runs those programs against a disposable localhost
|
|
168
|
+
server. Cases include initialization, authentication methods, mounted/versioned
|
|
169
|
+
paths, nullable/false/zero/omitted inputs, list output, failures, global metadata
|
|
170
|
+
and action state. Go dependency and toolchain downloads are disabled. Generated
|
|
171
|
+
Go files remain disposable generator outputs.
|
data/haveapi-go-client.gemspec
CHANGED