Coder Social home page Coder Social logo

Swagger support? about pistache HOT 8 OPEN

pistacheio avatar pistacheio commented on August 15, 2024
Swagger support?

from pistache.

Comments (8)

sebymiano avatar sebymiano commented on August 15, 2024 4

I added the support for Pistache on swagger-codegen.
It generates a server stub using Pistache as C++ server library and Json for Modern C++ for JSON serialization/deserialization.

An example of the automatically generated code can be found here.

from pistache.

cyremur avatar cyremur commented on August 15, 2024

Yes, you have to build with rapidJSON installed.

Try the rest description example. There is a hard coded path to oktal's swagger installation. If you replace that with your local swagger distribution, the example builds a banking API stub and serves an API json and a swagger doc page.

from pistache.

jwmonaco avatar jwmonaco commented on August 15, 2024

I had two issues with this codegen support:

  1. The library name changed from Net to Pistache, so the generated code will not compile. This issue was already mentioned in 6278d88

  2. The simple swagger example below generates code that will not compile. I don't see any errors/warning coming from codegen.

swagger: '2.0'
info:
  version: "1.0"
  title: Testing
definitions:
  versionInfo:
    type: object
    properties:
      timestamp:
        type: string
paths:
  /version:
    get:
      operationId: versionInfo
      responses:
        200:
          description: OK
          schema:
            $ref: '#definitions/versionInfo'

The problem is the the generated code has an include of the form #include "#definitions/versionInfo.h". It should be #include "VersionInfo.h". Here's the commands I used after saving the above snippet as /tmp/tst.yml. Examine /tmp/swagger/DefaultApi.h to see the bad include.

sudo docker run -v /tmp:/tmp swaggerapi/swagger-codegen-cli generate -l pistache-server -o /tmp/swagger -i /tmp/tst.yml
[main] INFO io.swagger.parser.Swagger20Parser - reading from /tmp/tst.yml
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/model/VersionInfo.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/model/VersionInfo.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/api/DefaultApi.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/DefaultApiMainServer.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/api/DefaultApi.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/impl/DefaultApiImpl.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/impl/DefaultApiImpl.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/model/ModelBase.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/model/ModelBase.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/CMakeLists.txt
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/README.md
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tmp/swagger/.swagger-codegen/VERSION

from pistache.

sebymiano avatar sebymiano commented on August 15, 2024

@jwmonaco you missed a / in the $ref.
The right version is $ref: '#/definitions/versionInfo' instead of $ref: '#definitions/versionInfo'.
If you run swagger-codegen with this updated yaml file it works as expected.

Regarding the first issue, I have updated codegen with the new library name. I'll submit a PR soon.

from pistache.

jwmonaco avatar jwmonaco commented on August 15, 2024

D'oh. Thanks! Out of curiosity did you see that mistake by inspection or did you use a tool to validate the example? I thought it was OK since I didn't get any errors from code gen or editor saying my reference was bad. Seems like a tool should have pointed me towards my mistake.

from pistache.

sebymiano avatar sebymiano commented on August 15, 2024

@jwmonaco you're welcome :)
I didn't use any tool to validate it. Btw, the example you provided is compliant with the swagger syntax.

The $ref: '#definitions/versionInfo' is still a valid path but it doesn't reference the versionInfo object available under definitions since the full path should start with the /.

from pistache.

FranciscoGualdi avatar FranciscoGualdi commented on August 15, 2024

Hello all... I truing to get more info about the pistache description.
Is it generated the OAS specification based on the pistache endpoint?
Is it possible request the specification using the pistache endpoint? How should be the request?

Any information will be great!

from pistache.

dennisjenkins75 avatar dennisjenkins75 commented on August 15, 2024

Examine "examples/rest_description.cc"

In one terminal:

$ ./build/examples/run_rest_description 9999
Cores = 4
Using 2 threads

In other terminal:

$ curl -s http://localhost:9999/banker-api.json | head 
{
    "swagger": "2.0",
    "info": {
        "title": "Banking API",
        "version": "0.1"
    },
    "basePath": "/v1",
    "schemes": [
        "http"
    ],

from pistache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.