Skip to content

Cannot generate usable interfaces #211

@panesofglass

Description

@panesofglass

Description

I ran into the following problems while trying to generate interfaces in the generative SwaggerProvider:

  • Cannot generate an interface using ProvidedTypeDefinition that will load at runtime.
  • Cannot generate valid interface methods on a ProvidedTypeDefinition. ProvidedMethod requires invokeCode, which appears to be converting the generated method into a public extern method.

Repro steps

Please provide the steps required to reproduce the problem

  1. Clone https://github.com/panesofglass/SwaggerProvider and switch to the api-interfaces branch.

  2. Run git reset --hard bb2a984101f767b689e49ed63ee38bfd607ffe89 to get to the interfaces implementation.

  3. Run build.cmd to run the FAKE build.

  4. Observe that, just after starting RunUnitTests, the program breaks with the following error:

screen shot 2018-03-14 at 4 01 24 pm

  1. Comment out generation of the interfaces to observe that the type provider runs tests successfully: https://github.com/panesofglass/SwaggerProvider/blob/api-interfaces/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs#L89

  2. To see the ProvidedMethod issue, roll back to this commit and run the build, then inspect the generated SwaggerProvider.ProvidedTests assembly for the Swagger.PetStore.Tests.PetStore.Contract type.

Expected behavior

  1. ProvidedTypeDefinition with TypeAttributes.Public ||| TypeAttributes.Interface ||| TypeAttributes.Abstract attributes should generate an interface that can be loaded at runtime.

  2. Generated interfaces should be able to contain generated methods.

  3. Generated interfaces should be implementable by user types.

  4. Generated interfaces should be implementable on generated types within the type provider.

Actual behavior

  1. Runtime fails to load the generated interface type, causing, in this case a test assembly, to crash even when the generated interface is not used.

  2. Generated interface methods are not public abstract method but public extern method.

Known workarounds

None.

Additional information

  • This PR shows the sequence of steps I've tried and includes a fork of ProvidedTypes.fs and ProvidedTypes.fsi that attempted to make the invokeCode parameter on ProvidedMethod optional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions