-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
134 additions
and
42 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
local types = require("@server/openapi/types") | ||
|
||
type Object<T> = types.Object<T> | ||
|
||
local function createLuauComment(object: Object<any>): string? | ||
local comment = {} | ||
if object.summary then | ||
table.insert(comment, `-- {object.summary}`) | ||
end | ||
if object.summary and object.description then | ||
table.insert(comment, "--") | ||
end | ||
if object.description then | ||
table.insert(comment, `-- {object.description}`) | ||
end | ||
if #comment > 0 then | ||
return table.concat(comment, "\n") | ||
else | ||
return nil | ||
end | ||
end | ||
|
||
return createLuauComment |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local fs = require("@lune/fs") | ||
local serde = require("@lune/serde") | ||
local openapiTypes = require("@server/openapi/openapi31") | ||
local createLuauComment = require("./createLuauComment") | ||
|
||
type OpenAPIObject = openapiTypes.OpenAPIObject | ||
|
||
local api: OpenAPIObject = serde.decode("yaml", fs.readFile("server/src/openapi/mocks/commented-schema.yml")) | ||
|
||
local comment = createLuauComment(api.components.schemas.SummaryAndDescription) | ||
local expected = [[-- A short summary | ||
-- | ||
-- A long-form description of the schema]] | ||
|
||
assert(comment, "no comment created") | ||
assert(comment == expected, "comment doesn't match expectation\ncomment: {comment}\nexpected: {expected}") | ||
|
||
comment = createLuauComment(api.components.schemas.SummaryOnly) | ||
expected = "-- A short summary" | ||
|
||
assert(comment, "no comment created") | ||
assert(comment == expected, "comment doesn't match expectation\ncomment: {comment}\nexpected: {expected}") | ||
|
||
comment = createLuauComment(api.components.schemas.DescriptionOnly) | ||
expected = "-- A long-form description of the schema" | ||
|
||
assert(comment, "no comment created") | ||
assert(comment == expected, "comment doesn't match expectation\ncomment: {comment}\nexpected: {expected}") | ||
|
||
comment = createLuauComment(api.components.schemas.Empty) | ||
assert(comment == nil, "a comment was created when it shouldn't have been") |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
openapi: 3.1.0 | ||
|
||
info: | ||
title: Title | ||
description: Description | ||
version: 1.0.0 | ||
basePath: /v1 | ||
|
||
components: | ||
schemas: | ||
SummaryAndDescription: | ||
summary: "A short summary" | ||
description: "A long-form description of the schema" | ||
|
||
SummaryOnly: | ||
summary: "A short summary" | ||
|
||
DescriptionOnly: | ||
description: "A long-form description of the schema" | ||
|
||
Empty: | ||
foo: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type Object<T> = { [string]: T } | ||
|
||
export type LuauType = { | ||
name: string, | ||
body: Primitive | { [string]: Primitive }, | ||
comment: string?, | ||
unions: { string }?, | ||
isExported: boolean?, | ||
isRequired: boolean?, | ||
} | ||
|
||
return {} |