Repository navigation
Check the openapi document of the admin api against a running otoroshi - #2824
Merged
Merged
Conversation
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.
Summary
The openapi document of the admin api (
/apis/openapi.json) described the Scala classes of the entities, by reflection, instead of the json the api reads and writes: wrong field names (locationinstead of_loc, camelCase instead of snake_case), fields that do not exist, missing fields, wrong content types, undocumented operations and routes, few descriptions and no examples. This PR makes the document the reference of the admin api, and adds a suite that checks it against a running otoroshi.The document
otoroshi/conf/schemas/openapi/<group>.json, with a description on every schema and property and examples. They are read once byOpenApiSchemas, and eachResourceofOtoroshiResourcescarries its own throughResourceVersion.schema(whatGET .../_schemaanswers). The entities of third party extensions keep a schema reflected from their class.OpenApiResourcePathsfrom whatGenericApiControllerreally does: json and yaml bodies, json patch / fields patch / form bodies forPATCH, ndjson for the bulk operations, thekindadded to every answer, the list parameters (pagination, sorting, filters, projection), and the operations that were missing (POST {id},DELETEof a collection,_schema)./api/..., and the/apis/...routes of specific controllers) moved fromadditionalPaths.json/additionalComponents.jsontoconf/schemas/openapi/paths/<family>.jsonandapi-<family>.json, rewritten against the controllers, and the routes that were not documented are./apiroutes that the generic api has no equivalent of are documented too, and the suite requires them:GET/DELETE /api/apikeys/{id}/quotas(read and reset the quotas of an api key),POST /api/certificates/{certId}/_renew,POST /api/certificates/_bundle(import a PEM bundle),POST /api/certificates/_dedupLetsEncrypt,DELETE /api/apps-sessions-module/{id}(log out every user of an auth module) andPOST /api/new/resources(build complete entities from partial json or yaml definitions, nothing is stored).index.jsonlists every file, and the tags of the hand written operations with their description.tools.OpenApiSchemaDraftsSpecdrafts the schema of a new entity from the json it writes, to complete by hand.The suite
sbt "testOnly OpenApiConformanceTests"(otoroshi/test/openapi/, not wired in CI) starts an otoroshi (cluster leader, every shipped extension enabled), reads the document it serves, and checks:$refresolved, no unused schema, unique operation ids, declared tags, valid keywords, types, formats, enums, defaults and examples;It runs without sbt too, filtered by test name:
org.scalatest.tools.Runner -s openapi.OpenApiConformanceSpec -z "<substring>", withotoroshi/conffirst on the classpath.Api behaviours it found
The document describes what the api should answer, it does not hide these: they are the 116 failures left of the suite (8377 tests, 8208 succeeded, 116 failed, 53 canceled). None of them is fixed here.
Content-Type.[]) is answered 500 on every entity./apis/openapi.*,/apis/plugins.*,/apis/workflows/doc.*) answers 502 on the admin api host, the server the document declares (DocAction does not send backOtoroshi-State-Resp).GET /apis/proxy.otoroshi.io/v1/drafts/:kind(conf/routes) shadows the generic_count,_schema,_templateand{id}of the drafts.GETanswers it without itsid.PUT /api/cluster/quotasandPOST /api/cluster/relayanswer 500 on bodies or headers they do not expect.Writing the schemas against the code found many more (500 on malformed inputs, settings lost on read, read defaults that differ from the defaults of a new instance, an ndjson export that cannot be imported back, docs that disagree with the formats...): they are listed for a review one by one, outside of this PR.
Choices to review
/api(apikeys, routes, groups...) is not required to be documented,/apisreplaces it. Only the seven routes above, with no/apisequivalent, are.envelopequery parameter of the generic api is not documented (it changes the shape of the answers).pathByIdis renamedpatchById(typo), which changes the names generated by sdk generators._schemaanswers the hand written schema of the entity, with the schemas it references undercomponents.schemas.openapi.jsonfiles are not regenerated here, the release does it.Test plan
sbt "testOnly OpenApiConformanceTests": 8208 succeeded, the 116 failures are the api behaviours abovesbt "testOnly UnitTests": 7665 succeededfunctional.OpenApiSchemasSpec: 10 succeededfunctional.ResponseCompressorSpec,functional.BrotliResponseCompressorSpec,functional.PluginsTestSpec(-l Browser): succeeded, but for the Swagger UI plugin test locally, that read a stale copy of the swagger ui bundle intarget/web/public/test