swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Generate a library that can be consumed by Windows UWP app

Open ncksol opened this issue 9 years ago • 7 comments

I am a bit confused about the support for UWP with swagger-codegen. According to this issue here: https://github.com/swagger-api/swagger-codegen/issues/2241 the beta support for uwp has been implemented. But I've just tried to generate the code with targetFramework=uwp and the result doesn't look valid to me.

The project generated contains references to libraries like System.Data which are part of .NET Framework, but are not support by uwp apps.

If I try to build the project, I get errors around the async functionality. I believe it is because the project file is a mishmash of different incompatible options. The "TargetPlatformIdentifier" property is set to UAP, but "ProjectTypeGuids" property is not set to "A5A43C5B-DE2A-4C0C-9213-0A381AF9435A" (which indicates type Universal Windows Class Library) and therefore project type is defaulted to standard .net framework library. In that case "TargetPlatformIdentifier" is ignored completely and with no "TargetFrameworkVersion" property mentioned the .net framework is defaulted to 3.5. And that version doesn't have support for async functionality, hence the build errors.

Now, I don't have much experience with UWP apps and might be doing something completely wrong here. Because based on the issue above, @jerry1621 managed to make it work just fine with UWP. So I am just looking for some help in understanding whether my approach is incorrect or is does UWP support still requires additional work.

ncksol avatar Feb 18 '17 13:02 ncksol

@ncksol thanks for reporting the issue.

The project generated contains references to libraries like System.Data which are part of .NET Framework, but are not support by uwp apps.

For UWP, what should be used instead of System.Data?

The "TargetPlatformIdentifier" property is set to UAP, but "ProjectTypeGuids" property is not set to "A5A43C5B-DE2A-4C0C-9213-0A381AF9435A"

So when the targetFramework=uwp option is provided, if we change ProjectTypeGuids to "A5A43C5B-DE2A-4C0C-9213-0A381AF9435A", the issue will be addressed?

wing328 avatar Feb 22 '17 06:02 wing328

@wing328

For UWP, what should be used instead of System.Data?

Well as far as I know UWP uses .Net Core which is delivered in a single package from nugget. It doesn't have those references to specific libraries any more.

So when the targetFramework=uwp option is provided, if we change ProjectTypeGuids to "A5A43C5B-DE2A-4C0C-9213-0A381AF9435A", the issue will be addressed?

I think it might work yes. Although I have my suspicions regarding RestSharp. I don't know how well it's going to play with UWP. The reason is, since UWP uses .NET Core libraries and not Standard .NET Framework libraries, in that project you also cannot reference any other libraries that are using Standard .NET Framework.

If you happy for this bug to hang around for a while, I was planning on trying to figure out a fix myself in the next week or two.

ncksol avatar Feb 22 '17 18:02 ncksol

Ok, I did some testing around the project that swagger generates for UWP. And I believe it is not possible at the moment to make it work. Reason being - RestSharp doesn't have a version that works with .NET Core. It looks like there is some work being done to make it support it, but the PRs are not getting merged and the whole has been dead for a couple of months now. - https://github.com/restsharp/RestSharp/issues/664

Not sure what's happening with RestSharp and whether they are going to support it. It seems to me that at them moment the only way to actually make Swagger work with UWP, is to create new template for UWP as a separate language and use another library. Which would obviously require rewriting the code that is getting generated.

ncksol avatar Mar 04 '17 12:03 ncksol

@ncksol thanks for looking into this. There's another ongoing work to make the C# API client to support another HTTP lib: RestSharp.Portable. From what I read, seems like RestSharp.Portable should work with UWP.

Do you think that will meet your requirement as well?

wing328 avatar Mar 06 '17 07:03 wing328

@ncksol can you please give #4955 a try?

git checkout -b Gronsak-issue-1557 master
git pull https://github.com/Gronsak/swagger-codegen.git issue-1557

wing328 avatar Mar 12 '17 03:03 wing328

@wing328 ok i've done a preliminary test and it seems like this PR does add all the functionality needed for UWP. I am going to do a more sophisticated test tomorrow trying to access my actual api through an UWP app. But this does look promising.

ncksol avatar Mar 12 '17 21:03 ncksol

@wing328 I can confirm now that this PR does indeed work. I am able to generated a good library and consume my api in a UWP app. thnx @Gronsak!

ncksol avatar Mar 17 '17 15:03 ncksol