Skip to content

Commit

Permalink
add @Swagger to be backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
jiachengzz committed May 1, 2022
1 parent 542c28a commit 154bb08
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/SwaggerMarkdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ROOT = dirname(dirname(@__FILE__))

include("OpenAPI.jl")

export OpenAPI, build, @swagger_str, InvalidSwaggerSpecificationException
export OpenAPI, build, @swagger, @swagger_str, InvalidSwaggerSpecificationException

const DOCS = []

Expand All @@ -17,6 +17,11 @@ macro swagger_str(doc)
return esc(quote push!($m.DOCS, $doc) end)
end

macro swagger(doc)
m = @__MODULE__
return esc(quote push!($m.DOCS, $doc) end)
end

function build(spec::AbstractDict{<:AbstractString,<:Any})::Dict{String, Any}
spec_copy = spec
if !haskey(spec_copy, "paths")
Expand Down
34 changes: 34 additions & 0 deletions test/macro_build_tests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
@testset "Build directly through Dict with @swagger_str" begin
swagger"""
/test_swagger_str:
post:
description: Testing swagger markdown test!
responses:
'200':
description: Returns a mysterious string test.
"""

@swagger """
/test_swagger:
post:
description: Testing swagger markdown test!
responses:
'200':
description: Returns a mysterious string test.
"""

spec = Dict{String, Any}([
"info" => Dict{String, Any}([
"version" => "2.0",
"title" => "Swagger Petstore"
]),
"swagger" => "2.0"
])
spec = build(spec)
@test haskey(spec, "paths")

paths = spec["paths"];
@test haskey(paths, "/test_swagger")
@test haskey(paths, "/test_swagger_str")
end

@testset "Build directly through Dict" begin
@swagger """
/test:
Expand Down

2 comments on commit 154bb08

@essenciary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60518

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 154bb08de82e6831f582d3dcc2df6c49c15b9597
git push origin v0.2.0

Please sign in to comment.