All Projects → immoh → swagger-spec

immoh / swagger-spec

Licence: EPL-1.0 license
Spec for Swagger 2.0 definition

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to swagger-spec

Openapi.tools
A collection of Editors, Linters, Parsers, Code Generators, Documentation, Testing
Stars: ✭ 257 (+1411.76%)
Mutual labels:  openapi, swagger2
swagger-converter
OpenAPI/Swagger 2.0 to OpenAPI 3.0 Converter WebService
Stars: ✭ 58 (+241.18%)
Mutual labels:  openapi, swagger2
Swagger to uml
Convert OpenAPI specifications (a.k.a. Swagger) to PlantUML diagrams
Stars: ✭ 144 (+747.06%)
Mutual labels:  openapi, swagger2
light-rest-4j
A RESTful framework built on top of light-4j with both Swagger 2.0 and OpenAPI 3.0 supports
Stars: ✭ 113 (+564.71%)
Mutual labels:  openapi, swagger2
Swag
Automatically generate RESTful API documentation with Swagger 2.0 for Go.
Stars: ✭ 5,173 (+30329.41%)
Mutual labels:  openapi, swagger2
Angular Swagger Ui
An angularJS implementation of Swagger UI
Stars: ✭ 131 (+670.59%)
Mutual labels:  openapi, swagger2
Slack Api Specs
Open API specifications for platform products by Slack
Stars: ✭ 148 (+770.59%)
Mutual labels:  openapi, swagger2
loopback-next
LoopBack makes it easy to build modern API applications that require complex integrations.
Stars: ✭ 4,412 (+25852.94%)
Mutual labels:  openapi
nestjs-asyncapi
NestJS AsyncAPI module - generate the documentation of your event-based services using decorators
Stars: ✭ 88 (+417.65%)
Mutual labels:  openapi
symmetric
A powerful tool to enable super fast module-to-API transformations. Learn in minutes, implement in seconds. Batteries included.
Stars: ✭ 65 (+282.35%)
Mutual labels:  openapi
reedelk-runtime
Reedelk Runtime Platform Community Edition
Stars: ✭ 25 (+47.06%)
Mutual labels:  openapi
daf-dataportal-backend
Backend per il nuovo frontend (in sviluppo) di dati.gov.it
Stars: ✭ 17 (+0%)
Mutual labels:  openapi
twitter-trend-analyzer
The trend analysis engine for a specific keyword of Twitter by using a graphical chart and geographical chart.
Stars: ✭ 20 (+17.65%)
Mutual labels:  openapi
openapi-definitions
OpenAPI Definitions
Stars: ✭ 30 (+76.47%)
Mutual labels:  openapi
starlite
Light, Flexible and Extensible ASGI API framework
Stars: ✭ 1,525 (+8870.59%)
Mutual labels:  openapi
cube
Common LISP Kubernetes Client
Stars: ✭ 33 (+94.12%)
Mutual labels:  openapi
mrapi
A framework for rapid development of API or DAL applications.
Stars: ✭ 20 (+17.65%)
Mutual labels:  openapi
intellij-openapi-generator
Intellij Plugin for openapi-generator
Stars: ✭ 73 (+329.41%)
Mutual labels:  openapi
arrest
Swagger REST framework for Node.js, with support for MongoDB and JSON-Schema
Stars: ✭ 17 (+0%)
Mutual labels:  openapi
sbt-lagom-descriptor-generator
Lagom API code generator
Stars: ✭ 23 (+35.29%)
Mutual labels:  openapi

swagger-spec Build Status Dependencies Status

A library that contains clojure.spec spec for Swagger (OpenAPI) definition version 2.0

Installation

Add the following dependency to your project file:

[swagger-spec "0.5.0"]

Usage

This library registers spec :swagger/definition which can be used for validation and data generation.

Generally map keys are required to be keywords except in certain places where integers (status code in Responses Object) and strings (path in Path Items object, mime type in Example Object) can also be used. This is to make it easier to avoid some pitfalls with keywords (e.g. first slash is treated as namespace separator.)

Validation

(ns example
  (:require [cheshire.core :as cheshire]
            [clojure.spec.alpha :as s]
            [swagger.spec]))

(s/valid? :swagger/definition (cheshire/parse-string (slurp "http://petstore.swagger.io/v2/swagger.json") true))
=> true

(s/explain :swagger/definition (-> (cheshire/parse-string (slurp "http://petstore.swagger.io/v2/swagger.json") true)
                                   (assoc :swagger "2.1")))
;; In: [:swagger] val: "2.1" fails spec: :swagger.definition/swagger at: [:swagger] predicate: #{"2.0"}
;; :clojure.spec.alpha/spec  :swagger/definition
;; :clojure.spec.alpha/value ...

Data Generation

The spec also allows test data to be generated for use with test.check:

(ns example2
  (:require [clojure.spec.alpha :as s]
            [clojure.spec.gen.alpha :as gen]
            [swagger.spec]))

(binding [s/*recursion-limit* 0]
  (first (gen/sample (s/gen :swagger/definition) 1)))
=> {:swagger "2.0"
    :info {:title "", :version "", :contact {:url ""}, :description "", :termsOfService ""}
    ...}

Unfortunately the resulting Swagger definition is 20k lines long pretty printed so I won't include it here. You can view the complete definition here.

I would have expected gen/sample to generate simpler definition, especially when recursion limit is set to 0. The default recursion limit of 4 causes OutOfMemoryError, the same happens if gen/generate is used instead of gen/sample.

Limitations

  • url field values are not validated to be in a format of a URL
  • email field values are not validated to be in a format of an email
  • Mime type values are not validated to be in a format of a mime type as described in RFC 6838
  • HTTP Status code values are not validated as described in RFC 7231 and IANA Status Code Registry
  • $ref field values are not validated to be valid JSON pointers
  • Path item object $ref field is not validated to point to a path item object
  • default field value is not validated to conform to the defined data type
  • XML object namespace values are not validated to be in a format of a URL
  • operationId value uniqueness is not validated
  • consumes field value is not validated to be either "multipart/form-data", "application/x-www-form-urlencoded" or both for file parameters
  • Names and locations of extension fields are not validated
  • Items object allows field description and validates it to be a string (not in specification)

There are probably many more aspects of specification that are missing and probably many that have been misunderstood. Some of the validations cannot be implemented using clojure.spec.

Contributing

If you would like to implement a missing validation or fix a misunderstood one, please file a pull request and I'll be more than happy to merge it.

License

Copyright © 2016 Immo Heikkinen

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].