OxygenFramework / Oxygen.jl

💨 A breath of fresh air for programming web apps in Julia
https://oxygenframework.github.io/Oxygen.jl/
MIT License
383 stars 25 forks source link

Issue with build() Swagger #204

Closed BrandonEscamilla closed 2 weeks ago

BrandonEscamilla commented 3 weeks ago

When trying to use the mergeschema() function in Oxygen.jl, I followed the steps provided in the documentation but encountered the following error:

ERROR: LoadError: '\t'
Stacktrace:
  [1] fetch_more_tokens(stream::YAML.TokenStream)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/scanner.jl:281
  [2] peek(stream::YAML.TokenStream)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/scanner.jl:198
  [3] parse_block_mapping_value(stream::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/parser.jl:461
  [4] peek(stream::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/parser.jl:54
  [5] compose_node(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:93
  [6] __compose_mapping_node(event::YAML.ScalarEvent, composer::YAML.Composer, node::YAML.MappingNode)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:154
  [7] _compose_mapping_node(start_event::YAML.MappingStartEvent, composer::YAML.Composer, anchor::Nothing)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:174
  [8] compose_mapping_node(composer::YAML.Composer, anchor::Nothing)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:183
  [9] handle_event(event::YAML.MappingStartEvent, composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:86
 [10] compose_node(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:94
 [11] __compose_mapping_node(event::YAML.ScalarEvent, composer::YAML.Composer, node::YAML.MappingNode)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:154
 [12] _compose_mapping_node(start_event::YAML.MappingStartEvent, composer::YAML.Composer, anchor::Nothing)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:174
 [13] compose_mapping_node(composer::YAML.Composer, anchor::Nothing)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:183
 [14] handle_event(event::YAML.MappingStartEvent, composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:86
 [15] compose_node(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:94
 [16] compose_document(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:50
 [17] compose(events::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/composer.jl:38
 [18] load(ts::YAML.TokenStream, constructor::YAML.Constructor)
    @ YAML ~/.julia/packages/YAML/6ydWl/src/YAML.jl:38
 [19] load(ts::YAML.TokenStream, more_constructors::Nothing, multi_constructors::Dict{…}; dicttype::Type{…}, constructorType::typeof(YAML.SafeConstructor))
    @ YAML ~/.julia/packages/YAML/6ydWl/src/YAML.jl:44
 [20] load
    @ ~/.julia/packages/YAML/6ydWl/src/YAML.jl:44 [inlined]
 [21] load (repeats 3 times)
    @ ~/.julia/packages/YAML/6ydWl/src/YAML.jl:47 [inlined]
 [22] load
    @ ~/.julia/packages/YAML/6ydWl/src/YAML.jl:88 [inlined]
 [23] build(openApi::OpenAPI)
    @ SwaggerMarkdown ~/.julia/packages/SwaggerMarkdown/RFth0/src/SwaggerMarkdown.jl:40

Before invoking the serve() function and OpenAPI build() function, the routes are included in the main file using the following code: include("router/users.jl"). A folder named routers contains individual route definitions for the API.

# Include routers
include("routers/users.jl")
.
.
.
include("routers/orgs.jl")

# OpenAPI
openApi_version = "3.0"

# the info of the API, title and version of the info are required
info = Dict{String, Any}()
info["title"] = "My API"
info["version"] = "1.0.0"
openApi = OpenAPI(openApi_version, info)
@show openApi # -> openApi = OpenAPI("3.0", Dict{String, Any}("title" => "MyApi", "version" => "1.0.0"), Dict{String, Any}(), Dict{String, Any}())

swagger_document = build(openApi) # Here it fails 
ndortega commented 2 weeks ago

Hi @BrandonEscamilla,

Thanks for the error logs, the build() function comes from the SwaggerMarkdown.jl package. Based on this error it most likely means you have incorrect spacing somewhere in your custom yaml docs. I personally have encountered this error in the past - the spacing has to be perfect or else it throws an error.