OData / ODataConnectedService

A Visual Studio extension for generating client code for OData Services
Other
81 stars 44 forks source link

CLI `generate` command fails silently when you pass a V1 schema #397

Open habbes opened 6 months ago

habbes commented 6 months ago

Describe the bug

The generate command completes without generating code when you pass a V1 (or V2) schema.

Version of the Project affected

OData CLI 0.3.0

To Reproduce

  1. Get an OData V1 schema file
  2. Run odata-cli generate -m my-v1-schema.xml -o output-dir

The command completes without emitting any errors, but no file is generated in the output directory.

Expected behavior

The output directory should contain generated code.

If there are any errors, they should be logged.

Actual behavior

No code is generated. No error is emitted.

Additional context

The offending code comes from the following snippet in GenerateCommand.cs: https://github.com/OData/ODataConnectedService/blob/master/src/Microsoft.OData.Cli/GenerateCommand.cs#L228

if (version == Constants.EdmxVersion4)
{
      await GenerateCodeForV4Clients(options, console).ConfigureAwait(false);
}
 else if (version == Constants.EdmxVersion3)
{
       await GenerateCodeForV3Clients(options, console).ConfigureAwait(false);
}

We check whether the version is V4 or V3 only. The GenerateCodeForV3Clients method actually supports V1, V2 and V3. So we should check for those as well.

And we should have an else block to emit an error for unsupported versions.

if (version == Constants.EdmxVersion4)
{
      await GenerateCodeForV4Clients(options, console).ConfigureAwait(false);
}
 else if (version == Constants.EdmxVersion3 || version == Constants.EdmxVersion2 || version == Constants.EdmxVersion1)
{
       await GenerateCodeForV3Clients(options, consol, version).ConfigureAwait(false);
}
else
{
       ReportUnsupportedVersionError();
}