Resolve specification issues and generate code from OpenAPI specifications.
This project is a collection of tools to help with merging, patching, and generating code (including user-provided templates) from API specifications.
- OpenAPI 3.0
- OpenAPI 3.1
TODO: add installation instructions
The openapi-generate
command can be used to generate code from an OpenAPI specification, using a built-in or custom template.
Command | Description |
---|---|
primecodegen openapi-generate -i openapi.yaml -g go -t client -o /out |
run code generation with generator go and template client |
Environment Variables:
PRIMECODEGEN_DEBUG_SPEC
- if set, the final OpenAPI specification is written to stdout.PRIMECODEGEN_DEBUG_TEMPLATEDATA
- if set, the template data passed to the code generator is written to stdout.
The openapi-generate-template
command can be used to pre-process the openapi spec and pass the resulting template data to an external code generator.
The command supports the following options:
Command | Description |
---|---|
primecodegen openapi-export-template-data -i openapi.yaml -g go -t client |
generate go template data, stdout |
primecodegen openapi-export-template-data -i openapi.yaml -g go -t client -o template.yaml |
generate go template data, file output |
The openapi-patch
command can be used to apply automatic modifications, merge multiple specifications, and apply custom patches to the OpenAPI specification.
Command | Description |
---|---|
primecodegen openapi-patch -i openapi.yaml -o patched.yaml |
if no patches are specified, the default ones are applied |
primecodegen openapi-patch -i openapi.yaml -i openapi.part2.yaml -o patched.yaml |
merge one or more specifications into one |
primecodegen openapi-patch -i openapi.yaml -p flattenSchemas -o patched.yaml |
apply built-in patch with id flattenSchemas |
primecodegen openapi-patch -i openapi.yaml -f noservers.jsonpatch |
apply a jsonpatch to the specification |
primecodegen openapi-patch -i openapi.yaml -f mypatch.patch |
apply a git patch to the specification |
primecodegen openapi-patch list |
list available patches |
Note: All the options can be combined, e.g. merging multiple specifications, custom user-provided patches and built-in patches.
The following built-in patches are available:
Patch | Default | Description |
---|---|---|
pruneOperationTags |
true | Removes all tags from operations. |
pruneOperationTagsExceptFirst |
false | Removes all tags from operations except the first one. |
pruneCommonOperationIdPrefix |
false | Removes common operation id prefixes (e. g. all operationIds start with API_ ) |
generateOperationIds |
false | Generates operationIds for all operations based on the HTTP path and method, overwriting existing ones. |
flattenSchema |
true | Flattens inline request bodies and response schemas into the components section of the document. |
missingSchemaTitle |
true | Adds a title to all schemas that are missing a title. |
Note: The patches are applied in the order you specify them in. If none are specified, the patches flagged as
default
are applied.
- Add support for AsyncAPI (https://github.com/asyncapi/parser-go/tree/master)
- Add support for Protobuf (https://github.com/yoheimuta/go-protoparser)
- OpenAPI Parser: libopenapi
- Patches - Git: go-gitdiff
- Patches - JSON: jsonpatch
Released under the MIT license.