Skip to content

Commit

Permalink
fix: add support for JSONSchemaProps in openapi generator
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Jul 10, 2024
1 parent d97bee0 commit 41911ca
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion kubernetes-model-generator/openapi/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ func main() {
}, "admission-registration"},
{[]reflect.Type{
reflect.TypeOf(apiextensionsV1.ConversionReview{}),
reflect.TypeOf(apiextensionsV1.JSONSchemaPropsOrArray{}),
reflect.TypeOf(apiextensionsV1.JSONSchemaPropsOrBool{}),
reflect.TypeOf(apiextensionsV1.JSONSchemaPropsOrStringArray{}),
reflect.TypeOf(apiextensionsV1Beta1.ConversionReview{}),
reflect.TypeOf(apiextensionsV1Beta1.JSONSchemaPropsOrArray{}),
reflect.TypeOf(apiextensionsV1Beta1.JSONSchemaPropsOrBool{}),
reflect.TypeOf(apiextensionsV1Beta1.JSONSchemaPropsOrStringArray{}),
reflect.TypeOf(apiextensionsV1Beta1.SelectableField{}),
reflect.TypeOf(apiextensionsV1Beta1.ValidationRule{}),
}, "apiextensions"},
Expand Down Expand Up @@ -114,7 +120,12 @@ func generateType(schemas openapi3.Schemas, t reflect.Type) {
if t.Kind() != reflect.Struct {
return
}
if schemas[getKey(t)] != nil {
// Prevent cycles
return
}
value := &openapi3.SchemaRef{Value: openapi3.NewObjectSchema()}
schemas[getKey(t)] = value
value.Value.Properties = make(map[string]*openapi3.SchemaRef)
// Gather fields
fields := extractFields(make([]reflect.StructField, 0), t)
Expand All @@ -139,7 +150,6 @@ func generateType(schemas openapi3.Schemas, t reflect.Type) {
generateType(schemas, field.Type.Elem())
}
}
schemas[getKey(t)] = value
}

func extractFields(fields []reflect.StructField, t reflect.Type) []reflect.StructField {
Expand Down Expand Up @@ -190,6 +200,13 @@ func openApiKind(t reflect.Type) *openapi3.SchemaRef {
return &openapi3.SchemaRef{
Value: openapi3.NewInt64Schema(),
}
case reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:
return &openapi3.SchemaRef{
Value: &openapi3.Schema{
Type: &openapi3.Types{openapi3.TypeNumber},
Format: "double",
},
}
case reflect.Array, reflect.Slice:
// Byte-arrays as String (Fabric8)
if t.Elem().Kind() == reflect.Uint8 {
Expand Down

0 comments on commit 41911ca

Please sign in to comment.