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

Const strings are not handled #56

Open
jprokopski opened this issue Jan 2, 2025 · 3 comments
Open

Const strings are not handled #56

jprokopski opened this issue Jan 2, 2025 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@jprokopski
Copy link

Report

When using const strings in the code, the generated XML is incorrect. Instead of correctly including the value of the constant in the XML, it generates empty sting.

Expected Behavior

[Document]
public class ExamplePolicy : IDocument
{
    public void Inbound(IInboundContext c)
    {
        c.SetHeader(Headers.Example, "Test");
    }
}

public static class Headers
{
    public const string Example = "X-Example";
}

should return

<!-- This file is generated by the Azure API Management Policy Toolkit -->
<!-- Version: 0.0.1.0 -->
<policies>
  <inbound>
    <set-header name="X-Example" exists-action="override">
      <value>Test</value>
    </set-header>
  </inbound>
</policies>

Actual Behavior

[Document]
public class ExamplePolicy : IDocument
{
    public void Inbound(IInboundContext c)
    {
        c.SetHeader(Headers.Example, "Test");
    }
}

public static class Headers
{
    public const string Example = "X-Example";
}

returns

<!-- This file is generated by the Azure API Management Policy Toolkit -->
<!-- Version: 0.0.1.0 -->
<policies>
  <inbound>
    <set-header name="" exists-action="override">
      <value>Test</value>
    </set-header>
  </inbound>
</policies>

Steps to Reproduce the Problem

  1. Create an example policy with a header as const string.
[Document]
public class ExamplePolicy : IDocument
{
    public void Inbound(IInboundContext c)
    {
        c.SetHeader(Headers.Example, "Test");
    }
}

public static class Headers
{
    public const string Example = "X-Example";
}
  1. Run compiler.

Component

Compiler

Version

v1.0.0

Contact Details

No response

Additional Information

No response

@jprokopski jprokopski added the bug Something isn't working label Jan 2, 2025
@Mielek
Copy link
Collaborator

Mielek commented Jan 6, 2025

Hello @jprokopski! Thank you for contributing that issue to the project. We really appreciate your time doing this.

Currently, constants, static fields and other value storing structures are not supported in the compiler. We know that this is one of the most useful features which would allow reusability of parts of the configuration. The feature has as well few problems which we need to discuss and solve, like how to do referencing of elements across files should work or how to do a value inlining in the expressions. We definity want to bring that in as a feature in the future releases.

As a part of this issue, we can improve the code to report an unsupported error to user when the unsupported policy parameter value is used. The code which handles policy parameters is now silently putting the empty string when unknow structure is used. Reporting the error there should cover the issue for now until the feature will not be implemented.

What do you think? Is the above fix acceptable before we will work on the feature?

@Mielek
Copy link
Collaborator

Mielek commented Jan 10, 2025

I check out that in the compiler from the main branch this is now correctly reported as an error.

@Mielek Mielek added enhancement New feature or request and removed bug Something isn't working labels Jan 10, 2025
@Mielek
Copy link
Collaborator

Mielek commented Jan 10, 2025

I changed the issue type to enhancement because of the reasons captured in the previous message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants