| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package main |
| 18 |
|
| 19 |
import ( |
| 20 |
"io" |
| 21 |
"log" |
| 22 |
"os" |
| 23 |
|
| 24 |
openapi_v2 "github.com/google/gnostic-models/openapiv2" |
| 25 |
yaml "sigs.k8s.io/yaml/goyaml.v2" |
| 26 |
|
| 27 |
"k8s.io/kube-openapi/pkg/schemaconv" |
| 28 |
"k8s.io/kube-openapi/pkg/util/proto" |
| 29 |
) |
| 30 |
|
| 31 |
func main() { |
| 32 |
if len(os.Args) != 1 { |
| 33 |
log.Fatal("this program takes input on stdin and writes output to stdout.") |
| 34 |
} |
| 35 |
|
| 36 |
input, err := io.ReadAll(os.Stdin) |
| 37 |
if err != nil { |
| 38 |
log.Fatalf("error reading stdin: %v", err) |
| 39 |
} |
| 40 |
|
| 41 |
document, err := openapi_v2.ParseDocument(input) |
| 42 |
if err != nil { |
| 43 |
log.Fatalf("error interpreting stdin: %v", err) |
| 44 |
} |
| 45 |
|
| 46 |
models, err := proto.NewOpenAPIData(document) |
| 47 |
if err != nil { |
| 48 |
log.Fatalf("error interpreting models: %v", err) |
| 49 |
} |
| 50 |
|
| 51 |
newSchema, err := schemaconv.ToSchema(models) |
| 52 |
if err != nil { |
| 53 |
log.Fatalf("error converting schema format: %v", err) |
| 54 |
} |
| 55 |
|
| 56 |
if err := yaml.NewEncoder(os.Stdout).Encode(newSchema); err != nil { |
| 57 |
log.Fatalf("error writing new schema: %v", err) |
| 58 |
} |
| 59 |
|
| 60 |
} |