I would like to avoid hardcoding everytime base uri in specification and use defined one in the root is there any way to achieve it, for example:
#%RAML 1.0
title: Some Service
version: v1
baseUri: https://example.com
/test:
post:
responses:
201:
headers:
Location:
type: string
example: https://example.com/v1/test/291 # here i would like to retrieve https://example.com/v1/ from root where I've already defined it.
Short answer: Yes.
You can specify the baseUri at the root of the document. It then applies to all resources.
See:
https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#the-root-of-the-document
Related
I need to create an API that has four possible HTTP query parameters. Either parameter one or parameter two is required. The others are optional. From the official RAML version 1.0 specification on Github, I found an almost exact scenario in the RAML queryString example.
I loaded it into Mulesoft Design Center to test it out. The RAML produces no errors in Design Center, and everything looks okay. According to the first example in the RAML, the following URL should produce a success (200 OK):
GET https://(mocking URL)/locations?start=2&lat=12&long=13
When I send it via Postman, it reaches the mocking service, but I get the following error:
{
"code": "REQUEST_VALIDATION_ERROR",
"message": "Error validating query string: expected type: JSONObject, found: Null"
}
I'm not sure if this is a Design Center limitation or if there's something off in my URL. Does anyone know what I'm doing wrong?
Here's the RAML sample from the official spec:
#%RAML 1.0
title: Illustrate query parameter variations
types:
lat-long: # lat & long required; mutually exclusive with location
properties:
lat: number
long: number
loc: # location required; mutually exclusive with lat & long
properties:
location:
paging: # each is optional, not exclusive with anything
properties:
start?: number
page-size?: number
/locations:
get:
queryString:
type: [paging, lat-long | loc ]
examples:
first:
value:
start: 2
lat: 12
long: 13
second:
value:
start: 2
page-size: 20
location: 1,2
third: # not valid
value:
lat: 12
location: 2
strict: false # because it's not valid
The RAML specification explicitly does not define validation for object types:
RAML does not define validation when a query parameter declaration
specifies any of the following types for the value of the query
parameter: an object type, a union of non-scalar types, or an array
type if the underlying type of the array is an object type or union of
non-scalar types. Processors MAY default to treating the format of the
query parameter value as JSON in applying the type to instances of
that query parameter, or they MAY allow other treatments based on
annotations.
Even if the Mocking Service implements the validation eventually, it might be better to use simple types for query parameters, like strings and numbers. It makes sense because usually query parameters are just used that way.
This looks like a bug in the MuleSoft Anypoit mocking tool.
The RAML spec is correct.
You may wish to raise a defect with MuleSoft support.
Is it okay according to the HTTP spec to have a request that (for example) does the following:
GET https://www.example.com/api/images/1 -> 200 OK, Content Type "image/png"
GET https://www.example.com/api/images/2 -> 404 NOT FOUND, Content Type "application/json"
We're having trouble with this in Swagger since you have to specify the Content-Type of the response before making the request, so I figured I'd ask whether what we want to do is even acceptable according to the HTTP spec before we continue digging into how it can be solved with Swagger
Yes, it's perfectly fine for an URL to return different HTTP status codes depending on the result of the request. It's also OK to return different media types, e.g. based on the Accept header (aka content negotiation) or other conditions.
In OpenAPI/Swagger 2.0, your example can be described like this:
paths:
/something:
get:
produces:
- image/png
- application/json
responses:
'200':
description: A PNG file
schema:
type: file
'404':
description: Not Found
schema:
type: object
# properties:
# ...
OpenAPI 3.0 improves response definitions and lets you specify the media types for specific status codes:
responses:
'200':
description: A PNG image
content:
image/png:
schema:
type: string
format: binary
'404':
description: Not found
content:
application/json:
schema:
type: object
# properties:
# ...
According to the JavaDoc for getServletMapping():
Specify the servlet mapping(s) for the DispatcherServlet, e.g. '/',
'/app', etc.
According to SpringMVC online reference doc, there are 2 ways to specify a URL for #RequestMapping annotation:
URI templates
Ant-style path patterns
So, does these 2 options apply to getServletMapping() as well? Which one is supported by getServletMapping()? Or both?
Ref:
Ant path patterns: Ant path style patterns
URI template: https://www.rfc-editor.org/rfc/rfc6570
I have problem with urls in my Symfony 2.3 aplication.
I have defined routing like this:
home_how_to_buy:
path: /strefa-wiedzy#jak-kupic
defaults:
_controller: FrameworkBundle:Template:template
template: 'GLHomeBundle:Default:faq.html.twig'
The problem is that when I create links for this page I have something like:
app_dev.php/strefa-wiedzy%23jak-kupic
I have been looking for escaping in yml files, but none of those solutions work for my path.
I will be gratefull for any help.
As stated in my answer here the hashtag is not intended to be in symfony routing. You can do the suggested workaround. But first you should consider, do you really need url-fragments in routing?
PHP's rawurlencode() encodes all chars except a-zA-Z0-9-._~ according to RFC 3986. But we want to allow some chars to be used in their literal form (reasons below). Other chars inside the path must of course be encoded, e.g. ? and # (would be interpreted wrongly as query and fragment identifier), ' and " (are used as delimiters in HTML).
In ASP.NET MVC how do I get the fully qualified path to my css file
by specifying the relative path.
Eg
Url.Content("~/Content/Print.css")
This returns eg "/Content/Print.css"
Where as I want
http://www.mysite.com/Content/Printcss
Understand the issue?
Malcolm
Similar to Phil, I would use the Request object. However, I would look at the Url property.
With the Url, you can call GetLeftPart(UriPartial.Authority) to get the missing part of your address:
string address =
System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +
Url.Content("~/Content/Print.css");
The GetLeftPart should return "http://www.mysite.com" as shown in the doc:
http://msdn.microsoft.com/en-us/library/system.uri.getleftpart(v=VS.100).aspx
I'd probably concatenate Request.UserHostName and your CSS location:
String.Format("{0}/Content/Print.css", Request.UserHostName);