You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In code generated by the cpprest client generator, we use the keyword inline is a query parameter, which is reserved in C++. By default, reserved keywords are escaped by prefixing them with an underscore.
Also, all identifiers that contain a double underscore __ in any position and each identifier that begins with an underscore followed by an uppercase letter is always reserved and all identifiers that begin with an underscore are reserved for use as names in the global namespace.
See the sample OpenAPI file below. When generating the cpprest client for this file, the signature for the generated GET /things call in DefaultApi.h looks like
On MSVC 14, this actually causes a compile failure:
DefaultApi.h(60): error C2735: 'inline' keyword is not permitted in formal parameter type specifier
openapi-generator version
4.2.2
OpenAPI declaration file content or url
openapi: 3.0.0info:
title: Inline APIversion: 0.0.1paths:
/things:
get:
summary: Returns a list of things.parameters:
- in: queryname: inlineschema:
type: booleandescription: Matches a keyword in C++.responses:
'200': # status codedescription: A JSON array of things.content:
application/json:
schema:
type: arrayitems:
type: string
Generate the cpp-restsdk client for the file given above.
Notice the underscores in the generated source.
Compile using msvc-14. The argument _inline is rejected.
Related issues/PRs
I found various language-specific escaping issues, but none which were directly relevant to this.
Suggest a fix
We were able to work around this using templates and the preprocessor. We added:
#define _inline r_inline
to the api-header.mustache template file, effectively replacing the keyword via the preprocessor before it gets compiled.
However, I believe the generator itself should be modified so that it escapes reserved words in a manner which does not conflict with C++ conventions. I opted for r_, but anything similar can be used.
I will post a PR immediately following this issue with this fix, although if you think there are any better alternatives, please let me know. I would be happy to adjust as needed. Thanks!
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
In code generated by the cpprest client generator, we use the keyword
inline
is a query parameter, which is reserved in C++. By default, reserved keywords are escaped by prefixing them with an underscore.This is documented as bad practice in C++, as there may still be conflicts with the global namespace:
See the sample OpenAPI file below. When generating the cpprest client for this file, the signature for the generated GET /things call in DefaultApi.h looks like
On MSVC 14, this actually causes a compile failure:
openapi-generator version
4.2.2
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
_inline
is rejected.Related issues/PRs
I found various language-specific escaping issues, but none which were directly relevant to this.
Suggest a fix
We were able to work around this using templates and the preprocessor. We added:
to the api-header.mustache template file, effectively replacing the keyword via the preprocessor before it gets compiled.
However, I believe the generator itself should be modified so that it escapes reserved words in a manner which does not conflict with C++ conventions. I opted for r_, but anything similar can be used.
I will post a PR immediately following this issue with this fix, although if you think there are any better alternatives, please let me know. I would be happy to adjust as needed. Thanks!
The text was updated successfully, but these errors were encountered: