Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit a5d9820

Browse files
committed
Revert "Add output filtering (oapi-codegen#2201)"
This reverts commit db8abb8.
1 parent 58bb3e6 commit a5d9820

6 files changed

Lines changed: 5 additions & 506 deletions

File tree

experimental/Configuration.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,6 @@ generation:
3737
path: github.com/org/project/models
3838
alias: models # optional, defaults to last segment of path
3939

40-
# Output options: control which operations and schemas are included.
41-
output-options:
42-
# Only include operations tagged with one of these tags. Ignored when empty.
43-
include-tags:
44-
- public
45-
- beta
46-
# Exclude operations tagged with one of these tags. Ignored when empty.
47-
exclude-tags:
48-
- internal
49-
# Only include operations with one of these operation IDs. Ignored when empty.
50-
include-operation-ids:
51-
- listPets
52-
- createPet
53-
# Exclude operations with one of these operation IDs. Ignored when empty.
54-
exclude-operation-ids:
55-
- deprecatedEndpoint
56-
# Exclude schemas with the given names from generation. Ignored when empty.
57-
exclude-schemas:
58-
- InternalConfig
59-
6040
# Type mappings: OpenAPI type/format to Go type.
6141
# User values are merged on top of defaults — you only need to specify overrides.
6242
type-mapping:

experimental/cmd/oapi-codegen/main.go

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"io"
7-
"net/http"
8-
"net/url"
96
"os"
107
"path/filepath"
118
"strings"
@@ -23,9 +20,9 @@ func main() {
2320
flagPackage := flag.String("package", "", "Go package name for generated code")
2421
flagOutput := flag.String("output", "", "output file path (default: <spec-basename>.gen.go)")
2522
flag.Usage = func() {
26-
fmt.Fprintf(os.Stderr, "Usage: %s [options] <spec-path-or-url>\n\n", os.Args[0])
23+
fmt.Fprintf(os.Stderr, "Usage: %s [options] <spec-path>\n\n", os.Args[0])
2724
fmt.Fprintf(os.Stderr, "Arguments:\n")
28-
fmt.Fprintf(os.Stderr, " spec-path-or-url path or URL to OpenAPI spec file\n\n")
25+
fmt.Fprintf(os.Stderr, " spec-path path to OpenAPI spec file\n\n")
2926
fmt.Fprintf(os.Stderr, "Options:\n")
3027
flag.PrintDefaults()
3128
}
@@ -38,8 +35,8 @@ func main() {
3835

3936
specPath := flag.Arg(0)
4037

41-
// Load the OpenAPI spec from file or URL
42-
specData, err := loadSpec(specPath)
38+
// Parse the OpenAPI spec
39+
specData, err := os.ReadFile(specPath)
4340
if err != nil {
4441
fmt.Fprintf(os.Stderr, "error reading spec: %v\n", err)
4542
os.Exit(1)
@@ -81,12 +78,7 @@ func main() {
8178

8279
// Default output to <spec-basename>.gen.go
8380
if cfg.Output == "" {
84-
// For URLs, extract the filename from the URL path
85-
baseName := specPath
86-
if u, err := url.Parse(specPath); err == nil && u.Scheme != "" && u.Host != "" {
87-
baseName = u.Path
88-
}
89-
base := filepath.Base(baseName)
81+
base := filepath.Base(specPath)
9082
ext := filepath.Ext(base)
9183
cfg.Output = strings.TrimSuffix(base, ext) + ".gen.go"
9284
}
@@ -111,31 +103,3 @@ func main() {
111103

112104
fmt.Printf("Generated %s\n", cfg.Output)
113105
}
114-
115-
// loadSpec loads an OpenAPI spec from a file path or URL.
116-
func loadSpec(specPath string) ([]byte, error) {
117-
u, err := url.Parse(specPath)
118-
if err == nil && u.Scheme != "" && u.Host != "" {
119-
return loadSpecFromURL(u.String())
120-
}
121-
return os.ReadFile(specPath)
122-
}
123-
124-
// loadSpecFromURL fetches an OpenAPI spec from an HTTP(S) URL.
125-
func loadSpecFromURL(specURL string) ([]byte, error) {
126-
resp, err := http.Get(specURL) //nolint:gosec // URL comes from user-provided spec path
127-
if err != nil {
128-
return nil, fmt.Errorf("fetching spec from URL: %w", err)
129-
}
130-
defer func() { _ = resp.Body.Close() }()
131-
132-
if resp.StatusCode != http.StatusOK {
133-
return nil, fmt.Errorf("fetching spec from URL: HTTP %d %s", resp.StatusCode, resp.Status)
134-
}
135-
136-
data, err := io.ReadAll(resp.Body)
137-
if err != nil {
138-
return nil, fmt.Errorf("reading spec from URL: %w", err)
139-
}
140-
return data, nil
141-
}

experimental/internal/codegen/codegen.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ func Generate(doc libopenapi.Document, specData []byte, cfg Configuration) (stri
3131
return "", fmt.Errorf("gathering schemas: %w", err)
3232
}
3333

34-
// Filter excluded schemas
35-
schemas = FilterSchemasByName(schemas, cfg.OutputOptions.ExcludeSchemas)
36-
3734
// Pass 2: Compute names for all schemas
3835
converter := NewNameConverter(cfg.NameMangling, cfg.NameSubstitutions)
3936
ComputeSchemaNames(schemas, converter, contentTypeNamer)
@@ -105,9 +102,6 @@ func Generate(doc libopenapi.Document, specData []byte, cfg Configuration) (stri
105102
return "", fmt.Errorf("gathering operations: %w", err)
106103
}
107104

108-
// Apply operation filters
109-
ops = FilterOperations(ops, cfg.OutputOptions)
110-
111105
// Generate client
112106
clientGen, err := NewClientGenerator(schemaIndex, cfg.Generation.SimpleClient, cfg.Generation.ModelsPackage)
113107
if err != nil {
@@ -164,9 +158,6 @@ func Generate(doc libopenapi.Document, specData []byte, cfg Configuration) (stri
164158
return "", fmt.Errorf("gathering operations: %w", err)
165159
}
166160

167-
// Apply operation filters
168-
ops = FilterOperations(ops, cfg.OutputOptions)
169-
170161
if len(ops) > 0 {
171162
// Generate server
172163
serverGen, err := NewServerGenerator(cfg.Generation.Server)

experimental/internal/codegen/configuration.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ type Configuration struct {
1515
Output string `yaml:"output"`
1616
// Generation controls which parts of the code are generated
1717
Generation GenerationOptions `yaml:"generation,omitempty"`
18-
// OutputOptions controls filtering of operations and schemas
19-
OutputOptions OutputOptions `yaml:"output-options,omitempty"`
2018
// TypeMapping allows customizing OpenAPI type/format to Go type mappings
2119
TypeMapping TypeMapping `yaml:"type-mapping,omitempty"`
2220
// NameMangling configures how OpenAPI names are converted to Go identifiers
@@ -40,20 +38,6 @@ type Configuration struct {
4038
StructTags StructTagsConfig `yaml:"struct-tags,omitempty"`
4139
}
4240

43-
// OutputOptions controls filtering of which operations and schemas are included in generation.
44-
type OutputOptions struct {
45-
// IncludeTags only includes operations tagged with one of these tags. Ignored when empty.
46-
IncludeTags []string `yaml:"include-tags,omitempty"`
47-
// ExcludeTags excludes operations tagged with one of these tags. Ignored when empty.
48-
ExcludeTags []string `yaml:"exclude-tags,omitempty"`
49-
// IncludeOperationIDs only includes operations with one of these operation IDs. Ignored when empty.
50-
IncludeOperationIDs []string `yaml:"include-operation-ids,omitempty"`
51-
// ExcludeOperationIDs excludes operations with one of these operation IDs. Ignored when empty.
52-
ExcludeOperationIDs []string `yaml:"exclude-operation-ids,omitempty"`
53-
// ExcludeSchemas excludes schemas with the given names from generation. Ignored when empty.
54-
ExcludeSchemas []string `yaml:"exclude-schemas,omitempty"`
55-
}
56-
5741
// ModelsPackage specifies an external package containing the model types.
5842
type ModelsPackage struct {
5943
// Path is the import path for the models package (e.g., "github.com/org/project/models")

experimental/internal/codegen/filter.go

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)