Skip to content

mattpolzin/VaporOpenAPIExample

Repository files navigation

VaporOpenAPIExample

This example shows off an early stage project to both add type information to Vapor requests/responses and also take advantage of that information to generate OpenAPI documentation.

Note that this app and the libraries it showcases are built off of Vapor 4.

The example app serves up OpenAPI documentation on itself using the beautiful Redoc viewer.

The OpenAPI document produced is compatible with the OpenAPI specification v3.1.x.

Documentation served by example app

The OpenAPI it produces contains (among other things) routes, path and query parameters, and success and error responses including response body schemas.

openapi: 3.1.1info: title: Vapor OpenAPI Example APIdescription: '## Descriptive Text This text supports _markdown_!'version: '1.0'servers: - url: https://127.0.0.1paths: /docs: get: tags: - Documentationsummary: View API Documentationdescription: API Documentation is served using the Redoc web app.responses: 200: description: OKcontent: text/html: schema: type: string/docs/openapi.yml: get: tags: - Documentationsummary: Download API Documentationdescription: Retrieve the OpenAPI documentation as a YAML file.responses: 200: description: OKcontent: application/x-yaml: schema: type: string/hello: get: tags: - Greetingssummary: View a greetingdescription: Say hello in one of the supported languages!parameters: - name: languagein: queryschema: type: stringenum: - english - spanishresponses: 200: description: OKcontent: application/json: schema: type: objectproperties: language: type: stringenum: - english - spanishgreeting: type: stringrequired: - language - greeting400: description: Bad Requestcontent: text/plain: schema: type: stringpost: tags: - Greetingssummary: Create a greetingdescription: The endpoint is not actually implemented. It is just mocked up.requestBody: content: application/json: schema: type: objectproperties: language: type: stringenum: - english - spanishgreeting: type: stringrequired: - language - greetingresponses: 201: description: Createdcontent: application/json: schema: type: objectproperties: language: type: stringenum: - english - spanishgreeting: type: stringrequired: - language - greetingdelete: tags: - Greetingssummary: Delete a greetingresponses: 204: description: No Content

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published