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