feat!: generate the REST client with OpenAPI.jl 1.x (0.5.0) - #25
Merged
Conversation
Merged
Several schemas used 'type: object' for values that OPA documents as any
JSON value, and two 200 responses were declared empty although OPA returns
a JSON body. The openapi-generator client tolerated both; a strict,
validating client does not.
- getDocumentSuccessResponse.result, compileSuccessResponse.result,
partialQuerySchema.input/options, patchOperation.value,
queryParameterPost.input and the createDocument request body are now
untyped (any JSON value), matching their descriptions and OPA's behaviour.
- inputSchema declares its single 'input' property instead of being a
free-form object.
- policy.ast.rules[].body[].terms is untyped: OPA emits an object for a
single term and an array for a call.
- GET /health 200 and DELETE /v1/policies/{id} 200 carry an application/json
body ('{}', plus 'metrics' for the delete), so they reference new
healthyResponse and deletePolicySuccessResponse components instead of
noContentResponse.
- The explain parameter's enum is a named schema (explainMode) so generated
clients get a stable type name.
Replace the openapi-generator (java) client, which needed OpenAPI.jl 0.2 and JSON 0.21, with a module generated natively by OpenAPI.jl 1.1 from the same specification. specs/openapi/generate.jl regenerates it strictly (a spec defect fails generation) from the pinned environment in specs/openapi/. The generated module is OPAClient; OpenPolicyAgent.Client is an alias, since a module cannot be named Client while defining the Client(server) constructor. Breaking changes for callers (see docs/src/client.md for a migration table): - operations are flat functions named after the operationId (get_document_with_path -> getdocumentwithpath) taking client as a keyword; the per-tag API structs (DataApi, ...) are gone - operations return the decoded body; with_http_info=true returns an ApiResponse; non-2xx responses throw Client.ApiError with the decoded body in ex.decoded instead of returning it - request bodies are typed (InputSchema(; input = ...)); explain takes Client.ExplainMode; free-form objects such as metrics are structs whose entries live in additional_properties - the client is constructed with Client.Client(url; headers, request_options) and relies on OpenAPI.jl >= 1.1.1 honouring allowReserved on the OPA path parameter, replacing escape_path_params=false Dependencies follow the generated code: HTTP 2, JSON 1.7, OpenAPI 1.1.1, Julia 1.10; TimeZones is no longer needed. Tests, docs and CI are updated accordingly. Version 0.5.0.
tanmaykm
force-pushed
the
tan/openapi1-client
branch
from
September 11, 2026 08:55
6f7ab8a to
6bea29e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the openapi-generator (java) client, which needed OpenAPI.jl 0.2 and JSON 0.21, with a module generated natively by OpenAPI.jl 1.1 from the same specification. Two commits: spec corrections, then the migration.
Spec corrections (commit 1)
A strict, validating client exposed places where the spec did not describe what OPA actually sends. The openapi-generator client tolerated them.
object:getDocumentSuccessResponse.result(atrueresult failed response validation),compileSuccessResponse.result,partialQuerySchema.input/options,patchOperation.value,queryParameterPost.input, thecreateDocumentrequest body. They are now untyped, matching their descriptions and the previous::Anyfields.inputSchemadeclares its singleinputproperty instead of being a free-form object.policy.ast.rules[].body[].termsis an object for a single term and an array for a call; it is now untyped (wasobject, which brokeGET /v1/policies).GET /health200 andDELETE /v1/policies/{id}200 return a JSON body ({}, plusmetricsfor the delete) although they were declared empty; they now reference newhealthyResponse/deletePolicySuccessResponsecomponents.explainenum is a named schema (explainMode) so the generated type has a stable name.Migration (commit 2)
specs/openapi/generate.jlregeneratessrc/client/OPAClient.jlin strict mode from the pinned environment inspecs/openapi/Project.toml(OpenAPI 1.1.0). The generated file is committed;generate.shand the per-model markdown tree are gone.OPAClient;OpenPolicyAgent.Clientis an alias of it, because a module cannot be namedClientwhile defining theClient(server; kwargs...)constructor.date-timefields).client.md,reference.md,ast_walker.md) and CI updated.docs/src/client.mdhas a 0.4 → 0.5 migration table.Breaking changes for callers
OpenAPI.Clients.Client(url; escape_path_params=false)Client.Client(url)api = Client.DataApi(openapi_client)clientas a keywordClient.get_document_with_path(api, path, Dict("input" => x))Client.getdocumentwithpath(path, Client.InputSchema(; input = x); client)response, http_resp = Client.get_document(api, path)response = Client.getdocument(path; client);with_http_info = truefor anApiResponseClient.post_compile(api; partial_query_schema = s)Client.postcompile(; body = s, client)explain = trueexplain = Client.ExplainMode("full")Client.ApiErrorthrown, decoded body inex.decodedmetrics::Dict{String,Any}metrics.additional_propertiesDependencies
{path}parameter is a slash-delimited document path declaredallowReserved: true, and 1.1.0 percent-encodes the slashes. 1.1.1 is now registered, so this resolves.Testing
203/203 locally on Julia 1.10.11 and 1.12.7 (originally against the JuliaComputing/OpenAPI.jl#112 branch, since released as 1.1.1). CI is green on all jobs.
x86 (32-bit) has been dropped from the matrix: Reseau.jl, pulled in via HTTP 2.x, fails to precompile on i686 Linux and Windows (JuliaServices/Reseau.jl#156). 32-bit is therefore untested.