Using Swagger in Angular [closed] - asp.net

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am new in Swagger and as far as I see it is used to generate API documents autotomatically. In addition to that, I think it is also used to generate frontend by using Swagger Codegen. AT this step, I am confused regarding to using swagger in my project properly.
I have created my backend using .NET Core and API methods are ready. Now, I need to integrate swagger to my project. I have an initial Angular frontend app, but as the code is mixed, I want to create frontend from stratch and then integrate Swagger to it. So;
1. Should I generate frontend using necessary Swagger tools? It does not seems to be good, but if it is used generally and will not be a problem as the project gets bigger, of course I can use that option.
2. If I create the Angular project from stratch, how can I integrate the swagger? Should I generate code by using the ts files of the related components?
3. If I add a new component to the frontend and corresponding API methods to the API where Swagger is already used. Which modification ahould I made? I gave a try and it geneartes a new swagger config file after building the project.

Going off on the comments I made below the question.
Just to clarify what swagger and openApi is, swagger is both a rest api specification (e.g. swaggerSpec.Json) and a set of tools to deal with the specification. For example, swagger codegen, swagger UI etc. Now at some point in time, the specification was renamed from swagger to OpenApi.
This means the specification is called OpenApi and swagger is a set of tools to deal with openApi.
Source: https://swagger.io/blog/api-strategy/difference-between-swagger-and-openapi/
Aside from swagger, there are a set of alternative tools like NSwag and Swashbuckle that can make working with the openApi specification easier.
There are 2 main parts:
Code generation for the openApi specification. You can generate code for the server (e.g. ASP.NET core rest controllers) from an OpenApi document and clients (e.g. C# rest clients, .TS rest clients, java you name it) from the OpenApi document. Or you can just generate the OpenApi specification (my SwaggerSpec.json) itself from e.g. your .net core project with some tooling.
(Web)Ui to easily host documentation. Swagger has webUI, NSwag, and even alternative tools like https://github.com/Redocly/redoc All of these include a way to easily test the Api endpoints you define. Generally these documentation sites are standalone things. They maybe configured style-wise but you generally leave them untouched. You can ofcourse roll your own - or clone any ui repos and alter that - but thats another topic.
I've investigated all 3 options (Swagger, SwashBuckle and NSwag) and i opted for NSwag because at the time a) it was the one i got working and b) it had the most features and c) the community was fairly active. This was about a year ago.
I shall explain my workflow and this should answer most questions you have. I feel like this Question is getting rather broad, so please do some digging around and try to get more specific questions tailored to your needs.
Like i said i use the NSwag toolchain:
I create Asp.Net controllers in my server app.
This contains some attributes to controller functions/endpoints so the swagger specification gets generated better:
I then use NSWag studio to create an openApi document file
Output:
At this point you could opt to use NSwag again to generate for example a typescript client which you can then use in your angular/react w/e frontend project:
I then add the swagger document to my asp.net server project, and enable the swagger UI:
Somewhere in Startup.cs:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IOptions<AppSettings> appSettingsAccessor, ILogger<Startup> logger, StaticFileConfigSection staticFileConfig)
{
// Add the openApi document and serve the swagger dashboard.
app.UseOpenApi();
app.UseSwaggerUi3(); // serve Swagger UI
...
And I can then go to /swagger to see the web ui:
And that's it. All these tools can be automated ofcourse - but i opted not to. Getting that to work can be a hassle and with NSwag studio i was always a button click away anyways. And this forced me to be more careful with my work.

Using Codegen is your choice. You can use the generated code as a boilerplate to have a straight start with your API integration. You may just copy the generated models and services and integrate them. It will save you a lot of coding time and also avoid human error in the coding of the services. But the rest of the frontend can be anything you like, not necessarily the generated project. You may use for example an Angular seed of choice and just integrate the services from Codegen.
As I've mentioned, you can copy the generated services and models from Cogeden, to have a head start. If you decide to go fully manual, you'll have to use Angular HTTP to make the requests to the server (https://angular.io/guide/http). You have to manually define the models and the services to operate with the entities. Swagger will only be a reference for the API in this case, no integration at all with Angular. I discourage this option unless the library generated by Codegen is insufficient. If the Swagger design is properly done (which sadly is uncommon to see), following all the standards and providing complete data models, you can trust the generated library.
This is advice and not objective guidance: if the updates to the API are minor, make them directly in your code and keep your Swagger updated with the new changes. If the changes are relevant, you need a new major API version, with a different endpoint. In that case, generating a new Swagger Codegen library and placing it in place of the old one will be a good idea. To be able to do this, you must avoid modifying the internals of the services of the generated library, using the library as much "as-is" as possible.

Related

Does all features belongs to Django Rest Framework available in FAST API to develop REST APIS

I have been working in the Django rest framework since three years on wards. Recently reading about FAST API frame work. FAST API looking like a very good framework for the current REST API service development. Seems like few things are missing from FAST API which are there in django.
Pagination
class based views.
mock testing
class based views.
struggled allot to provide the lookup for encrypted data in the django rest framework.
Could any one help me that how can we achieve above features with FAST API.
Currently in Jan 2020. FastAPI has a much smaller and different featureset to Django Rest Framework (DRF).
DRF is built on Django you have all the features Django available to you as well as convenient tools for building REST API's.
With FastAPI the framework way is more minimal it provides a simple, quick way to create and test a set of OpenAPI compatible endpoints. With a focus on speed and asynchronous style request-response handling.
However does not include ORM or migrations, admin, accounts etc and all the other 'batteries included' stuff you get with Django.
To achieve the functionality you have listed you'd right now you'd have to roll-your-own or use some pre-existing async python packages and adapt for your needs.

Embed Alfresco WebPreviewer in my own website

I have a Spring MVC application that connect with Alfresco using CMIS libraries, actually I can upload documents and download it but I need integrate Alfresco's WebPreviewer to preview documents in my app.
I found some code here but I don't know how to do it
It's hard to say for certain because of the limited amount of information that you've provided, but I think that the problem that you're going to be faced with when trying to use any of the existing previewer code is one of authentication. If you're using only using CMIS then you won't be able to use any of the WebScript based REST APIs that the Alfresco widgets will be using.
There are two possible previewer widgets that you can use - the older YUI2 based previewer (that you'd currently find in the document details page and the Document Library film strip view, and the newer Aikau component that you'd find in the faceted search previewer (from version 5.0 onwards).
I suspect that you won't be able to re-use either of these components without either authenticating against Alfresco in a way that allows you to access the WebScript based REST APIs or extending and customizing those widgets.
You've said that you have your own Spring MVC application, but you haven't said whether or not that is using the Surf extension - if it is, and you're using the authentication capabilities provided by Surf then you will be authenticated to use those REST APIs - as the Surf authentication provides access across all APIs (including CMIS) via a single authentication.
If you are able to access those APIs then you should be able to follow the steps outlined in both the form post and the blog posts in your own question and the previous answer, however - based on your question I suspect that you can't do that.
If you've not come across it, you might be interested in the Aikau archetype that builds a ready-made Alfresco client using Surf (see this link) and that tutorial also shows how to use the Aikau previewer (see here).
Because this is providing you with a Spring MVC client that is preconfigured to authenticate against Alfresco, you might be able to port your application to use it.
Otherwise, as I said earlier - chances are you'll need to extend the existing widgets to use the CMIS APIs to render the previewers. Again, Aikau is easier to extend that the old YUI2 widgets - but is reliant on Surf.

Single Page Application Project Templates for.NET 4.5 and Angular

Has there ever been a more confusing/difficult time to be a web developer using the Microsoft stack? That's not really my question... I know that the answer is a categorical no. :)
The single page app template that comes with VS 2013 is deplorable.
I've been working on building up a similar project template that uses Angular JS on the client, but I'm starting to spin my wheels a bit porting over the external (openId/oauth) login features.
I believe this is because of the lack of good, single-point-of-truth, and current documentation for Katana's auth/security bits and also because of how unreadable the client side code is in the S.P.A. template in visual studio 2013.
I know that I can get through it, but while I'm struggling with it, I'm wondering:
Are there any good community provided project templates or example code bases in existence that use .NET 4.5 (MVC5/Web Api 2), Angular JS, the new ASP.NET Identity stuff, and the Katana packages?
There's HotTowel.Angular, but it takes no stance on security. Besides, it's a Nuget package, which can't or shouldn't dictate as much as a proper project template can.
I agree with your observations. I have found the following setup that seems to meet your requirements and I think works very well (I don't have a template), I would suggest the following:
Create an empty WebApi2 project and adopt authentication/authorization depicted here
Use a regular index.html in the base directory as a launching point for your angular application. You can either maintain your client packages with nuget, npm, or bower.
Use whatever technique you like for organization of client code.
Personally, I would create 3 projects, One for client code, (mydomain.com) One for your api (api.mydomain.com) and one for your Model/Repository/Data Access layer.
update
Here is an open-source project that might be what you're looking for!

Generate Flex SOAP client using maven

I have a java server side project which contains JAX-WS web-services (using JavaEE 6 and the #WebService annotation).
Is there some kind of plugin that would allow me to generate Flex client stubs during my maven build ?
I have taken a look at enunciate, but it seems to generate only AMF client.
I've also tried to look at GraniteDS, but their doc seems a little opaque to me.
Notice my Flex project is compiled using flexmojos, which contains a flexmojos:generate mojo that should be able to generate domain object (however I don't understand how to say it to use domain classes from ANOTHER project, and not from a different folder).
So, is there any maven plugin that would allow the kind of feature described in this Adobe page ?
Well most solutions use the WebServices WSDL description and generate stuff from that.
I documented this process in my Wiki. Don't be confused about the CXF Part, just have a look at the "Seting Flex up as Web Service client" part. When I did this, I used the code generation features of Flash Builder to generate the code and to work with that code.
I know this is not the cleanest way to do it, but it worked then (about 2 Years ago). Things like wsld2as weren't available then ... perhaps you should have a look at that.

REST web service with asp.net

How can I add a reference to the REST web service to an ASP.NET application? The REST is generating the WADL file. How can I add a reference to my application . I tried the regular way, using Add Web Reference option, but that gives me an error.
You already asked this question a few days ago. You cannot do it, nor should you try to do it. One of the major objectives of REST is to decouple the client from the server, if you start generating proxy code on the client based on WADL you are likely to embed information into the client that with create coupling.
A REST message is supposed to be self descriptive therefore WADL should be completely unnecessary for a correctly built REST service.

Resources