Skip to content

refactor!: centralize reference resolution and implement specific reference types. #203

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

Merged
merged 23 commits into from
Jan 31, 2025

Conversation

VisualBean
Copy link
Contributor

@VisualBean VisualBean commented Jan 27, 2025

This pull request includes several important changes across multiple files in the LEGO.AsyncAPI project. The changes primarily focus on adding copyright notices, modifying namespace imports, and enhancing the AsyncApiDiagnostic class.

Closes: #196

Licensing and Namespace Updates:

  • Added copyright notices:

    • src/LEGO.AsyncAPI.Bindings/Sns/Principal.cs
    • src/LEGO.AsyncAPI.Bindings/Sns/PrincipalObject.cs
    • src/LEGO.AsyncAPI.Bindings/Sns/PrincipalStar.cs
    • src/LEGO.AsyncAPI.Bindings/Sqs/PrincipalObject.cs
    • src/LEGO.AsyncAPI.Bindings/Sqs/PrincipalStar.cs
  • Removed unnecessary using directive:

    • src/LEGO.AsyncAPI.Bindings/Sns/Statement.cs
    • src/LEGO.AsyncAPI.Bindings/Sqs/Statement.cs

Code Enhancements:

  • Modified SnsOperationBinding class to use this.identifierFixFields:

    • src/LEGO.AsyncAPI.Bindings/Sns/SnsOperationBinding.cs
  • Added Append method to AsyncApiDiagnostic class:

    • src/LEGO.AsyncAPI.Readers/AsyncApiDiagnostics.cs

Refactoring:

  • Removed AsyncApiExternalReferenceResolver class:

    • src/LEGO.AsyncAPI.Readers/AsyncApiExternalReferenceResolver.cs (Fa207344R1)
  • Refactored AsyncApiJsonDocumentReader to use instance context:

Reference implementations has changed

Changed References to be dereferenced through a 'workspace' type.
Resolved references are cached here for later, and referenced through the new reference types specifically.

private AsyncApiParameter Target
{
    get
    {
        this.target ??= this.Reference.Workspace.ResolveReference<AsyncApiParameter>(this.Reference);
        return this.target;
    }
}

public override string Description { get => this.Target?.Description; set => this.Target.Description = value; }

References are still resolved at read time however, due to constraints in how the project align with eachother.

The core Reference type, has been amended to return more 'correct' output, in terms of what used to be the 'Id' which in reality was supposed to be the fragment identifier.

External Reference resolution

External references will now be resolved, as many turtles down as is required.
The reference streams (original documents) are cached in the workspace, in case there are multiple fragmented references to them.
All external references are forced to json (from yaml) and json-pointers are used for fragment lookups.
This means that you can technically reference yaml documents from a json asyncapi document, and vice versa, but this should be seen more as a feature than anything else.

external uri's are expected to be prefixed with either file:// or http(s)://.
A custom StreamLoader can be implemented if something different is needed.
Stream output is expected to be yaml or json.

Fragments

Fragments are now fully resolved, across the document if needed - not just components.
this means that you can now reference other parts of the document if needed.
like this.

asyncapi: 2.3.0
info:
  title: test
  version: 1.0.0
channels:
  workspace:
    publish:
      message:
        title: test message
  other:
    $ref: "#/channels/workspace"

Fixes

This also fixes a few missing reference resolution paths;

  • Bindings
  • MessageTraits

BREAKING CHANGE:

References

References are now specific types that decorator the original type.
This means 2 things.

  1. References are written directly instead of the type, rather than added to the original type.

Changed from

new AsyncApiOperationTrait()
{
    Reference = new AsyncApiReference()
    {
        FragmentId = "kafka",
        Type = ReferenceType.OperationTrait,
    },
},

To

new AsyncApiOperationTraitReference("#/components/operationTraits/kafka");
  1. references are now fully qualified (rather than using the type as a weak reference, you must now write out where the reference is actually located.). (except for SecurityRequirements which still reference components through the scheme name rather than the components location.)

Renames

AvroSchema has been renamed to AsyncApiAvroSchema to denote the top level abstract as a specific AsyncApi Class.

Others

The concrete payload types has been removed, as these posed unneeded complexity for the library consumers.
Particularly with references.

Now the AsyncApiAvroSchema and AsyncApiJsonSchema types can be used directly as message payloads.

@VisualBean VisualBean changed the title [DRAFT] refactor: bigger better stronger references [DRAFT] refactor: reimplement references as specific types Jan 27, 2025
plus minor formatting fixes across the solution
@VisualBean VisualBean changed the title [DRAFT] refactor: reimplement references as specific types refactor: reimplement references as specific types Jan 30, 2025
@VisualBean VisualBean marked this pull request as ready for review January 30, 2025 12:49
@VisualBean VisualBean changed the title refactor: reimplement references as specific types refactor: Centralize reference resolution and reimplement references so they can be dereferenced. Jan 30, 2025
@VisualBean VisualBean changed the title refactor: Centralize reference resolution and reimplement references so they can be dereferenced. refactor: centralize reference resolution and reimplement references so they can be dereferenced. Jan 30, 2025
@VisualBean VisualBean changed the title refactor: centralize reference resolution and reimplement references so they can be dereferenced. refactor: centralize reference resolution and reimplement reference types. Jan 31, 2025
@VisualBean VisualBean changed the title refactor: centralize reference resolution and reimplement reference types. refactor!: centralize reference resolution and reimplement reference types. Jan 31, 2025
@VisualBean VisualBean changed the title refactor!: centralize reference resolution and reimplement reference types. refactor(references)!: centralize reference resolution and reimplement reference types. Jan 31, 2025
@VisualBean VisualBean changed the title refactor(references)!: centralize reference resolution and reimplement reference types. refactor(references)!: centralize reference resolution and implement specific reference types. Jan 31, 2025
@VisualBean VisualBean changed the title refactor(references)!: centralize reference resolution and implement specific reference types. refactor!: centralize reference resolution and implement specific reference types. Jan 31, 2025
@VisualBean VisualBean merged commit e2fbdaf into vnext Jan 31, 2025
5 checks passed
@VisualBean VisualBean deleted the alex/refs branch January 31, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant