I'm new to swagger, and I'm trying to make a very simple specification, with only a get method in order to retrieve a web page, this is the code:
{
"swagger": "2.0",
"info": {
"title": "example",
"description": "Sample api to retrieve a web page.",
"version": "0.1"
},
"host":"example.org", #"localhost:8080",
"schemes": [
"https"
],
"paths": {
"/":{
"get":{
"summary":"Return the web page.",
"description":"",
"produces":["text/html"],
"responses":{
"200":{
"description":"OK",
},
"400":{
"description":"Bad request"
},
"404":{
"description":"Not Found"
}
}
}
}
}
}
I'm using the swagger online editor.
Unfortunately when I execute the request, it did not return the web page and no one of the status code that I have implemented in the specification, it return me in the detail section the error:
TypeError: Failed to fetch
Someone can tell me where I'm wrong?
Thank you.
For the "Try it out" button to work in the Swagger online editor, your API endpoints must be CORS-enabled. That is, your server (example.org or localhost:8080) must be configured to return certain response headers that would allow editor.swagger.io to make cross-domain requests to your server. This is explained in more details here:
https://github.com/swagger-api/swagger-ui#cors-support
The way to configure CORS depends on the server/framework used to host the app. This page has instructions for some common web servers:
https://enable-cors.org/server.html
Related
I have to retrieve the logo and cover from the Google My Business Locations and I would like to understand which kind of API I should call.
To get the locations list I've called the accounts.locations.list and the REST services give me back the correct results with a lot of data.
But these results do not contain the media logo and cover, and reading the documentation I've seen this page accounts.locations.media.list but it refers to the old API with a hostname "mybusiness.googleapis.com" while the other is "mybusinessbusinessinformation.googleapis.com", and calling it with the OAuth 2.0 Playground the service returns this error:
{
"error": {
"status": "PERMISSION_DENIED",
"message": "Google My Business API has not been used in project 711831863231 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project=711831863231 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"code": 403,
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"url": "https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project=711831863231",
"description": "Google developers console API activation"
}
]
},
{
"reason": "SERVICE_DISABLED",
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"domain": "googleapis.com",
"metadata": {
"consumer": "projects/711831863231",
"service": "mybusiness.googleapis.com"
}
}
]
}
}
so I thought that I needed to add the API on the Google Console page but all the My Business API are enabled and I don't see a generic My Business or a specific Media API to add.
I think this API might be disable as showed on the response with the label "SERVICE_DISABLED" but I can't understand which API I have to call to extract this information (logo and cover, but also the other media linked with the location).
I am trying to implement Ocelot/Swagger/MMLib and .net microservices on my Windows 2019 server.
Everything is working fine, I can call each of the microservices correctly through the API gateway using postman, but I would like to display the swagger documentation as the API is going to be used by a third party.
If I use the ip address/port number I get the correct page displayed, with my microservice definitions. However if I reroute this to a physical url (eg https://siteaddress.com/path/swagger.index.html) I get the main swagger document but a 'Failed to load API definition' error, followed by 'Fetch error undefined /swagger/docs/v1/test.
The network page of my browser inspection gives a 'Http Error 404.0 Not Found'. The requested url is 'https://siteaddress.com:443/swagger/docs/v1/test'.
My ocelot.json is:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/v1/TestSvc/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "test.api",
"Port": "80"
}
],
"UpstreamPathTemplate": "/api/v1/TestSvc/{everything}",
"UpstreamHttpMethod": [ "POST" ],
"SwaggerKey": "test"
}
...
],
"SwaggerEndPoints": [
{
"Key": "test",
"Config": [
{
"Name": "Test API",
"Version": "v1",
"Url": "http://test.api:80/swagger/v1/swagger.json"
}
]
}
...
]
}
I have tried changing paths in ocelot.json and startup.cs. I can see nothing in the MMLib documentation regarding this scenario, which is surely common in deploying these sites.
Suggestion on where to go next appreciated.
Page with ipaddress and port number
Page with physical address and error message
I want to filter and select Project Online data using Enterprise Custom Fields (ECF) in an Azure Logic App. I start with the out-of-the-box Project Online connector to trigger on project publish, then list project and task details.
Using the default connector, I can return project data but it does not contain the ECF data. Looking at the generated code, the Project Online connector uses /_api/ProjectServer. If I make similar requests (outside of Logic Apps) using /_api/Projectdata I get the ECF data.
If I edit the Logic App code with modified URL and fields, I get a 404 error. There seems to be something missing that I cannot see when I make the request with the modified values from within the Logic App.
My guess is the connector is limiting access to /_api/Projectdata (though the trigger itself is using this URL).
The following returns the data I want if I request it straight from the browser:
https://tenant.sharepoint.com/sites/PWA/_api/Projectdata/Projects(guid'project_GUID')
This is the raw input in the logic app:
{
"host": {
"connection": {
"name": "/subscriptions/subscription_GUID/resourceGroups/MyRG/providers/Microsoft.Web/connections/projectonline-1"
}
},
"method": "get",
"path": "/_api/Projectdata/Projects(guid'project_GUID')",
"queries": {
"siteUrl": "https://tenant.sharepoint.com/sites/PWA"
}
}
This is the raw output of the error:
{
"statusCode": 404,
"headers": {
"Access-Control-Allow-Methods": "GET, PUT, PATCH, DELETE, POST",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "3600",
"Access-Control-Expose-Headers": "*",
"Date": "Thu, 20 Sep 2018 16:58:42 GMT",
"Content-Length": "54",
"Content-Type": "application/json"
},
"body": {
"statusCode": 404,
"message": "Resource not found"
}
}
URLs and GUID have been modified in the examples above.
I am aware that swagger core , swagger inflector read a swagger.yaml / json file in creating a http response, Now we have a use wire mock to stub response where the content for the stub has to come from the swagger file.
I have gone through many examples but unable to figure out the right function to convert the swagger.yaml/json to return the http response. Please help me
SwaggerHub can be used to define your API in JSON or YAML. The UI provided alongside shows the API vividly. The UI has the option to trigger a newly defined API and check the response as a model - the structure of JSON response body. If "example" has been given in the API specification, it's fetched in the response.
If this response model works as per requirement, it can be then used in WireMock to generate stubbed responses having canned data. A swagger specification fragment and response model shown below -
API specification -
"swagger": "2.0",
"info":{
"version":"v0.1",
"title":
"Capital city finder",
"description":"Search capital city by country name"
},
"definitions":{
"city":{
"properties":{
"countryName":{
"type":"string",
"example":"United Kingdom"
},
"capitalCity":{
"type":"string",
"example":"London"
},
"nationalAnimal":{
"type":"string",
"example":"Lion"
},
"popularFood":{
"type":"string",
"example":"Fish & Chips"
}
... ... ...
Response Model -
[
{
"countryName": "United Kingdom",
"capitalCity": "London",
"nationalAnimal": "Lion",
"popularFood": "Fish & Chips"
}
]
Not sure if this is still relevant to you now.
For automation purposes I'm trying to create issues through the JIRA REST API, but I'm getting a 500, Internal Server Exception as response without any additional information.
With the Chrome-plugin "advance REST client", I ran through the following steps:
Entered the endpoint: h.ttps://[company-jira-url]/rest/api/2/issue/
Set the HTTP method: POST
Added the required headers:
Content-Type: application/json
Authorization: Basic (100% sure this one's correct)
Added the json payload (Basically the minimum required fields):
{
"fields": {
"project":
{
"key": "HACK"
},
"summary": "REST EXAMPLE",
"description": "Creating an issue via REST API",
"issuetype": {
"name": "Bug"
}
}
}
Click "Send"
The request basically looks like this (base64 string is not correct in this example):
The Request
Result:
The Response
Anyone ?