Contributions
Re: Configurable option for generating body content in Post requests
I'm just using whatever codegen version is current on Swaggerhub, which I'm using for development. I exported the server stubs for plain "jaxrs", IIRC. Again, the strange part is that the whole operation works fine end-to-end if the body is included in the original request packet; it's when the body is sent in a separate packet that the API is just called with a "null" value for a required [body] parameter. I'm having some trouble accessing the API through Swaggerhub at the moment but the API definition (in the original yaml) for the Swagger 2.0 version of the API, was as follows: swagger: '2.0' info: version: '1.0' title: '...' ... HostSpec: type: object required: - host-id properties: host-id: type: string ... paths: /hosts: ... put: description: ... tags: - Host Management operationId: AddHost consumes: - application/json - application/xml produces: - application/json - application/xml parameters: - name: HostSpec description: ... in: body schema: $ref: '#/definitions/HostSpec' required: true responses: 200: description: Successful operation schema: $ref: '#/definitions/empty-success-response' ... Let me know if there's anything else of possible interest? Thanks a lot, -Patrick.1.7KViews0likes1CommentRe: Configurable option for generating body content in Post requests
Sure - I use a C++ tool using cpprest stubs generated from the same API. The calling code looks as follows (let me know if there are other parts of interest): std::shared_ptr<ApiConfiguration> apiConfig = std::make_shared<ApiConfiguration>(); apiConfig->setUserAgent("Agent-42"); apiConfig->setBaseUrl("http://XXX:8080/XXX/XXX-backend/1.0"); std::shared_ptr<ApiClient> apiClient = std::make_shared<ApiClient>(); apiClient->setConfiguration(apiConfig); std::shared_ptr<HostManagementApi> hostMgmtApi = std::make_shared<HostManagementApi>(apiClient); std::shared_ptr<HostSpec> hs = std::make_shared<HostSpec>(); hs->setHostId(hostID); pplx::task<std::shared_ptr<Empty_success_response>> requestTask = hostMgmtApi->addHost(hs); requestTask.then([=](pplx::task<std::shared_ptr<Empty_success_response>> task) { fprintf(stderr, "Task completed; collecting response...\n"); try { std::shared_ptr<Empty_success_response> response = task.get(); } catch (const std::exception &e) { printf("Error exception during task.get(): %s\n", e.what()); } });1.7KViews0likes0CommentsConfigurable option for generating body content in Post requests
Hi, I'm creating a simple REST service. I figured I'd use JAX-RS. I've generated my API and the documentation looks good. I'm having trouble modifying the generated JAX-RS code (I'm using Jersey/Jetty) to retrieve 'body' parameters properly. If they're sent in a single packet with the request, the stub is invoked OK. If the body comes in another packet, however, Jetty dispatches the call as soon as the headers are complete and my server stub is invoked with a "null" parameter that should've been retrieved from the HTTP body. Is there any good JAX-RS sample code that actually properly retrieves a 'body' parameter for use? Is there anything special my code needs to do if the passed function parameter is "null"? Am I supposed to be writing code to retrieve it from the body once that actually arrives, and block until then somehow? Any pointers to complete sample code (that don't just return"Magic!" without looking at the parameters...) would be much appreciated! Thanks! -Patrick.1.8KViews0likes5CommentsSwaggerhub-generated JAX-RS server stubs act as if "delayDispatchUntilContent" is false?
Hi, I'm experimenting with an API on SwaggerHub and I've generated both client-side (cpprest) and server-side (JAX-RS) stubs from the API. The strange part is that when I use a tool like Postman, which sends the complete request (headers and body) in a single packet, the server responds as expected but when I use the generated (cpprest) client stubs the request headers come in a first packet and the body in a second packet. They re-assemble fine (I can see a valid-looking combined packet in Wireshark) but it looks as if the server request is dispatched as soon as the headers arrive, without waiting for the body parameters to arrive (despite the "Content-length" header value). As a result the server sees a request that's got a "null" value for the body parameter (even though the parameter is marked as "required"), as if"delayDispatchUntilContent" is false? I've tried adding a "jetty.xml" file that explicitly defaults and sets "delayDispatchUntilContent" to "true" but that doesn't seem to make any difference. Any idea what I'm missing here? Any suggestions for a workaround, or a fix? Thanks in advance! -Patrick.1.3KViews0likes0Comments