swagger-api / swagger-api/swagger-codegen
[C++] [pistache] Code generation for Pistache leads to uncompilable code
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I can generate a server with 1 API with json model classes which is fine, but when I add the code snippet put in later section of the bugreport, the generated .cpp file doesn't compile:
In file included from /server/impl/DefaultApiImpl.h:28:0,
from /server/DefaultApiMainServer.cpp:16:
/server/api/DefaultApi.h:33:38: error: ‘model’ is not a namespace-name
using namespace io::swagger::server::model;
^~~~~
/server/api/DefaultApi.h:33:43: error: expected namespace-name before ‘;’ token
using namespace io::swagger::server::model;
^
In file included from /server/DefaultApiMainServer.cpp:16:0:
/server/impl/DefaultApiImpl.h:36:38: error: ‘model’ is not a namespace-name
using namespace io::swagger::server::model;
^~~~~
/server/impl/DefaultApiImpl.h:36:43: error: expected namespace-name before ‘;’ token
using namespace io::swagger::server::model;
^
make[2]: *** [server/CMakeFiles/default_api_server.dir/DefaultApiMainServer.cpp.o] Error 1
make[1]: *** [server/CMakeFiles/default_api_server.dir/all] Error 2
From what I gather, this 'default' handler that should return HTML doesn't use any model and therefore the header for the model isn't included, but the "using namespace" is however generated (which is a bad idea for a header file BTW, but that is a different issue)
Swagger-codegen version
2.4.0-SNAPSHOT
Swagger declaration file content or url
'/':
get:
summary: Returns the webapp
produces:
- text/html
responses:
200:
description: Returns the webapp
examples:
text/html:
<html><body>Main webapp</body></html>
Command line used for generation
java -jar ../swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -v -i swagger.yaml -l pistache-server -o server
Suggest a fix/enhancement
Probably an issue in the mustache templates ?
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
Run the supplied swagger-codegen command and inspect the generated DefaultApi.h, DefaultApiImpl.h, and DefaultApiMainServer.cpp alongside the Pistache mustache templates. Confirm the model namespace is referenced without its header when the HTML handler uses no model, then verify the generated server compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100