-
-
Save m-o-e/74f7f64c26a743387bb6ef5e08c53ce5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Lux::OpenApi | |
# https://www.youtube.com/watch?v=mNz6eHfsESQ | |
SKELETON = { | |
openapi: "3.0.3", | |
info: { | |
title: "API - Powered by Lux", | |
description: ["For justice, and all things bright!", "Home is where the spark is."].shuffle.first, | |
termsOfService: "https://example.com/terms", | |
contact: { | |
name: "API Support", | |
url: "https://example.com/support/", | |
email: "support@example.com" | |
}, | |
license: { | |
"name": "Apache 2.0", | |
"url": "https://www.apache.org/licenses/LICENSE-2.0.html" | |
}, | |
"version": "1.0.1" | |
}, | |
servers: [ | |
{ | |
"url": "/", | |
"description": "Home is where the spark is." | |
} | |
], | |
paths: {} of String => String, | |
components: {} of String => String, | |
security: {} of String => String, | |
tags: {} of String => String, | |
externalDocs: {} of String => String, | |
} | |
class_getter doc : AnyHash::JSON = SKELETON.to_any_json | |
def to_json | |
@@doc.to_json | |
end | |
end | |
# in endpoint creator macro... | |
Lux::OpenApi.doc.merge!({ | |
"paths" => { | |
{{path}} => { | |
{{method.downcase}} => { | |
"summary" => {{summary}}, | |
"description" => {{description}}, | |
"tags" => {{tags}}, | |
"operationId" => "{{method.capitalize.id}}{{path.camelcase.id.gsub(/[^A-z]/, "_")}}" | |
# parameters: // populated in `params` macros | |
# requestBody: // populated in `response` macro | |
# responses: // // populated in `response` macro | |
# deprecated: // todo | |
# security: // todo | |
} | |
} | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment