apache / apache/pulsar

[Bug] Swagger definitions for creating sinks/sources are incorrect

Open
#19,542 3 comments 0 reactions 0 assignees View on GitHub
Stale type/bug
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Version

The affected versions are all versions from Pulsar 2.9+
I did not check earlier versions.

### Minimal reproduce step

1) Download swagger definitions from the Pulsar website, e.g. https://pulsar.apache.org/swagger/2.9.3/
2) Import swagger definitions into Postman
3) Use Pulsar Sink REST API > sinks > {tenant}/{namespace} > POST Creates a new Pulsar Sink in cluster mode to create a sink. Can use Postman directly or export generated curl command. Below is an example of the generated curl:

```
curl --location 'http://localhost:8080/admin/v3/sinks/public/default/my-jdbc' \
--header 'Content-Type: multipart/form-data' \
--form 'tenant="public"' \
--form 'namespace="default"' \
--form 'name="my-jdbc"' \
--form 'inputs="[\"my-input\"]"' \
--form 'configs="{\"jdbc.xyz\":\"abc\"}"' \
--form 'sinkType="jdbc-postgres"'
```

### What did you expect to see?

Successfully created a sink

### What did you see instead?

HTTP 400 Bad Request
```
{
"reason": "Sink config is not provided"
}
```

### Anything else?

The problem is that in the swagger definition, every field gets interpreted as a separate form, as you can see here:
```
curl --location 'http://localhost:8080/admin/v3/sinks/public/default/my-jdbc' \
--header 'Content-Type: multipart/form-data' \
--form 'tenant="public"' \
--form 'namespace="default"' \
--form 'name="my-jdbc"' \
--form 'inputs="[\"my-input\"]"' \
--form 'configs="{\"jdbc.xyz\":\"abc\"}"' \
--form 'sinkType="jdbc-postgres"'
```

The correct request however, needs to look contain a single form called `sinkConfig` that contains a json of all these parameters:
```
curl --location 'http://localhost:8080/admin/v3/sinks/public/default/my-jdbc' \
--header 'Content-Type: multipart/form-data' \
--form 'sinkConfig="{"tenant":"public", "namespace":"default", ... }"
```

The same issue is affecting the route for Sources.

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Download the Swagger definitions from the Pulsar 2.9.3 website and reproduce the generated Postman request for the Sinks REST API. Compare the multipart form produced for sink creation with the request described in the issue, then check the corresponding Sources route. Done means the definitions generate a single sinkConfig or equivalent source configuration form containing the JSON parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, postman
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.