Skip to content

[bug] OpenAPI 3: schema items - Value MUST be an object and not an array #433

@zaakn

Description

@zaakn

Related to #83, #84

After the PR was merged, it was rolled back in this commit:
540b249#diff-38bb6d02d3442ac95d8613ef4fed0b1cb70f7bc2001d1abe71bafbede04a0dd1

 - SchemaOrReference items = 30;
 + ItemsItem items = 30;

As the comments in the latest code say, I also agree that the wrong model is being used.

case "array":
// I do believe there is a bug inside of OpenAPIv3.proto. I think the type of "schema.Items.SchemaOrReference"
// shouldn't be an array of pointers but rather a single pointer.
// According to: https://swagger.io/specification/#schemaObject
// The 'items' "Value MUST be an object and not an array" and "Inline or referenced schema MUST be of a Schema Object"
for _, schemaOrRef := range schema.Items.SchemaOrReference {
arrayFieldInfo := b.buildFromSchemaOrReference(name, schemaOrRef)
if arrayFieldInfo != nil {
fInfo.fieldKind, fInfo.fieldType, fInfo.fieldFormat, fInfo.enumValues = FieldKind_ARRAY, arrayFieldInfo.fieldType, arrayFieldInfo.fieldFormat, arrayFieldInfo.enumValues
return fInfo
}
}

Using the protoc-gen-openapi:

message Foobar {
	repeated string domains = 1 [
		(openapi.v3.property).items.schema_or_reference = {
			schema: {
				format: "hostname";
			}
		}
	];
}

output OpenAPI yaml:

Foobar:
    type: object
    properties:
        domains:
            type: array
            items:
                - type: string
                - format: hostname

Expected:

Foobar:
    type: object
    properties:
        domains:
            type: array
            items:
                type: string
                format: hostname

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions