swagger-api / swagger-api/swagger-codegen
[cpprest][C++] Why isn't the Base URL automatically set?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
In general, I think that what is written in yaml should be set automatically.
because There may be divergence between the specification and the code.
However, to use currently generated code, you have to set baseUrl manually.
I don't know why it isn't set Base URL automatically on generated code.
#include "api/api/PetApi.h"
using namespace io::swagger::client::api;
int main()
{
std::shared_ptr<ApiClient> apiClient(new ApiClient);
std::shared_ptr<ApiConfiguration> apiConfig(new ApiConfiguration);
apiConfig->setBaseUrl("http://petstore.swagger.io/v2"); ///<========== Why??
apiClient->setConfiguration(apiConfig);
PetApi api(apiClient);
api.getPetById(1).then([=](pplx::task<std::shared_ptr<Pet>> example) {
try {
std::cout << example.get()->getName() << '\n';
} catch(const std::exception& e) {
std::cout << "getExample() exception: " << e.what() << '\n';
}
}).wait();
}
swagger: '2.0'
info:
description: 'This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.'
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io <================== Why?
basePath: /v2
....
Suggest a fix/enhancement
I want to improve if there is a need, please support.
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 tracing the generated C++ client from PetApi.h and ApiConfiguration, then inspect how the Swagger YAML host and basePath are handled. The change is complete when generated clients use those specification values without requiring a manual setBaseUrl call; verify the behavior with the Petstore example shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100