Skip to content

Commit

Permalink
Reference listmeta in CR openapi
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Jun 26, 2020
1 parent a730ad5 commit b432793
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -50,14 +50,16 @@ import (
const (
// Reference and Go types for built-in metadata
objectMetaSchemaRef = "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta"
listMetaSchemaRef = "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta"
listMetaType = "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"
typeMetaType = "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"

definitionPrefix = "#/definitions/"
)

var (
swaggerPartialObjectMetadataDescriptions = metav1beta1.PartialObjectMetadata{}.SwaggerDoc()
swaggerPartialObjectMetadataDescriptions = metav1beta1.PartialObjectMetadata{}.SwaggerDoc()
swaggerPartialObjectMetadataListDescriptions = metav1beta1.PartialObjectMetadataList{}.SwaggerDoc()

nameToken = "{name}"
namespaceToken = "{namespace}"
Expand Down Expand Up @@ -457,7 +459,8 @@ func (b *builder) buildListSchema() *spec.Schema {
s := new(spec.Schema).WithDescription(fmt.Sprintf("%s is a list of %s", b.listKind, b.kind)).
WithRequired("items").
SetProperty("items", *spec.ArrayProperty(spec.RefSchema(name)).WithDescription(doc)).
SetProperty("metadata", getDefinition(listMetaType))
SetProperty("metadata", *spec.RefSchema(listMetaSchemaRef).WithDescription(swaggerPartialObjectMetadataListDescriptions["metadata"]))

addTypeMetaProperties(s)
s.AddExtension(endpoints.ROUTE_META_GVK, []map[string]string{
{
Expand Down
Expand Up @@ -419,6 +419,17 @@ func TestNewBuilder(t *testing.T) {
t.Fatalf("unexpected list properties, got: %s, expected: %s", gotListProperties.List(), want.List())
}

if e, a := (spec.StringOrArray{"string"}), got.listSchema.Properties["apiVersion"].Type; !reflect.DeepEqual(e, a) {
t.Errorf("expected %#v, got %#v", e, a)
}
if e, a := (spec.StringOrArray{"string"}), got.listSchema.Properties["kind"].Type; !reflect.DeepEqual(e, a) {
t.Errorf("expected %#v, got %#v", e, a)
}
listRef := got.listSchema.Properties["metadata"].Ref
if e, a := "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta", (&listRef).String(); e != a {
t.Errorf("expected %q, got %q", e, a)
}

gotListSchema := got.listSchema.Properties["items"].Items.Schema
if !reflect.DeepEqual(&wantedItemsSchema, gotListSchema) {
t.Errorf("unexpected list schema: %s (want/got)", schemaDiff(&wantedItemsSchema, gotListSchema))
Expand Down

0 comments on commit b432793

Please sign in to comment.