Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Oapi Codegen | 4,130 | 1,002 | 7 hours ago | 89 | August 07, 2023 | 409 | apache-2.0 | Go | ||
Generate Go client and server boilerplate from OpenAPI 3 specifications | ||||||||||
Openapi Typescript | 3,562 | 239 | a day ago | 90 | August 14, 2023 | 41 | mit | TypeScript | ||
Generate TypeScript types from OpenAPI 3 specs | ||||||||||
Drf Yasg | 3,165 | 290 | 91 | 19 days ago | 62 | July 20, 2023 | 242 | other | Python | |
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code. | ||||||||||
Graphql Mesh | 2,976 | 82 | 10 hours ago | 1,625 | September 26, 2022 | 187 | mit | TypeScript | ||
GraphQL Mesh — Query anything, run anywhere | ||||||||||
Schemathesis | 1,846 | 4 | 3 days ago | 229 | August 14, 2023 | 134 | mit | Python | ||
Guarantee flawless API functionality with thorough, high-quality test scenarios generated from your API specification. | ||||||||||
Datamodel Code Generator | 1,838 | 54 | 21 hours ago | 172 | August 09, 2023 | 106 | mit | Python | ||
Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources. | ||||||||||
Drf Spectacular | 1,833 | 53 | 3 days ago | 60 | July 23, 2023 | 64 | bsd-3-clause | Python | ||
Sane and flexible OpenAPI 3 schema generation for Django REST framework. | ||||||||||
Compojure Api | 1,094 | 265 | 7 months ago | 135 | January 16, 2018 | 37 | epl-1.0 | Clojure | ||
Sweet web apis with Compojure & Swagger | ||||||||||
Sofa | 1,007 | 5 | 11 | 5 days ago | 47 | September 13, 2023 | 50 | mit | TypeScript | |
The best way to create REST APIs - Generate RESTful APIs from your GraphQL Server | ||||||||||
Swagger To Graphql | 893 | 28 | 6 | 10 months ago | 47 | October 02, 2019 | 35 | mit | TypeScript | |
Swagger to GraphQL API adapter |
Build a GraphQL schema from a given Swagger or Open API specification.
To install swagql as devDependency run:
npm i -D swagql
cat swagger.yml | npx swagql [-p <babel-plugin1-path>,<babel-plugin2-path>] [-n NamePrefix_]> schema.js
Input swagger schema can be in YAML or JSON format. The generated schema exports
a schema
object and two symbols FETCH
and VERIFY_AUTH_STATUS
. These
symbols should reside in the context
used while creating the GraphQL server.
The definition of VERIFY_AUTH_STATUS
symbol is optional. It is used to check
the authorization status for given request and swagger auth config. If a given
request does not satisfy the required auth status, you can throw an auth error
from this function. requestContext
can be used to hold the information about
the current request, such as the request object itself.
In the case where you are merging multiple schemas, you may wish to have all
of the methods and types be unique, and can pass the --name-prefix
(or -n
)
flag to prepend the given string to all of the above.
const { schema, FETCH, VERIFY_AUTH_STATUS } = require(pathToSchema);
function verifyAuthStatus(requestContext, authConfig) {
// verify if current request satisfies authConfig for the given endpoint.
// if not, throw an auth error.
}
const context = {
[FETCH]: apiClient.fetch,
[VERIFY_AUTH_STATUS]: verifyAuthStatus.bind(null, request),
};
Use schema and context in your app
const { graphql } = require('graphql');
graphql(schema, query, context)
.then(result => console.log(result));
If given REST API response includes lists, we need to add page info and edge connection cursors to handle pagination in GraphQL.
To handle this, the generated schema looks for convertArrayToConnection
and
parseCursorOptions
function definitions in ./array-to-connection.js
. SwagQL
provides a default implementation for array-to-connection. If your APIs return
pagination information in the response, the default implementation can be used
as follows:
// array-to-connection.js
module.exports = require('swagql/array-to-connection');
If your API responses handle pagination differently, you may have to customize array-to-connection implementation.
test/fixtures/petstore.json
is taken from https://petstore.swagger.io/v2/swagger.json