asyncapi-codegen icon indicating copy to clipboard operation
asyncapi-codegen copied to clipboard

[BUG] asyncapi-codegen v0.46.2 fails to parse schema where "required" is array formatted instead of string formatted.

Open ericfitz opened this issue 4 months ago • 0 comments

Describe the bug.

Author's note: I had Claude Code generate the markdown for my bug report, but I reviewed every single line of it as I filled in the sections of this form. - EF

Bug Report: asyncapi-codegen v0.46.2 - Schema Parsing Error

Summary

The asyncapi-codegen tool fails to parse valid AsyncAPI v3.0 schemas with a specific error related to required field handling.

Error Message

Error: json: cannot unmarshal bool into Go struct field Schema.components.schemas.Validations.required of type string

Problematic Schema Pattern

Cell:
  type: object
  properties:
    id:
      type: string
    shape:
      type: string
  required: # <-- This array format causes the error
    - id
    - shape

AsyncAPI v3.0 Documentation Reference

According to the AsyncAPI v3.0 Schema Object specification, AsyncAPI schema objects are JSON schemas, and the required property is defined in the referenced draft JSON schema validation document as an array of strings.

required: [string]

The value of this keyword MUST be an array. Elements of this array, if any, MUST be strings, and MUST be unique.

The tool appears to expect required as a single string rather than an array of strings, which contradicts the specification.

Impact

This prevents the tool from being used with standard AsyncAPI v3.0 specifications that follow the documented schema patterns, limiting its usability for AsyncAPI v3.0 adoption.

Workaround Attempted

Creating a syntactically invalid asyncapi schema document specifying a single string value for "required" will allow the tool to complete without error, but other tools are likely to experience problems with the asyncapi schema document if they perform strict JSON schema validation or if they have a use case for more than one string value for required.

Expected behavior

The tool should successfully parse valid AsyncAPI v3.0 schemas that use array format for required fields

Screenshots

n/a

How to Reproduce

Reproduction Steps

  1. Create an AsyncAPI v3.0 specification with:

    • required: [field1, field2] array in a schema
  2. Run: asyncapi-codegen -i specification.yaml -p asyncapi -o output.go

  3. Observe the parsing errors described above

Note: example file with this problem is available here.

Minimal Reproduction Case

asyncapi: "3.0.0"
info:
  title: Bug Reproduction
  version: "1.0.0"

channels:
  "/test":
    address: "/test"
    messages:
      testMessage:
        payload:
          type: object
          properties:
            id:
              type: string
          required:
            - id

Running asyncapi-codegen -i reproduction.yaml -p test -o output.go produces the error.

🖥️ Device Information [optional]

  • Tool Version: asyncapi-codegen v0.46.2
  • AsyncAPI Version: 3.0.0
  • Go Version: 1.24.2
  • OS: macOS (Darwin 24.6.0)

👀 Have you checked for similar open issues?

  • [x] I checked and didn't find similar issue

ericfitz avatar Aug 16 '25 01:08 ericfitz