oapi-codegen
oapi-codegen copied to clipboard
Add support for generating only allowlisted schemas
Overview
As a user, I would like to generate only specific schemas. The new flag/option would generate models similar to --exclude-schemas, but via allowlisting approach rather than blocklisting. The reason for that is that schema generation via --exclude-schemas is not usable for large OpenAPI specs or to generate known subset of models.
Implementation
It should only work when generating models from OpenAPI specs. The new flag/option could be defined as --only-schemas (or some alternative name). For validation, if both --only-schemas and --exclude-schemas are passed, an error would be raised.
Example
OpenAPI specs
---
schemas:
Book:
properties:
name:
type: string
Article:
properties:
name:
type: string
Ignored:
properties:
name:
type: string
Model generator config
---
package: models
output: models/models.gen.go
generate:
models: true
only-schemas:
- Book
- Article
Use-case
Generating models for sub-components/SDKs from a parent OpenAPI specs. For example, when we need only some models defined in a central OpenAPI specs, we would use --only-schemasoption.
Hey, this sounds good! Would be happy to review a PR for this (although note I'm a little snowed under with reviews and the other projects I'm maintaining right now)
Hi @jamietanna, will probably have a PR by EOW. In case it ends up in main, when could we expect a release?
Per https://github.com/deepmap/oapi-codegen/discussions/1494 I'm hoping at some point this month. I've got a day off work this Friday which I'm hoping to spend some time looking at everything tagged in https://github.com/deepmap/oapi-codegen/milestone/9 as priority, then go from there.
It's absolutely fine (and recommended) for you to pin on the main branch (in this repo, we're on master for now) until release, if it's something you really need