I have following code to define Docket for swagger documentation for my rest API in a spring boot application:
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(regex("/((^|, )(api1|api2))+$/.*"))
.build().apiInfo(apiInfo());
My aim is to have endpoints url as /api1/... OR /api2/..., but it is not working.
What am I missing here?
Related
Sometimes response of a service is too large that swagger cannot get and beautify response as json.
if we try with "curl" command, we get response very fast. I think this is because of "Syntax highlighting" configuration of swagger.
In this url, we can understand that one way is change this config:
springdoc.swagger-ui.syntaxHighlight.activated=false
Do you have any idea in wso2 apim 4.1.0?
Can we change API Definition for this? or we have to change core configs of wso2?
With advanced UI customization you should be able to get this done. Please refer - https://apim.docs.wso2.com/en/latest/reference/customize-product/customizations/advanced-ui-customization/
You will have to customize the Swagger UI and add the springdoc.swagger-ui.syntaxHighlight.activated property there.
In[1], it is added springdoc.swagger-ui.validatorUrl for the Swagger UI.
[1] -
https://github.com/wso2/apim-apps/blob/main/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/ApiConsole/SwaggerUI.jsx#L32
I have a custom domain name in AWS API gateway. I am using the same domain for 2 separate API stages. One API stage is REST API, and the other HTTP API.
When I test out my setup, everything works for the REST API. However, the mapping path for HTTP API is not working and I get status-code = 404 Not Found, with 0kb body.
references used:
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-mappings.html
https://docs.aws.amazon.com/apigateway/latest/developerguide/rest-api-mappings.html
From my testing in postman, i get the following result when calling the custom domain.
1. {{api.gateway.custom.domain.url}}/foobar - works
2. {{api.gateway.custom.domain.url}}/this-no-work/foobar - 404
3. {{api.gateway.custom.domain.url}}/this-works/foobar - works
does anyone know why (2) gives 404? api-gateway REST API with mapping works while api-gateway HTTP API will return 404 with 0kb body. Is there something I am missing?
note: the (none) path mapping has been added for a sanity check, and I was able to get the expected response.
I had the same problem.
The problem is in the configuration of routers of your application.
When you configure one API mapping in AWS API Gateway, the configured path (this-no-work) is passed to your web application as a prefix of routes.
SO ... if you have one route like this:
/api/foobar
you need configure one more route with the prefix point to the same action:
/this-no-work/api/foobar
A good one is to make one global configuration to your web app.
You can note it enabling the cloudwatch logs of your API Gateway stage and looking into the cloudwatch logs the path property passed from API Gateway to the Web application.
Thanks to answer from #gean-ribeiro, I was able to figure why my HTTP API was returning 404 Not Found.
Turns out it was not an issue with HTTP API. The error 404 Not Found with 0kb body was coming from the API integration sitting behind APIG. Specifically, it was a load balancer using rules based on HTTP path pattern.
By default, any unmatched path pattern will return 404 with text/plain body. this-no-work was a new HTTP API I added, and it did not have the necessary listener rules.
Once I added a new listener rule for HTTP Path pattern is /this-no-work/*, it worked as expected..
when default endpoin is created in my case it uses this pattern
https://{api_id}.execute-api.{region}.amazonaws.com/
an answer might be: Disable the default endpoint for an HTTP API
more details here
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-disable-default-endpoint.html
When I query my Invoke URL as https://xxx.execute-api.yyy.amazonaws.com/test/q?apiKey=AAA with my below setup my backend receives a call as https://api.mysite.com/q?apiKey=AAA&apiKey=111: one apiKey=AAA comes from the client, the second one - apiKey=111 comes from the Integration Request configuration.
Question:
What/How should I configure an integration that apiKey=AAA either removed from the client call or replaced on the integration step with 111 value so that only one apiKey comes to the backend?
Note:
with proxy passthrough integration the Mapping Templates are not available;
the reason for such configuration is that my legacy backend has a big amount of endpoints which is not possible to configure individually.
My setup:
I have created a new REST API.
Then I have created a new Configure as a Proxy resource named proxy with a Resource Path /{proxy+} with the following setup for ANY method as a proxy integration:
Integration type HTTP Proxy
Endpoint URL: https://api.mysite.com/{proxy}
Content Handling: Passthrough
As a next step, I have configured an Integration Request for my /{proxy+} - ANY by adding a new query string to the URL Query String Parameters section:
Name: myApiKey
Mapped from: '111'
Then I click Deploy API to test stage and getting Invoke URL, let's say: https://xxx.execute-api.yyy.amazonaws.com/test.
Even with Proxy Integration, we can still override Request & Response.
Here is the blog. Let me try to summarize.
Ensure that Use Proxy Integration is unchecked
Simple VTL template in Mapping Template to replace apiKey queryParameter.
#set($newApiKey = "abcd")
$input.json("$")
#set($context.requestOverride.querystring.apiKey = $newApiKey)
Add Method Responses example response codes 200, 400 and 500.
Add Integration Response for each status code for each response codes for example http status for 2xx 2\d{2} with pass through behaviour.
Lets say we have a proxy setup for path /someapi/sompath. Above template will replace /someapi/sompath?apiKey=100 to {proxy}?apiKey=abcd
I am trying to use the AWS API Gateway+Swagger to route the request to my express backend. I can't figure out how to automate the setup of the integration request as the Swagger file has no details on it.
I'm also having difficulty with the endpoint url parameter when setting my method requests to GET/VPC Link on the integration type
For example:
My api gateway path is /info/car/{model}/aggregate
Now the endpoint url is http://carapi.com/info/car/{model}/aggregate
I have lots of gateway paths all of which are the same paths that my carapi.com site uses, so I don't want to keep retyping the path over and over. When entering in the endpoint url, I was able to simplify not having to type carapi.com by using stage variables turning my endpoint url to
http://${stageVariables.carApi}/info/car/{model}/aggregate
However after reading https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#stagevariables-template-reference
I see that there is also a $context available, but it gives me an error(when I try to call the api in postman, says 'internal server error' for the message) when I try to implement the context (which through that link shows that I can implement the path).
http://${stageVariables.carApi}/${context.resourcePath}
So my question is: how do I automate the setup of Integration requests so I don't have to manually setup each and every one(as I have hundreds of paths)? Is there also anyway to not have to set the paths manually for the endpoints?
I don't know of any solution which is ready to use.
In my project, we wrote a custom solution that downloads the application Swagger json, parses it, adds the required integration and generates another json file. Then we import that into API Gateway. This has been converted as a Jenkins job and runs as a post job of microservice deployment.
Another way is, instead of generating the json, directly call API Gateway APIs and add the integration.
I'm making a Passthrough API Gateway using Magento 2 API to search certain products (GET Method). In this document the parameters look like this:
searchCriteria[filter_groups][0][filters][0][field]:name
searchCriteria[filter_groups][0][filters][0][value]:%tea%
searchCriteria[filter_groups][0][filters][0][condition_type]:like
When i try the endpoint API URL that given to me, it works and the result looks like this:
Then I start to make the Passthrough API Gateway in AWS but unfortunately AWS API Gateway doesn't allow me to input square bracket([]) in the URL Query String Parameters with message warnings : [], errors : [Parameter name should match the following regular expression: ^[a-zA-Z0-9._$-]+$].
I tried to deploy the API Gateway without any URL Query String Parameters and the response is that parameter is required.