Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Wiki
  • Building your own Templates

Building your own Templates · Changes

Page history
use OpenAPI spec instead authored Aug 12, 2018 by William Cheng's avatar William Cheng
Hide whitespace changes
Inline Side-by-side
Building-your-own-Templates.md
View page @ 4744b011
...@@ -4,13 +4,13 @@ First off, the codegen project has transforming logic as well as templates for e ...@@ -4,13 +4,13 @@ First off, the codegen project has transforming logic as well as templates for e
https://github.com/openapitools/openapi-generator/tree/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages https://github.com/openapitools/openapi-generator/tree/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages
Each template does a few things, namely generate a data structure from the swagger specification (note: the codegen project will transform previous versions of the swagger spec into a 2.0 specification before performing the transformation. See the [Swagger-Parser](https://github.com/swagger-api/swagger-parser) project for details). While you do not necessarily need to perform transformations, it's likely necessary, or every programming language would have roughly the same syntax. Each template does a few things, namely generate a data structure from the OpenAPI specification (note: the codegen project will transform previous versions of the OpenAPI spec into a 2.0 specification before performing the transformation. See the [Swagger-Parser](https://github.com/swagger-api/swagger-parser) project for details). While you do not necessarily need to perform transformations, it's likely necessary, or every programming language would have roughly the same syntax.
The transform logic needs to implement [CodegenConfig.java](https://github.com/openapitools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java) and is most easily done by extending [DefaultCodegen.java](https://github.com/openapitools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java). Take a look at the various implementations as a guideline while the instructions get more complete. The transform logic needs to implement [CodegenConfig.java](https://github.com/openapitools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java) and is most easily done by extending [DefaultCodegen.java](https://github.com/openapitools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java). Take a look at the various implementations as a guideline while the instructions get more complete.
Aside from transforming, the implementing class gets to decide "what to do" with the data structure. Namely, which data structures to apply to which template files. You have the following at your disposal: Aside from transforming, the implementing class gets to decide "what to do" with the data structure. Namely, which data structures to apply to which template files. You have the following at your disposal:
1) Operations. There is a data structure which represents all the operations that are defined in the swagger specification. A single file is created for each `OperationGroup`, which is essentially a grouping of different operations. See the `addOperationToGroup` in `DefaultCodegen.java` for details on this operation. 1) Operations. There is a data structure which represents all the operations that are defined in the OpenAPI specification. A single file is created for each `OperationGroup`, which is essentially a grouping of different operations. See the `addOperationToGroup` in `DefaultCodegen.java` for details on this operation.
You can have many files created for each `OperationGroup` by processing multiple templates and assigning a different file naming pattern to them. So for a single file per operation: You can have many files created for each `OperationGroup` by processing multiple templates and assigning a different file naming pattern to them. So for a single file per operation:
......
Clone repository
  • API client generator HOWTO
  • Building your own Templates
  • Customizing client code generation
  • FAQ
  • Git Branches
  • Home
  • How to add a generator for a new language or framework
  • Integration Tests
  • Migration Guide
  • Mustache Template Variables
  • Pull Request Checklist
  • Release Checklist
  • Samples folder
  • Server stub generator HOWTO
  • Vendor Extensions
View All Pages