Transforms a Hydra API doc in an intermediate representation that can be used for various tasks such as creating smart API clients, scaffolding code or building administration interfaces.
MIT License
104
stars
71
forks
source link
Use the path specified in OpenAPI schema as the URL #131
Description
I was trying to get the api-platform admin working with my api, but all api requests by the admin were to http://. Intermediate paths like /api/ and /v1/ are ignored.
My openapi json file specifies paths for each resource. Looking over the code the intermediate paths are stipped, I'm not sure why:
let serverUrlOrRelative = "/";
if (document.servers) {
serverUrlOrRelative = document.servers[0].url;
}
....
const splittedPath = removeTrailingSlash(path).split("/");
const name = inflection.pluralize(splittedPath[splittedPath.length - 2]);
const url = `${removeTrailingSlash(serverUrl)}/${name}`;```
So "/api/v1/users" becomes "http://users" which of course is incorrect and very few schemas have just the resource name at the base path of the domain.
It seems the only way to have an intermediate path is to add a server to the openapi json document, but I don't see why this should be necessary when the openapi schema already includes the path to use. Also even if servers are specified, the code only picks the first server, so this means urls with different base paths will be converted to using the same base path based on the first server making it less flexible. Many common frameworks don't include servers when generating the openapi spec, making the api-platform admin unusable. It's also not mentioned in the README that a server needs to be specificied in order to have the correct urls.
I also find it strange that it pluralises it, why change the path at all? These paths are used by the admin to make api requests so they should be the same as that given in the schema.
Example
parseOpenApi3Documentation could accept a property:
Description/. Intermediate paths like /api/ and /v1/ are ignored.
I was trying to get the api-platform admin working with my api, but all api requests by the admin were to http:/
My openapi json file specifies paths for each resource. Looking over the code the intermediate paths are stipped, I'm not sure why:
So "/api/v1/users" becomes "http://users" which of course is incorrect and very few schemas have just the resource name at the base path of the domain.
It seems the only way to have an intermediate path is to add a server to the openapi json document, but I don't see why this should be necessary when the openapi schema already includes the path to use. Also even if servers are specified, the code only picks the first server, so this means urls with different base paths will be converted to using the same base path based on the first server making it less flexible. Many common frameworks don't include servers when generating the openapi spec, making the api-platform admin unusable. It's also not mentioned in the README that a server needs to be specificied in order to have the correct urls.
I also find it strange that it pluralises it, why change the path at all? These paths are used by the admin to make api requests so they should be the same as that given in the schema.
Example
parseOpenApi3Documentation could accept a property:
Or maybe it could accept a function: