openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[C++][Pistache-server] Help - How to write one server application that handles the full API ?

Open CyrilleBenard opened this issue 8 years ago • 9 comments

Description

I wonder how we are supposed to write one cpp-pistache server application that will handle the full API ? When I have a look to the petstore sample , I can find 3 "main example", so 3 different applications.

I mean PetApiMainServer.cpp, StoreApiMainServer.cpp and UserApiMainServer.cpp will each listen to the port 8080. How are we supposed to write ONE main application that will listen to the port 8080 and handle all the 3 API ? What would be the server instantiation ?

Many thanks in advance

openapi-generator version

N/A

OpenAPI declaration file content or url

N/A

Command line used for generation

N/A

Steps to reproduce

N/A

Related issues/PRs

N/A

Suggest a fix/enhancement

N/A

CyrilleBenard avatar Jul 12 '18 14:07 CyrilleBenard

Have you found a solution? If not I could check this weekend.

etherealjoy avatar Jul 18 '18 06:07 etherealjoy

No solution right now. I'm surprised that the generator (cpp-pistache lang) seems to produce a code with ONE "http end point" per operationId (openapi v3 syntax)). This implies a "listen" on each operationId so, I wonder how we are supposed to develop one application that listen onto only one http port to handle every operationId :open_mouth:

CyrilleBenard avatar Jul 18 '18 08:07 CyrilleBenard

I was a little wrong : The "HTTP End point" (ie listened port) is not defined by the operationId keyword but by the keyword tags that will produce a one to one relationship between class and tags.

A workaround to embed all the API inside the same application would be to define every path/operationId with the same tags list, so that the generator will produce only ONE api class and so, only one "HTTP End point" but that also means "bye bye" the split class architecture like Pet, Store and User.

This is a workaround, not a nice solution I think. We should be able to define several API, so several classes but one HTTP End point. If I am not wrong, there not the same issue in, at least, Java ?

CyrilleBenard avatar Jul 18 '18 12:07 CyrilleBenard

The issue is there only for pistache. Others don't have this problem. This is due to the inheritance pattern used. But it can be solved.

etherealjoy avatar Jul 23 '18 08:07 etherealjoy

@CyrilleBenard To solve this; In the Api class the following members should be std::shared_ptr

    Pistache::Http::Endpoint httpEndpoint;
    Pistache::Rest::Router router;

The Api class has to accept these members in the constuctor They need to be constructed outside in a single file hosting the ApiMainServer function. Pass the same router and endpoint to all Api classes from the same spec.

etherealjoy avatar Aug 04 '18 19:08 etherealjoy

@stkrwork @wing328 Is this something we should do? I mean the Pistache server is probably the only server with three separate binary to run the PetStore sample. I have some idea to do this.

etherealjoy avatar Aug 28 '18 13:08 etherealjoy

I'm interested in a fix to this "pretty wrong" behavior but I'm also interested in some prior features that makes the compilation fail, for example bug issue 257 638 768 773 Of course 372, that seems to be in development, 537 are majors features that I follow.

Indeed, this current bug issue shows a strange behavior of the generator and probably, as you said @etherealjoy , it may be the only server stub that behaves like this. From my point of view, its not yet a prior fix but I'm really interested in a "uniform" behavior regarding the others server stubs. If its not a heavy development you can describes what you think about :+1:

EDIT: Delete the #xxx to avoid cross reference on each bug issue mentioned above. Sorry for that

CyrilleBenard avatar Aug 29 '18 07:08 CyrilleBenard

@etherealjoy could you expose or better, modify the Pistache integration to got a uniform behavior between all languages ? I mean, avoid the specific Pistache mapping "One Tag list" => "One End point" as explained previously. It would be nice to have this feature and obviously, more usable.

CyrilleBenard avatar Oct 12 '18 09:10 CyrilleBenard

@CyrilleBenard Please try out #1230 to see this feature

etherealjoy avatar Oct 12 '18 20:10 etherealjoy