azure-sdk-for-cpp
azure-sdk-for-cpp copied to clipboard
C++ autorest generator tooling
Query/Question
What tooling is used to generate the code from the swagger specs?
I see comments about the generator, but don't see any evidence of the tool in the relevant azure sdk repos, nor the Autorest repo.
// Code generated by Microsoft (R) AutoRest C++ Code Generator.
There's an autorest config file in this readme
Why is this not a Bug or a feature Request?
We're using the Azure CPP SDK and investigating tooling options to generate CPP code from OpenAPI specs for other endpoints.
Setup (please complete the following information if applicable):
N/A
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [x] Query Added
- [x] Setup information Added
@jboelterintc to help understand your code generation and SDK need, we'd love to learn more about your scenario and use case here.
What are you using the "Azure CPP SDK" for currently (which libraries in particular are you using and which Azure services do you use), and what would you like to generate from the OpenAPI specs? Can you please share more details?
@ahsonkhan
I'm using the azure-storage-blobs-cpp library in an application to interact with the Azure blob store apis. This application also interacts with other REST APIs (unrelated to Azure) and I've been exploring the possibility of using the same code generation approach and the underlying Azure::Core::IO and Azure::Core::Http libraries from azure-core-cpp.
I would like to use the the autorest cpp generator that used by the Azure SDK, but as best I can tell, the autorest cpp plugin is not published.
A rough example of using the azure core library directly --
int main()
{
auto jsonObject = nlohmann::json::parse(R"(
{
"pi": 3.141,
"happy": true
}
)");
try {
// we need a transport to send the request
auto transport = std::make_shared<Azure::Core::Http::WinHttpTransport>();
// create a stream from the json object for the request body
auto jsonString = jsonObject.dump();
std::vector<uint8_t> jsonBytes(jsonString.begin(), jsonString.end());
Azure::Core::IO::MemoryBodyStream requestBody(jsonBytes);
// create a request and set the url, method, query parameters, and headers
const Azure::Core::Url& url {"http://localhost:8000/api/v1/test"};
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url, &requestBody);
request.GetUrl().AppendQueryParameter("param1", "value1");
request.SetHeader("Content-Type", "application/json");
request.SetHeader("Content-Length", std::to_string(requestBody.Length()));
request.SetHeader("User-Agent", "Test 1234");
// send our request
Azure::Core::Context context;
auto response = transport->Send(request, context);
auto status = response->GetStatusCode();
auto body = response->ExtractBodyStream()->ReadToEnd();
fmt::print("- - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
fmt::print("Status: {} {}\n", static_cast<int>(status), HttpStatusCodeToString(status));
fmt::print("Headers\n");
for(auto header: response->GetHeaders()) {
fmt::print(" {:<40}: {}\n", header.first, header.second);
}
fmt::print("Body\n");
fmt::print("{}\n", std::string(body.begin(), body.end()));
fmt::print("- - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n");
}
catch (const std::exception& e)
{
fmt::print("Error: {}\n", e.what());
}
return 0;
}
Thanks for sharing @jboelterintc.
The storage library uses a bespoke code generator which is specific to storage and won't be released publicly. There are no plans to release an OpenAPI based code generator for C++. Moving forward, we are focused on providing a C++ TypeSpec emitter for REST API code generation.
Hi @jboelterintc. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
Hi @jboelterintc, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.