Skip to content

Commit

Permalink
Output only controller specific JSON Schema
Browse files Browse the repository at this point in the history
This commit makes schemagen output only JSON Schema for the
Kedge controllers by default. This behavior can be changed by
setting --controller flag to false.

Fixes kedgeproject#22
  • Loading branch information
concaf committed Jan 3, 2018
1 parent 9558e7a commit 634a830
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
kedgeSpecLocation string
kubernetesSchema string
openshiftSchema string
isController bool
)

// RootCmd represents the base command when called without any subcommands
Expand All @@ -27,7 +28,7 @@ var RootCmd = &cobra.Command{
}
},
Run: func(cmd *cobra.Command, args []string) {
if err := pkg.Conversion(kedgeSpecLocation, kubernetesSchema, openshiftSchema); err != nil {
if err := pkg.Conversion(kedgeSpecLocation, kubernetesSchema, openshiftSchema, isController); err != nil {
fmt.Println(err)
os.Exit(-1)
}
Expand All @@ -46,4 +47,5 @@ func init() {
RootCmd.Flags().StringVarP(&kedgeSpecLocation, "kedgespec", "k", "types.go", "Specify the location of Kedge spec file")
RootCmd.Flags().StringVarP(&kubernetesSchema, "k8sSchema", "s", "swagger.json", "Specify the location of Kuberenetes Schema file")
RootCmd.Flags().StringVarP(&openshiftSchema, "osSchema", "o", "osv2.json", "Specify the location of OpenShift schema file")
RootCmd.Flags().BoolVarP(&isController, "controller", "c", true, "output only controller specific definitions")
}
18 changes: 17 additions & 1 deletion pkg/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func MergeDefinitions(target, src *openapi.OpenAPIDefinition) {
}
}

func Conversion(KedgeSpecLocation, KubernetesSchema, OpenShiftSchema string) error {
func Conversion(KedgeSpecLocation, KubernetesSchema, OpenShiftSchema string, controllerOnly bool) error {
defs, mapping, err := GenerateOpenAPIDefinitions(KedgeSpecLocation)
if err != nil {
return err
Expand All @@ -72,10 +72,26 @@ func Conversion(KedgeSpecLocation, KubernetesSchema, OpenShiftSchema string) err
for k, v := range defs {
api.Schema.SchemaProps.Definitions[k] = v
}

if controllerOnly {
retainOnlyControllers(api.Schema.Definitions)
}

PrintJSONStdOut(api.Schema)
return nil
}

func retainOnlyControllers(definitions spec.Definitions) {
for k := range definitions {
switch k {
case "io.kedge.DeploymentSpecMod", "io.kedge.DeploymentConfigSpecMod", "io.kedge.JobSpecMod":
continue
default:
delete(definitions, k)
}
}
}

func augmentProperties(s, t spec.Schema) spec.Schema {
for k, v := range s.Properties {
if _, ok := t.Properties[k]; !ok {
Expand Down

0 comments on commit 634a830

Please sign in to comment.