Extending the Spec
You may want to extend the resulting OpenAPI spec, to add additional endpoints, tweak the schema, add security schemes, changelog/information, etc. entrest allows a few different ways of extending the OpenAPI spec.
SpecFromPath
Configuration option SpecFromPath
allows
you to provide a path to a JSON file containing the base OpenAPI spec. This is useful if you want to start with a
base spec, and then add additional endpoints/security schemes/etc. This is the simplest option to managing extensions
that is much less tedious than dealing with the Spec
option.
Base OpenAPI spec from our kitchensink example, where we register a /version
endpoint and associated schema:
Take a look at the resulting OpenAPI spec, which includes the /version
endpoint and associated schema
here.
Request Headers
TODO
Response Headers
TODO
Error Responses
TODO
Spec
Configuration Option
Configuration option Spec
allows you to provide
a custom OpenAPI spec through the ogen.Spec
type provided by ogen. This is
more of an advanced option, as it allows you to use additional Go logic to add additional generated endpoints or
similar. This spec is effectively treated like the "base" in which the generated spec is merged into. A basic
example:
PreGenerateHook
and PostGenerateHook
Configuration option PreGenerateHook
and PostGenerateHook
are
similar to the Spec
option, but you get access to the ent graph. Primarily useful if you need to
extend the spec with ent-specific information, or you want to reuse content from the generated configuration,
and build upon it.
Example with a PreGenerateHook
:
Same thing with a PostGenerateHook
, but it runs after the spec has been generated: