dapperdox icon indicating copy to clipboard operation
dapperdox copied to clipboard

Defining an array response

Open jkeyes opened this issue 7 years ago • 4 comments

DapperDox Version 1.1.1

One of my endpoints returns an array of strings. I have defined the response as follows:

"responses": {
    "200": {
        "description": "",
        "schema": {
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    }
}

When I run dapperdox I get the following error: references a model definition that does not have a title member. If my response is an object with a title no errors are displayed.

Have I made an obvious mistake, or does DapperDox not support primitive array requests or responses?

Thanks.

jkeyes avatar Dec 15 '17 12:12 jkeyes

I enabled tracing and see that the array type is being found:

REMAP SCHEMA (Type is now [array string])

but the check for the Title is being made regardless of the array item type:

id := TitleToKebab(s.Title)

if len(fqNS) == 0 && id == "" {
    logger.Errorf(nil, "Error: %s %s references a model definition that does not have a title member.", strings.ToUpper(method.Method), method.Path)
    os.Exit(1)
}

jkeyes avatar Dec 15 '17 12:12 jkeyes

I've built the latest from source and am getting the same error for the petstore specification:

Go Version

$ go version
go version go1.9.2 linux/amd64

Go Env

$ go env
GOARCH="amd64"
GOBIN="/home/ubuntu/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ubuntu/go"
GORACE=""
GOROOT="/usr/lib/go-1.9"
GOTOOLDIR="/usr/lib/go-1.9/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build023144929=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Run Dapperdox

$ ~/go/bin/dapperdox -spec-dir=`pwd`/src/github.com/dapperdox/dapperdox/examples/specifications/petstore   -log-level=trace
2017/12/16 23:06:57 DapperDox server version 1.1.1 starting
2017/12/16 23:06:57 Configuration:
2017/12/16 23:06:57 	          BindAddr: localhost:3123
2017/12/16 23:06:57 	         AssetsDir:
2017/12/16 23:06:57 	  DefaultAssetsDir: assets
2017/12/16 23:06:57 	           SpecDir: /home/ubuntu/go/src/github.com/dapperdox/dapperdox/examples/specifications/petstore
2017/12/16 23:06:57 	      SpecFilename: [/swagger.json]
2017/12/16 23:06:57 	             Theme:
2017/12/16 23:06:57 	          ThemeDir:
2017/12/16 23:06:57 	          LogLevel: trace
2017/12/16 23:06:57 	           SiteURL: http://localhost:3123/
2017/12/16 23:06:57 	    SpecRewriteURL: []
2017/12/16 23:06:57 	DocumentRewriteURL: []
2017/12/16 23:06:57 	     ForceSpecList: %!s(bool=false)
2017/12/16 23:06:57 	        ShowAssets: %!s(bool=false)
2017/12/16 23:06:57 	         ProxyPath: []
2017/12/16 23:06:57 	    TLSCertificate:
2017/12/16 23:06:57 	            TLSKey:
2017/12/16 23:06:57 listening on localhost:3123
2017/12/16 23:06:57 Listen for and serve swagger spec requests for start up
2017/12/16 23:06:57 Registering specifications
2017/12/16 23:06:57 - Scanning base directory /home/ubuntu/go/src/github.com/dapperdox/dapperdox/examples/specifications/petstore
2017/12/16 23:06:57   - /home/ubuntu/go/src/github.com/dapperdox/dapperdox/examples/specifications/petstore/swagger.json
2017/12/16 23:06:57     = URL : /swagger.json
2017/12/16 23:06:57     + File: /home/ubuntu/go/src/github.com/dapperdox/dapperdox/examples/specifications/petstore/swagger.json
2017/12/16 23:06:57 Looking in default theme dir for assets/themes//status_codes.csv
2017/12/16 23:06:57 Looking in default theme assets/themes/default/status_codes.csv
2017/12/16 23:06:57 No status code map file found.
2017/12/16 23:06:57 Importing OpenAPI specifications from http://localhost:3123/swagger.json
2017/12/16 23:06:57 [XVlBzgbaiCMRAjWwhTHc] [trace] request started: 2017-12-16 23:06:57.720920641 +0000 UTC m=+0.093380962
2017/12/16 23:06:57 Serve file /swagger.json
2017/12/16 23:06:57 [XVlBzgbaiCMRAjWwhTHc] [trace] request completed: 2017-12-16 23:06:57.721073622 +0000 UTC m=+0.093533967
2017/12/16 23:06:57 [XVlBzgbaiCMRAjWwhTHc] [info] GET /swagger.json (200, 153.005µs)
2017/12/16 23:06:57 Parse OpenAPI specification 'Swagger Petstore'
2017/12/16 23:06:57   In tag loop...
2017/12/16 23:06:57     - Everything about your Pets
2017/12/16 23:06:57     In path loop...
2017/12/16 23:06:57   Operation tag length: 1
2017/12/16 23:06:57     > Check tags
2017/12/16 23:06:57       - Compare tag 'pet' with 'pet'
2017/12/16 23:06:57 Response for status 200
2017/12/16 23:06:57 resourceFromSchema: Schema type: [array]
2017/12/16 23:06:57 FQNS: []
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 got s.Items.Schema for Pet
2017/12/16 23:06:57 putting s.Type back
2017/12/16 23:06:57 REMAP SCHEMA (Type is now [array])
2017/12/16 23:06:57 Create resource pet
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 A call resourceFromSchema for property name
2017/12/16 23:06:57 resourceFromSchema: Schema type: primitive
2017/12/16 23:06:57 FQNS: [name]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Chopped name from myFQNS leaving []
2017/12/16 23:06:57 Create resource name
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property name type: string
2017/12/16 23:06:57 A call resourceFromSchema for property photoUrls
2017/12/16 23:06:57 resourceFromSchema: Schema type: [array]
2017/12/16 23:06:57 FQNS: [photoUrls]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 got s.Items.Schema for
2017/12/16 23:06:57 REMAP SCHEMA (Type is now [array string])
2017/12/16 23:06:57 Chopped photoUrls[] from myFQNS leaving []
2017/12/16 23:06:57 Create resource photoUrls[]
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property photoUrls type: array
2017/12/16 23:06:57 Processing an array property photoUrls
2017/12/16 23:06:57 A call resourceFromSchema for property status
2017/12/16 23:06:57 resourceFromSchema: Schema type: primitive
2017/12/16 23:06:57 FQNS: [status]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Chopped status from myFQNS leaving []
2017/12/16 23:06:57 Create resource status
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property status type: string
2017/12/16 23:06:57 A call resourceFromSchema for property tags
2017/12/16 23:06:57 resourceFromSchema: Schema type: [array]
2017/12/16 23:06:57 FQNS: [tags]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 got s.Items.Schema for Tag
2017/12/16 23:06:57 putting s.Type back
2017/12/16 23:06:57 REMAP SCHEMA (Type is now [array])
2017/12/16 23:06:57 Chopped tags[] from myFQNS leaving []
2017/12/16 23:06:57 Create resource tags[]
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 Append ID onto newFQNZ [] + 'tags[]'
2017/12/16 23:06:57 A call resourceFromSchema for property id
2017/12/16 23:06:57 resourceFromSchema: Schema type: primitive
2017/12/16 23:06:57 FQNS: [tags[] id]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Chopped id from myFQNS leaving [tags[]]
2017/12/16 23:06:57 Create resource id
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property id type: int64
2017/12/16 23:06:57 Append ID onto newFQNZ [] + 'tags[]'
2017/12/16 23:06:57 A call resourceFromSchema for property name
2017/12/16 23:06:57 resourceFromSchema: Schema type: primitive
2017/12/16 23:06:57 FQNS: [tags[] name]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Chopped name from myFQNS leaving [tags[]]
2017/12/16 23:06:57 Create resource name
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property name type: string
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property tags type: array
2017/12/16 23:06:57 Processing an array property tags
2017/12/16 23:06:57 A call resourceFromSchema for property category
2017/12/16 23:06:57 resourceFromSchema: Schema type: primitive
2017/12/16 23:06:57 FQNS: [category]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Got an object, so slicing category from resourceFQNS leaving [category]
2017/12/16 23:06:57 Create resource category
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 A call resourceFromSchema for property name
2017/12/16 23:06:57 resourceFromSchema: Schema type: primitive
2017/12/16 23:06:57 FQNS: [category name]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Chopped name from myFQNS leaving [category]
2017/12/16 23:06:57 Create resource name
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property name type: string
2017/12/16 23:06:57 A call resourceFromSchema for property id
2017/12/16 23:06:57 resourceFromSchema: Schema type: primitive
2017/12/16 23:06:57 FQNS: [category id]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Chopped id from myFQNS leaving [category]
2017/12/16 23:06:57 Create resource id
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property id type: int64
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property category type: object
2017/12/16 23:06:57 A call resourceFromSchema for property id
2017/12/16 23:06:57 resourceFromSchema: Schema type: primitive
2017/12/16 23:06:57 FQNS: [id]
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Chopped id from myFQNS leaving []
2017/12/16 23:06:57 Create resource id
2017/12/16 23:06:57 Call compileproperties...
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 resource property id type: int64
2017/12/16 23:06:57 resourceFromSchema done
2017/12/16 23:06:57 ++ Resource version latest  ID pet
2017/12/16 23:06:57    - Creating new resource
2017/12/16 23:06:57    - Resource origin is a response, so storing in global list
2017/12/16 23:06:57 Response for status 400
2017/12/16 23:06:57 Skipping /v2/pet/findByTags post - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/pet/findByTags put - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/pet/findByTags delete - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/pet/findByTags head - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/pet/findByTags options - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/pet/findByTags patch - Operation is nil.
2017/12/16 23:06:57     In path loop...
2017/12/16 23:06:57 Skipping /v2/user/createWithArray get - Operation is nil.
2017/12/16 23:06:57   Operation tag length: 1
2017/12/16 23:06:57     > Check tags
2017/12/16 23:06:57       - Compare tag 'pet' with 'user'
2017/12/16 23:06:57 Skipping /v2/user/createWithArray put - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/user/createWithArray delete - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/user/createWithArray head - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/user/createWithArray options - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/user/createWithArray patch - Operation is nil.
2017/12/16 23:06:57     In path loop...
2017/12/16 23:06:57 Skipping /v2/user/createWithList get - Operation is nil.
2017/12/16 23:06:57   Operation tag length: 1
2017/12/16 23:06:57     > Check tags
2017/12/16 23:06:57       - Compare tag 'pet' with 'user'
2017/12/16 23:06:57 Skipping /v2/user/createWithList put - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/user/createWithList delete - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/user/createWithList head - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/user/createWithList options - Operation is nil.
2017/12/16 23:06:57 Skipping /v2/user/createWithList patch - Operation is nil.
2017/12/16 23:06:57     In path loop...
2017/12/16 23:06:57 Skipping /v2/pet get - Operation is nil.
2017/12/16 23:06:57   Operation tag length: 1
2017/12/16 23:06:57     > Check tags
2017/12/16 23:06:57       - Compare tag 'pet' with 'pet'
2017/12/16 23:06:57 resourceFromSchema: Schema type: object
2017/12/16 23:06:57 FQNS: []
2017/12/16 23:06:57 CHECK schema type and items
2017/12/16 23:06:57 Error: POST /v2/pet references a model definition that does not have a title member.

jkeyes avatar Dec 16 '17 23:12 jkeyes

Sorry for the delay! We will try and reproduce what you are doing and point you in the right direction. We have specifications that have array responses, so we'll do a compare and see what is missing in your spec. The documentation probably needs updating - perhaps a crib-sheet should be added for common patterns.

Will be back soon!

zxchris avatar Jan 02 '18 11:01 zxchris

Seems to be the same issue as #79

paulduran avatar Jan 02 '18 14:01 paulduran