Skip to content

feat: automated AsyncAPI generation from Go structs - #8

Closed
jpower432 wants to merge 11 commits into
complytime:mainfrom
jpower432:feat/asyncapi-gen
Closed

feat: automated AsyncAPI generation from Go structs#8
jpower432 wants to merge 11 commits into
complytime:mainfrom
jpower432:feat/asyncapi-gen

Conversation

@jpower432

Copy link
Copy Markdown
Member

Summary

Please include a summary of the changes and the context of this PR.

Related Issues

Inform any issues relevant to this PR. For example:

  • Closes #ISSUE_NUMBER

Review Hints

  • Review hints here. Replace this text. Don't use the italics format!

  • Use this optional section to give any relevant information that could help the reviewer to more quickly and assertively understand and test the changes.

  • Good examples are useful commands, if it is better to review all commits together or in a suggested sequence, any relevant discussion in other PRs or issues, etc.

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Implements AST-based parser that walks Go source files and returns
[]EventSpec values from structs annotated with the asyncapi sentinel
blank field pattern.

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Remove unreachable `if field.Names != nil` guard in extractEventSpec
and replace string-concatenated temp path with filepath.Join in test.

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Implements BuildDoc() converting []EventSpec to an AsyncAPIDoc model
with channels, send/receive operations, CloudEvents envelope schemas,
data schemas, and NATS JetStream bindings.

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Adds missing assertion to TestBuildDoc_Operations verifying that the
receive operation carries an empty NATS stream (binding is send-only).

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Implements WriteYAML to marshal AsyncAPIDoc to disk with SPDX header
and 0o644 permissions.

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Replaces the stub main.go with the full CLI entry point that wires
ParseFile, BuildDoc, and WriteYAML together. Adds the go:generate
directive and asyncapi sentinel tag to events/events.go, and commits
the generated api/events/asyncapi.yaml.

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Adds generate, asyncapi-lint, and an expanded check task to Taskfile.yml.
Fixes NATS binding: stream name moved to x-stream extension (valid per
AsyncAPI spec extensions), bindingVersion set to 0.1.0 (was "latest").
Adds nolint directives for gosec G306 on intentional 0o644 file writes.

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Extends BuildDoc and the asyncapi-gen CLI with optional -description,
-license, -contact-name, and -contact-url flags. Updates the go:generate
directive in events/events.go and regenerates api/events/asyncapi.yaml
with the full metadata matching the original hand-authored file.

Assisted-by: Claude (Anthropic, Claude Sonnet 4.6)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Comment thread api/events/asyncapi.yaml
url: https://github.com/complytime/complyapi
defaultContentType: application/cloudevents+json

servers:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpower432 great! This is actually what I was referencing in my comment on https://github.com/complytime/nunya/issues/430 here

Comment thread api/events/asyncapi.yaml
type:
type: string
const: dev.complytime.evidence.ingested
EvidenceIngestedData:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go struct output '#/components/schemas/EvidenceIngestedData'

Comment thread api/events/asyncapi.yaml
payload:
$ref: '#/components/schemas/EvidenceIngestedCloudEvent'
schemas:
EvidenceIngestedCloudEvent:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consumers would use the public contract or build and then extract the schemas as JSON from components.schemas.EvidenceIngestedCloudEvent

}
}

// goTypeToJSONSchema maps Go type strings to JSON Schema type strings.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hbraswelrh revisit for the structs -> JSON

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

Successfully merging this pull request may close these issues.

3 participants