Coder Social home page Coder Social logo

Swagger / OpenAPI integration about rapidoid HOT 8 OPEN

rapidoid avatar rapidoid commented on May 22, 2024 24
Swagger / OpenAPI integration

from rapidoid.

Comments (8)

cnuonline avatar cnuonline commented on May 22, 2024

This is must for making using for Restful documentation and lamba services need quick documentation

from rapidoid.

picaron avatar picaron commented on May 22, 2024

Hi @nmihajlovski

This would be a really cool feature to add

I imagine you are really busy.

I would be open to contribute this PR following your guidelines/suggestions on how to tackle this.

from rapidoid.

nmihajlovski avatar nmihajlovski commented on May 22, 2024

Hi @picaron, that sounds great! Thanks for taking initiative on this.

For easy illustration of the requirements, let's start with the following example:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: An paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

(source: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml)

For the info and servers sections we could introduce a new configuration section openapi.

Of course, the paths section will be more challenging. The paths can be automatically generated from the routes, but some information is missing: summary, description, tags, operationId, parameters (partially) etc.

As a first step I propose a simple bootstrap of OpenAPI from the information already available in the routes (e.g. generating basic paths from Rapidoid's routes (the parameters and responses will be missing, until we find a proper way of modelling them). Some suggestions:

  • the OpenAPI / Swagger integration should ideally be implemented in a separate module rapidoid-openapi, similar to how it's done for the OAuth support,
  • for the bootstrap: App.bootstrap(args).openapi(),
  • basic configuration: openapi section (with corresponding Conf.OPENAPI) - useful for the info and servers elements of the spec.

I will try to find a proper way to model the parameters and responses...

Any feedback, questions and suggestions are welcome! :) Thanks again for helping with this one!

from rapidoid.

ddorian avatar ddorian commented on May 22, 2024

Any (fastest) library that does something like https://marshmallow.readthedocs.io and can be connected to both swagger/rapidoid/routes so it validates request/response and also builds the api-specification. Like you can integrate python(flask+marshmallow+webargs+swagger+apispec).

In this case I think only the routes would be from rapidoid and the other stuff from external modules (no need to reinvent request parsing + validation?).

Make sense ?

from rapidoid.

danielbraga avatar danielbraga commented on May 22, 2024

Hi @nmihajlovski,

How to get paths, methods and parameters?

Thanks

from rapidoid.

nmihajlovski avatar nmihajlovski commented on May 22, 2024

@danielbraga Thanks for the PR! I merged it into a new branch: openapi.

The routes can be accessed using On.setup().routes().allNonAdmin().

The tricky part would be accessing the parameters. I am going to add support for a generic (JSON-style) "schema" property that can be configured per route.

from rapidoid.

nmihajlovski avatar nmihajlovski commented on May 22, 2024

@danielbraga @picaron FYI:

  • I added meta-data model for the routes (RouteMeta),
  • I removed the template-based YAML generation (@danielbraga sorry for that). Instead, I implemented dynamic docs construction from RouteMeta into Java collections, which are then rendered as JSON or YAML.

Also, I merged the openapi branch into master. This is still work in progress, but the next release of Rapidoid will have early-access/experimental OpenAPI support.

Open issues:

  • smart construction of request/response data schema from Java types,
  • support for response headers.

from rapidoid.

nestoru avatar nestoru commented on May 22, 2024

Any possibility to actually make swagger the route definition holder? A DRY top down approach would ideally declare all of the below in swagger and only in swagger:

  1. Route definitions with references to endpoint executable code
  2. Validation of request payload against defined schema
  3. Validation of response payload [optional for those that favor response time over spec-conformity]

from rapidoid.

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.