swagger-api / swagger-api/swagger-parser
[Feature]: Allow customization of Accept-header In RemoteUrl
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
Feature Description
Currently, the Accept-header is hard coded in RemoteUrl:
private static final String ACCEPT_HEADER_VALUE = "application/json, application/yaml, */*";
Users can't change it, even if their Api might require different headers
Use Case
When using the GH file api, one has to set the Accept-header to application/vnd.github.v3.raw to retrieve the raw file content. This is currently not possible.
Suggested Solution (optional)
The easiest solution would be to back-off if the user provided its own header using the already existing List<AuthorizationValue> auths:
private static void setRequestHeaders(List<AuthorizationValue> header, URLConnection conn) {
conn.setRequestProperty("Accept", ACCEPT_HEADER_VALUE);
conn.setRequestProperty("User-Agent", USER_AGENT_HEADER_VALUE);
// allows user to override defaults
for (AuthorizationValue item : header) {
conn.setRequestProperty(item.getKeyName(), item.getValue());
}
}
I'am happy to provide the PR if you agree with this course of action
Alternatives Considered
No workaround exists since the behavior is hard coded
Additional Context
Checklist
- I have searched the existing issues to ensure this is not a duplicate.
- This feature would be useful to more than just my use case.
- I have provided enough detail for the maintainers to understand the scope of the request.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating RemoteUrl and its setRequestHeaders method, then read how the existing AuthorizationValue list is passed into request setup. The change is done when callers can override the default Accept header, including for the GitHub raw-file use case, without removing the existing default behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100