DapperDox / dapperdox

Beautiful, integrated, OpenAPI documentation.
http://dapperdox.io
GNU General Public License v3.0
409 stars 59 forks source link

Unable to start the server / naming of $ref problem ? #84

Closed JLNNN closed 6 years ago

JLNNN commented 6 years ago

Hey,

I've got an issue when using your start script and it took me hours to find out what's the problem. Do you have an idea, WHY this is happening?

https://gist.github.com/JLNNN/fad9b3cd94017172921be71e96b01a67

The only differences in my example files is the naming of "definitions" and "defs" in the $ref.

I'm running the server with ./run_example.sh, this is my config:

#!/usr/bin/env bash
./dapperdox \
    -spec-dir=examples/specifications/petstore/ \
    -spec-filename=swagger.json \
    -bind-addr=0.0.0.0:3123 \
    -site-url=http://localhost:3123 \
    -spec-rewrite-url=petstore.swagger.io=PETSTORE.swagger.io \
    -log-level=trace \
    -force-specification-list=false \
    -theme=default  \
    #-tls-certificate=server.rsa.crt \
    #-tls-key=server.rsa.key \
    #-author-show-assets=true \
    #-assets-dir=./examples/overlay/assets \
    #-proxy-path=/developer=https://developer.some-dev-site.com

This is the output I get when using the not working json:

2018/03/22 16:15:50 DapperDox server version 1.2.2 starting
2018/03/22 16:15:50 Configuration:
2018/03/22 16:15:50               BindAddr: 0.0.0.0:3123
2018/03/22 16:15:50              AssetsDir: 
2018/03/22 16:15:50       DefaultAssetsDir: assets
2018/03/22 16:15:50                SpecDir: examples/specifications/petstore/
2018/03/22 16:15:50           SpecFilename: [swagger.json]
2018/03/22 16:15:50                  Theme: default
2018/03/22 16:15:50               ThemeDir: 
2018/03/22 16:15:50               LogLevel: trace
2018/03/22 16:15:50                SiteURL: http://localhost:3123
2018/03/22 16:15:50         SpecRewriteURL: [petstore.swagger.io=PETSTORE.swagger.io]
2018/03/22 16:15:50     DocumentRewriteURL: []
2018/03/22 16:15:50          ForceSpecList: %!s(bool=false)
2018/03/22 16:15:50             ShowAssets: %!s(bool=false)
2018/03/22 16:15:50              ProxyPath: []
2018/03/22 16:15:50         TLSCertificate: 
2018/03/22 16:15:50                 TLSKey: 
2018/03/22 16:15:50 listening on 0.0.0.0:3123
2018/03/22 16:15:50 Listen for and serve swagger spec requests for start up
2018/03/22 16:15:50 Registering specifications
2018/03/22 16:15:50 - Scanning base directory /Users/name/Downloads/dapperdox-1.2.2.darwin-amd64/examples/specifications/petstore
2018/03/22 16:15:50   - /Users/name/Downloads/dapperdox-1.2.2.darwin-amd64/examples/specifications/petstore/swagger.json
2018/03/22 16:15:50     = URL : /swagger.json
2018/03/22 16:15:50     + File: /Users/name/Downloads/dapperdox-1.2.2.darwin-amd64/examples/specifications/petstore/swagger.json
2018/03/22 16:15:50 Looking in default theme dir for assets/themes/default/status_codes.csv
2018/03/22 16:15:50 Processing HTTP status code file: assets/themes/default/status_codes.csv
2018/03/22 16:15:50 Serving specifications from 127.0.0.1:3123
2018/03/22 16:15:50 Importing OpenAPI specifications from http://127.0.0.1:3123/swagger.json
2018/03/22 16:15:50 [XVlBzgbaiCMRAjWwhTHc] [trace] request started: 2018-03-22 16:15:50.771582 +0100 CET
2018/03/22 16:15:50 Serve file /swagger.json
2018/03/22 16:15:50 [XVlBzgbaiCMRAjWwhTHc] [trace] request completed: 2018-03-22 16:15:50.771788 +0100 CET
2018/03/22 16:15:50 [XVlBzgbaiCMRAjWwhTHc] [info] GET /swagger.json (200, 206µs)
2018/03/22 16:15:50 Load specification error: object has no field "defs"

Greetings, Julian

zxchris commented 6 years ago

That error is coming from the internal OpenAPI parser (go-openapi).

The OpenAPI specification specifies that models appear in a definitions sub-document of the spec.

You have named this section defs, and while that may be valid JSON, it is not valid OpenAPI, so it will not have been recognised or imported as being part of an OpenAPI specification. So as far as the spec is concerned, you don't have any models defined (no definitions), and thus dereference #/defs/xxxxx leads to the error.