Skip to content

primelib/primecodegen-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrimeCodeGen

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

Installation

TODO: add installation instructions

OpenAPI Code Generator

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.

OpenAPI Template Data

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

OpenAPI Patch

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.

Roadmap

Credits

License

Released under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages