Is it possible to specify the client library using swagger codegen? - swagger-codegen

When generating a client based on Swagger metadata, is it possible to specify or configure things somehow that the output should use some other client library?
So if it was a C# client for example, to automatically replace the HttpClient or RestSharp client (I don't recall what it is now as I have not used it in a while) with some custom library?

Yes it is possible,
The codegen uses templates and configuation java classes to generate code in different languages. If you're willing to modify these templates and classes this would be a quite simple modification.
You can find the opensource repository here Swagger-Codegen
The template files for each language can be found here:
https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources
Java config classes:
https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages
List of template variables:
https://github.com/swagger-api/swagger-codegen/wiki/Mustache-Template-Variables
Template are written in mustache:
https://mustache.github.io/mustache.5.html
Interesting read if you want to start from scratch:
https://github.com/swagger-api/swagger-codegen/wiki/How-to-add-a-generator-for-a-new-language-or-framework

Related

Local instance of gitlab does not respond to REST-calls from the API documentation located in "/gitlab/doc/api/v4"

I have undertaking a master thesis project that uses the openapi.yaml files to auto generate test for REST-api web-services - This has lead me to host a local instance of gitlab, so that I can run the tool I am working on, on gitlab. For that to happen I need the .yaml files containing the documentation for the API calls. Such files are found within in the gitlab source-code, but the call does not seem to work.
Some calls work, namely:
http://localhost/api/v4/version
http://localhost/api/v4/users
http://localhost/api/v4/projects
http://localhost/api/v4/groups
all returns meaningful JSON.
the problem is that a lot of the calls within the documentation does not work (returns a "404 not found"), namely:
http://localhost/api/v4/metadata
http://localhost/api/v4/projects/{id}/access_tokens
and more calls specified in the documentation.
The problem is that a lot of the calls that work are not documented (all of the above except the 'version' call). I have really tried to look for an alternative openapi.yaml files, but with little success and I am also puzzled to why the one left in the actual source-code does not contain meaningful documentation. Have I overlooked something? I am currently using postman and providing a sudo authentication-token.
Thanks in advance - I must surely have overlooked something!
Currently I have tried to look for an alternative openapi.yaml both by googling and be browsing swaggerhub.com. I Have look at the documentation pages for gitlab, but I have not found anything I did not already have.
Unfortunately, at this time of writing, GitLab does not provide an OpenAPI spec for all of its API. Only a very small part of the API is documented in openapi.yml. There is an open issue that is tracking this improvement.
For now, the online API docs are going to be your best source of information available on using the GitLab API.
As for your problem of getting 404 responses, the most common cause of this is that the credentials you are using do not have permissions to the project/feature you are trying to access or you are not using a proper authentication method. Also keep in mind some features of the API require an appropriate license entitlement.

swagger API documentation with my own yaml file

I have my API documented with Swagger. For developer convenience I would like to provide the swagger GUI on my website as well. However, my provider has not installed the php yaml extension. It implies that I can't use the GUI on my own website.
So, I would like to use a third party GUI. I know that I can use https://petstore.swagger.io/ and enter the link to my yaml file in the text box. This is also not really user friendly. I prefer to open the GUI and specify the yaml when calling the url. For the user the GUI opens with my API definition.
Any thoughts?
If for some reason you cannot host Swagger UI youself, here are some alternatives you can try:
Use SwaggerHub to host your API definition and docs.
Disclosure: I work for the company that makes SwaggerHub.
Use GitLab to host your OpenAPI YAML/JSON file. GitLab uses Swagger UI to render OpenAPI files. Example:
https://gitlab.com/gofus/gofus-api/blob/dev/swagger.yaml
Use https://petstore.swagger.io with the url query parameter to automatically load your API definition:
https://petstore.swagger.io?url=https://yoursite.com/api.yaml
For this to work, the server where your OpenAPI file is hosted must use HTTPS and support CORS.

Is it necessary to migrate from ember-data/active-model-adapter to DS.JSONAPISerializer for ember 3?

Documentation for DS.ActiveModelAdapter is exists only for 1.13 (for 2 - 404:
https://api.emberjs.com/ember-data/1.13/classes/DS.ActiveModelAdapter
So, it looks like it's moved out from DS:
https://github.com/ember-data/active-model-adapter
We have ember-data 2.13.2 and it's working fine with active-model-adapter
But we got some issues with the bump to ember-data 2.14.11 with nested behavior
The big issue here is to rewrite the backend part.
We also may use RESTAdapter:
https://www.emberscreencasts.com/posts/113-restadapter-vs-jsonapiadapter-vs-activemodeladapter
but it looks like ember way is JSONAPIAdapter way:
https://api.emberjs.com/ember-data/release/classes/JSONAPIAdapter
So, generally, the question is: what way is better for ember-upgrade?
keep backend API and maintain active-model-adapter
rewrite backend API and migrate to JSONAPIAdapter (with data/relationships approach)
rewrite backend API and migrate to RESTAdapter
keep backend API and implement custom serializer to change on the fly input/output to use JSONAPIAdapter or RESTAdapter (pick best) logic on FE (maybe it's some crazy way, but it's just to ask)
Note: backend API on RubyOnRails
A rewrite of your backend is not needed. Ember Data is flexible enough to handle all REST APIs that follow some convention among their endpoints.
Let's have a look on your specific use case.
ActiveModelAdapter and ActiveModelSerializer were deprecated in Ember Data 1.13 and removed in Ember Data 2.0. But the logic itself is still available through active-model-adapter package.
All that package does is providing a customization of Ember Data's build-in RestAdapter and RestSerializer packages. If you ignore the in-source documentation it's actually not much code. You can find it in the addon/ folder of active-model-adapter package.
So even if this package would not be available you could still customize RestAdapter and RestSerializer in the same way to support your backend as is.

How to use external file to modify a variable when the app is in production?

I have a web page made with .Net Core 2.1 and Vue, when the web application is in production mode, how to leave a config file as the Net Core appsettings.json and modify a variable.
My doubt is also about how to build the content of it, and how to access to that variable in one of my component page in vue.
Thank you
Sounds like what you may be after is External Configuration Store pattern
https://learn.microsoft.com/en-us/azure/architecture/patterns/external-configuration-store
This will allow you to store the configuration information in external storage, and provide an interface that can be used to quickly and efficiently read and update configuration settings

HttpBrowserCapabilities Custom Browser file parsing

If I have a custom .browser file, and I want to evaluate what will happen if it is given a particular User Agent, is there any way to do that through the .NET API?
I was attempting to use HttpBrowserCapabilites, but I'm not sure how to load a custom .browser file into that class.
Normally, you should not have to explicitly load the HttpBrowserCapabilities class; ASP.NET will load it for you, as long as you have your .browser file in the right place (in App_Browsers).
However, testing it will be another problem. You can't modify the "User-Agent" HTTP Header from within either the HttpApplication (global.asax) or a custom HttpModule.
This leaves only awkward techniques, such as using Reflection to force the value, or using an external tool (such as Fiddler). Alternately, if you're good with C/C++, you could take a simple example for an ISAPI filter and modify it, then install it in IIS.
Install the User Agent Switcher Firefox extension. It will let you adjust the user agent the browser sends to the web server.
http://chrispederick.com/work/user-agent-switcher/