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

CLI Generation to handle parameter of type 'string' but different format #4679

Merged
merged 4 commits into from
May 21, 2024

Conversation

rohitkrsoni
Copy link
Contributor

@rohitkrsoni rohitkrsoni commented May 18, 2024

fixes #4615

CLI Generator is unable to handle parameters such as DateTime, Date, etc. More precisely, the parameters having type="string" and format="datetime", "date" etc.
image

Screenshots:

Tests:
image

Kiota Update:
image

Build of Sample project:
image

Change in the builder Class:
image

calebkiage
calebkiage previously approved these changes May 18, 2024
@rohitkrsoni
Copy link
Contributor Author

Hi @baywet, are there any further changes required for this PR?

Copy link
Member

@andrueastman andrueastman left a comment

Choose a reason for hiding this comment

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

@rohitkrsoni Any chance you could add a changelog entry to the Changelog file at the repository root?

@rohitkrsoni
Copy link
Contributor Author

@rohitkrsoni Any chance you could add a changelog entry to the Changelog file at the repository root?

Done, thanks :)

@andrueastman andrueastman merged commit 6ea9b3c into microsoft:main May 21, 2024
206 checks passed
@baywet
Copy link
Member

baywet commented May 21, 2024

@rohitkrsoni @andrueastman there seems to be a regression with this one see this smoke build (only microsoft people will see that)

Has about 16k errors like this one : error CS0029: Cannot implicitly convert type 'string' to 'string[]'

This seems to be caused by the fact that the option now is Option<string[]> but the parameter for the method is string no array.
I'm guessing we should expand the fix to include array information for the parameter type. But I'd like more context from @calebkiage here before we make any changes.

@calebkiage
Copy link
Contributor

Ah, I missed the fact that GetPrimitiveTypeName does not handle collection information. We would need to add the collection type information from the schema.

Something like:

    private static CodeType GetQueryParameterType(OpenApiSchema schema)
    {
        var paramType = GetPrimitiveType(schema) ?? new()
        {
            IsExternal = true,
            Name = schema.Items?.Type ?? schema.Type,
        };

        paramType.CollectionKind = schema.IsArray() ? CodeTypeBase.CodeTypeCollectionKind.Array : default,
        return paramType;
    }

@rohitkrsoni
Copy link
Contributor Author

Hi @baywet, can I get the sample description file so that I can reproduce the issue on my local.

I tried to reproduce the issue by adding a parameter mentioned below.

      - name: testStringArrayParameter
        in: query
        description: 'Usage: newParameter=@newParameter'
        schema:
          type: array
          items:
            type: string

I didn't get any error but got this in Query Parameter properties:
image

And the option created is:

var testStringArrayParameterOption = new Option<string>("--test-string-array-parameter", description: "Usage: newParameter=@newParameter") {
};
testStringArrayParameterOption.IsRequired = false;
command.AddOption(testStringArrayParameterOption);

Is this behavior expected?

@baywet
Copy link
Member

baywet commented May 22, 2024

Thanks for the additional context @calebkiage
@rohitkrsoni yes I believe this is the scenario I'm referring to. When the option value gets assigned to the query parameter, the types don't match anymore. Would you mind following up with an additional pull request please?

@rohitkrsoni
Copy link
Contributor Author

@baywet sure leave that on me!

@rohitkrsoni
Copy link
Contributor Author

To fix this:
Issue: #4707
PR: #4708

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.

CLI generation does not handle DateTime path parameters
4 participants