Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zaakn opened this issue Mar 23, 2024 · 0 comments
Open

Comments

@zaakn
Copy link

zaakn commented Mar 23, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant