Skip to content

Conversation

@philhassey
Copy link

No description provided.

This complete redesign of the x/exp/schema package introduces:

- Builder pattern API similar to the public ast package:
  - Schema.AddEntity(), AddAction(), AddCommonType(), AddNamespace()
  - EntityDecl with MemberOf(), SetAttributes(), SetTags(), SetEnum()
  - ActionDecl with InActions(), SetPrincipalTypes(), SetResourceTypes(), SetContext()
  - Type constructors: Boolean(), Long(), String(), SetOf(), Record(), Entity(), Extension(), Ref()

- Dual format support:
  - MarshalJSON() / UnmarshalJSON() for JSON schema format
  - MarshalCedar() / WriteCedar() / UnmarshalCedar() for human-readable Cedar format
  - Full round-trip conversion between formats

- Comprehensive type system:
  - Discriminated union pattern using interfaces
  - TypeBoolean, TypeLong, TypeString, TypeSet, TypeRecord, TypeEntity, TypeExtension, TypeRef
  - Attribute helpers: Attr(), OptionalAttr(), RequiredAttr()

- Annotations support for namespaces, entities, actions, and common types
- Backward compatibility with SetFilename() for error message customization
- ~95% test coverage with comprehensive test suite
- Add tests for unknown type variants to exercise error paths in JSON and Cedar marshaling
- Add tests for nil type handling in attributes, tags, context, and common types
- Add tests for JSON error propagation in nested structures
- Remove dead code (unreachable err check in attrFromJSON)
- Add targeted failing writer tests to exercise error paths

The remaining uncovered code (~2.3%) consists of defensive error handling in internal conversion functions that can only be triggered if the internal parser produces invalid output, which never happens in practice.
- Add BadTypeForTesting helper in internal/schema/ast for testing unknown type paths
- Add internal_test.go with tests for internal conversion functions
- Extract unmarshalFromInternal helper for testability
- Test all error paths in type conversion, including:
  - Unknown internal types in convertInternalType
  - Bad types in Set elements, Record attributes, entity shapes, tags, contexts
  - Error propagation through namespace, schema, entity, action conversions
  - CommentBlock handling in schema and namespace declarations
- All 100% of statements now covered
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