Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the path specified in OpenAPI schema as the URL #131

Closed
primal100 opened this issue Aug 18, 2023 · 0 comments
Closed

Use the path specified in OpenAPI schema as the URL #131

primal100 opened this issue Aug 18, 2023 · 0 comments

Comments

@primal100
Copy link

primal100 commented Aug 18, 2023

Description
I was trying to get the api-platform admin working with my api, but all api requests by the admin were to http://<resource_name>. 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:

parseOpenApi3Documentation("http://localhost/openapi.json", keepPathsAsUrls=true)

Or maybe it could accept a function:

const convertUrl = (path) => {
     return path;
}
parseOpenApi3Documentation("http://localhost/openapi.json", convertUrls=convertUrl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant