how to handle paths with openapi? - openapi

The structure of my node here in the company follow this sequence.
I have the app.js and all request will check my openapi /paths to see if there is a path that match my path in the url.
If there is no match I get a message path is not found.
But I need way to handle any path that isn't list in my openapi /paths instead of putting all path in the list.
for example I have 100 path 10 of them I will put explicit in the openapi paths all other (90) I want to handle without declaring in the in the openapi paths
I would like something like this:
paths:
/v1/client
/v1/product
...
...
/* for the 90 other paths
so when I call
localhost:3000/v1/client works fine
localhost:3000/vi/product works fine
this paths above will the treat for a specific function
localhost:3000/v1/anything doesn't work because isn't explict declared in my openapi paths.
I dont want to declare all other paths in the openapi. I want to forward all these other path to an spefic funtion.
thanks in advance.

Related

How to construct URL for Google API with query parameters

I'm trying to construct a URL to request with GET method:
https://dataform.googleapis.com/v1beta1/{workspace=projects/*/locations/*/repositories/*/workspaces/*}:readFile
https://cloud.google.com/dataform/reference/rest/v1beta1/projects.locations.repositories.workspaces/readFile#query-parameters
what I have but not working:
https://dataform.googleapis.com/v1beta1/{workspace=projects/my-project/locations/europe-west4/repositories/my-repo/workspaces/my-workspace}:readFile
Now I don't know how to put in the query parameter path.
I've tried to add ;path=my_file%2Ejson or ?path=my_file%2Ejson at the end of above URL and path is my_file at root of my-repo
My question is:
Is this even the right way to do this and how to do this correctly?
This is the correct query syntax for setting the path in your case:
https://dataform.googleapis.com/v1beta1/projects/MY_GCP_PROJECT/locations/europe-west4/repositories/REPOSITORY_NAME/workspaces/MY_WORKSPACE:readFile?path=my_file.json
So it works without the curly brackets and "workspace=".

What's the difference between URL.standardized and URL.absoluteURL?

In Swift's URL class, there are .standardized and .absoluteURL properties (.standardizedURL and .absoluteURL, and .URLByStandardizingPath in Objective-C's NSURL). There's also .standardizedFileURL.
I have no idea what the difference is between all these, but there must be one since they provide all of them, right? I mean clearly the .standardizedFileURL is meant to only deal with file URLs, but other than that (for instance, if all are called on a file URL), what's the difference?
From the above-linked docs:
Swift
standardized
Returns a URL with any instances of “..” or “.” removed from its path.
absolute​URL
Returns the absolute URL.
Discussion
If the URL is itself absolute, this will return self.
standardized​File​URL
Standardizes the path of a file URL.
Discussion
If the is​File​URL is false, this method returns self.
Objective-C
standardized​URL
A copy of the URL with any instances of ".." or "." removed from its path. (read-only)
Discussion
This property contains a new NSURL object, initialized using the receiver’s path with any instances of ".." or "." removed. If the receiver does not conform to RFC 1808, this property contains nil.
absolute​URL
An absolute URL that refers to the same resource as the receiver. (read-only)
Discussion
If the URL is already absolute, this property contains a copy of the receiver. Resolution is performed per RFC 1808.
URLBy​Standardizing​Path
A URL that points to the same resource as the original URL using an absolute path. (read-only)
Discussion
This property only works on URLs with the file:​ path scheme. For all other URLs, it returns a copy of the original URL.
Like string​By​Standardizing​Path, this property can make the following changes in the provided URL:
Expand an initial tilde expression using string​By​Expanding​Tilde​In​Path.
Reduce empty components and references to the current directory (that is, the sequences “//” and “/./”) to single path separators.
In absolute paths only, resolve references to the parent directory (that is, the component “..”) to the real parent directory if possible using string​By​Resolving​Symlinks​In​Path, which consults the file system to resolve each potential symbolic link.
In relative paths, because symbolic links can’t be resolved, references to the parent directory are left in place.
Remove an initial component of “/private” from the path if the result still indicates an existing file or directory (checked by consulting the file system).
Note that the path contained by this property may still have symbolic link components in it. Note also that this property only works with file paths (not, for example, string representations of URLs).
If url is an absolute URL, url.absoluteURL == url.
If url is a relative URL and has a non-nil baseURL, then url.absoluteURL returns an absolute URL by resolving the relativity of url in the context of baseURL (and thus url.absoluteURL != url).
If url is a relative URL, url.standardized does not return an absolute URL, and may in fact return a URL that does not resolve the same way as url (!) because url.standardized removes any leading .. components of the path.
Example:
let base = URL(string: "https://stackoverflow.com/q/43258046/77567")!
// output: "https://stackoverflow.com/q/43258046/77567"
let rel = URL(string: "../16176911", relativeTo: base)!
// output: "../../16176911 -- ttps://stackoverflow.com/q/43258046/77567"
rel.absoluteURL
// output: "https://stackoverflow.com/q/16176911"
rel.standardized
// output: "16176911 -- ttps://stackoverflow.com/q/43258046/77567"
rel.standardized.absoluteURL
// output: "https://stackoverflow.com/q/43258046/16176911"
I think the key difference is that two URLs with different absolute paths may actually refer to the same resource, and in that case, they would have the same standardized URL. Examples of path elements that could cause this are:
~ vs /absolute/path/to/user/home/directory
paths that include soft links
/path/to/thing vs /path/to/other/../thing
etc.
The standardized url (URL.standardizedFileURL in swift) is very useful because two URLs that point to the same file should have the same standardizedFileURL even if they have different absolute paths. So one should generally use the standardized path if they wish to compare two file URLs.

How to map urls?

I would like to map pages such domain/content/myProject/home.html to domain/home.html. /content/myProject/ is not needed. I have the following code:
String newpath = getResourceResolver().map(page.getPath());
this does not change anything. newpath is stay page.getPath()
how to solve this issue?
Answering as this question as it remains unanswered. Here is an example of how the etc mappings should look like:
Trick is you add 2 entries to sling:internalRedirect as / and /content/example/
AEM first tries to resolve resources with first entry '/'. So non page URLs like /etc/designs, /content/dam etc will be addressed by the first entry. If it is unable to resolve using the first one, it uses the second entry to resolve the page.
This is also the adobe recommended way for URL shortening compared to other techniques like apache redirect.
You need to create map in etc.Then Resource Resolver will take care of trimming the path .
CREATING MAPPING DEFINITIONS IN AEM
In a standard installation of AEM you can find the folder:
/etc/map/http
This is the structure used when defining mappings for the HTTP protocol. Other folders (sling:Folder) can be created under /etc/map for any other protocols that you want to map.
Configuring an Internal Redirect to /content
To create the mapping that prefixes any request to http://localhost:4503/ with /content:
Using CRXDE navigate to /etc/map/http.
Create a new node:
Type sling:Mapping
This node type is intended for such mappings, though its use is not mandatory.
Name localhost_any
Click Save All.
Add the following properties to this node:
Name sling:match
Type String
Value localhost.4503/
Name sling:internalRedirect
Type String
Value /content/
Click Save All.
This will handle a request such as:
localhost:4503/geometrixx/en/products.html
as if:
localhost:4503/content/geometrixx/en/products.html
had been requested.
You can refer here for further documentation http://docs.adobe.com/docs/en/cq/5-6-1/deploying/resource_mapping.html

get folders of a folder in one drive pro (sharepoint) rest api

I am trying to get a list of folders underneath my documents folder using the sharepoint rest api. This seems like it should be very simple but I am having a hard time seeing how to do this from the documentation.
I want to determine if the following folder exists:
[https]://[Site]/personal/[Path to User]/Documents/test
I tried:
[https]://[Site]/_api/web/GetFolderByServerRelativeUrl('/Documents')
gives 'file not found', I would expect to get some json returned that gives me file information etc, how do I determine if the /Documents/test folder has been created with the rest api?
I believe you should try it like this:
[https]://[Site]/_api/web/GetFolderByServerRelativeUrl('Documents')/folders
This should give a list of all of the folder underneath your documents library.
Hope this helps.
Web.GetFolderByServerRelativeUrl method accepts serverRelativeUrl parameter that specifies the server-relative URL for the folder.
Examples
For location:
[https]://[Site]/personal/[Path to User]/Documents
the following REST requests return folder object:
[https]://[Site]/personal/[Path to User]/_api/web/GetFolderByServerRelativeUrl('/personal/[Path to User]/Documents')
or
[https]://[Site]/personal/[Path to User]/_api/web/GetFolderByServerRelativeUrl('Documents')
Note: relative Url to Documents library is specified (not starts with / like in your example)
Please check it your url is valid like and check the url of your document library :
[https]://[Site]/Documents
In your case it should be like, if its Documents library:
[https]://[Site]/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')
Or Write full relative path of your URL like
[https]://[Site]/_api/web/GetFolderByServerRelativeUrl('/personal/[Path to User]/Documents/test')

Data binding - getBindingContext() returns absolute path rather than relative

I've got a table which I'm firing an event on row selection. In the handler I want to get the context for the selected row and then create a new context for a lower level oData object and then bind that to a Text view.
I'm sure there is a beautifully succinct way of doing this but currently I am:
Getting the binding path and adding a string to create a path to my lower level object:
var path = oEvent.getParameters().listItem.getBindingContext().sPath + "/ComplianceNote";
This is returning a path with / as the first character, from what I understand this means it's the root object of the service or this is an "absolute" path. My current workaround is to remove the first character:
path = path.substr(1, path.length);
Then I can bind my Text view:
noteText.bindElement(path);
noteText.bindProperty("text", "Note");
This works fine but seems to me to be a code smell hacking around with the string. My questions are:
Why is the path returned as "absolute" rather than "relative"
What is the correct way to achieve this. I've been looking at things like setBindContext and bindText.
Cheers,
Gregor