there is a url like
http://someservice.com/confirm?{token}
Is this any way how to describe this endpoint in terms of swagger notation
if use as query parameter then you get
/confirm:
get:
summary: ...
parameters:
- in: query
name: token
...
http://someservice.com/confirm?token=value that is not OK
from other side it is not possible to use url notation in follow way:
/confirm?{token}:
get:
summary: ...
parameters:
- in: path
name: token
...
due to query strings in paths are not allowed.
This is currently not supported, neither in OpenAPI 2.0 nor in OpenAPI 3.0. Here's the corresponding feature request:
Support for arbitrary query strings
Related
Got following issue using OpenAPI / Swagger with ESP 1.35.0 on Cloud Run:
/go/{ppage}/subitem:
get:
summary: Get a subitem
operationId: ppage
parameters:
- in: path
name: ppage
type: string
required: true
description: Get/Retrieve a subitem
x-google-backend:
address: https://example.com/go
Given an operation config above, path gets translated into https://example.com/go?ppage=m2jobs, where:
{ppage} path parameter becomes query parameter with key ppage in a call to the backend and
/subitem part of the path vanishes in a call to the backend
Is it correct/expected?
Please advise.
Indeed, according with the following link, the backend proto translates the path parameter to query parameter and the /path/ vanishes after the first /{path param}/
https://github.com/googleapis/googleapis/blob/master/google/api/backend.proto#L35-L91
Your assumptions are correct!
Best
I'm introducing an optional "query parameter" (with default value) for one of my API endpoint ( i.e. /foo2) but hoping that existing API consumers don't have to make any changes in their application when they regenerate the java client stub from the new swagger file.
I was expecting that the generated java client will offer overloaded methods, to operate with and without a method parameter, so that my existing API consumers can work without any changes to their call. At the same time, they can switch to its more generic offering.
public void foo2Get() throws ApiException {
public void foo2Get(String type) throws ApiException {
But it generates ONLY the latter. I don't see the former.
At the same time, generated python client from same swagger throws a var arg and this way it more flexible and hence old and new offerings will work without any issues.
def foo2_get(self, **kwargs):
(swagger sample used: attached)
** Description**
Is there a way to overcome this limitation with java code generator.
swagger-generator version
swagger 2.0
Swagger declaration file content or url
swagger: '2.0'
info:
title: identity
version: Unknown
consumes:
- application/json
produces:
- application/json
parameters:
typeParam:
name: type
in: query
required: false
allowEmptyValue: true
default: basic
type: string
enum:
- basic
- advanced
paths:
/foo2:
get:
consumes:
- application/json
parameters:
- "$ref": "#/parameters/typeParam"
responses:
'200':
description: OK
I have an API which allows any arbitrary path to be passed in, for example all of these:
/api/tags
/api/tags/foo
/api/tags/foo/bar/baz
Are valid paths. I tried to describe it as follows:
/tags{tag_path}:
get:
parameters:
- name: tag_path
in: path
required: true
type: string
default: "/"
However, https://generator.swagger.io encodes slashes in the path, so it doesn't work. So is there a way to describe my API in Swagger?
This is not supported as of OpenAPI 3.1, and I have to resort to a workaround.
If I have a path /tags{tag_path} and I enter something like this as tag_path: /foo/bar, then the actual query request URL will be: /tags%2Ffoo%2Fbar. So, I just added support for that on my backend: the endpoint handler for /tags* urldecodes the path (which is %2Ffoo%2Fbar), and it becomes /foo/bar again.
Yes, a hack, but it works, and it's better than nothing. In my case, tag names can't contain the / character, so there's no conflict. Your mileage may vary, of course.
If you are using a framework like Connexion, chances are it does support a wildcard path parameter (even though it is not in the OpenAPI spec).
Here is an example for Connexion.
paths:
/pages/{path}:
get:
# (...)
parameters:
- name: "path"
in: path
description: "Remainder of path, including slashes."
schema:
type: string
format: path
The difference is the format: path added.
I have an API which allows any arbitrary path to be passed in, for example all of these:
/api/tags
/api/tags/foo
/api/tags/foo/bar/baz
Are valid paths. I tried to describe it as follows:
/tags{tag_path}:
get:
parameters:
- name: tag_path
in: path
required: true
type: string
default: "/"
However, https://generator.swagger.io encodes slashes in the path, so it doesn't work. So is there a way to describe my API in Swagger?
This is not supported as of OpenAPI 3.1, and I have to resort to a workaround.
If I have a path /tags{tag_path} and I enter something like this as tag_path: /foo/bar, then the actual query request URL will be: /tags%2Ffoo%2Fbar. So, I just added support for that on my backend: the endpoint handler for /tags* urldecodes the path (which is %2Ffoo%2Fbar), and it becomes /foo/bar again.
Yes, a hack, but it works, and it's better than nothing. In my case, tag names can't contain the / character, so there's no conflict. Your mileage may vary, of course.
If you are using a framework like Connexion, chances are it does support a wildcard path parameter (even though it is not in the OpenAPI spec).
Here is an example for Connexion.
paths:
/pages/{path}:
get:
# (...)
parameters:
- name: "path"
in: path
description: "Remainder of path, including slashes."
schema:
type: string
format: path
The difference is the format: path added.
I have an URL like this:
/id/{idnumber}/status
In this URL, /id/{idnumber} is the API base path, and /status is the resource.
I know that OpenAPI (Swagger) allows parameters in paths, like so:
paths:
/id/{number}/status:
but this is not what I need, because /id/{idnumber} is the base path and not part of the resoruce path.
Is there any way to have a parameter in the base path?
host: my.api.com
basePath: /id/{idnumber} # <---
paths:
/status:
Parameterized base paths are supported in OpenAPI 3.x, using server variables:
openapi: 3.0.0
...
servers:
- url: https://my.api.com/id/{number}
variables:
number:
default: '-1'
Note that server variables MUST have a default value - it will be used if the client does not supply a value.
For details, see:
Server Object and Server Variable Object sections of the the OpenAPI 3.0 Specification
API Server and Base URL on swagger.io
I don't think basePath allows variables.
For your case, you don't need to use basePath. You can simply put /id/{idnumber} in the URL path. For example:
"/pet/{petId}": {