Skip to content

Commit

Permalink
Generate empty schema for Any type (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Simon committed Nov 29, 2016
1 parent b61e25d commit de7cdac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion goagen/gen_schema/json_schema.go
Expand Up @@ -282,7 +282,9 @@ func TypeSchema(api *design.APIDefinition, t design.DataType) *JSONSchema {
s := NewJSONSchema()
switch actual := t.(type) {
case design.Primitive:
s.Type = JSONType(actual.Name())
if name := actual.Name(); name != "any" {
s.Type = JSONType(actual.Name())
}
switch actual.Kind() {
case design.UUIDKind:
s.Format = "uuid"
Expand Down
1 change: 1 addition & 0 deletions goagen/gen_swagger/goo.json
@@ -0,0 +1 @@
{"swagger":"2.0","info":{"title":"title","description":"description","termsOfService":"terms","contact":{"name":"contactName","email":"contactEmail@goa.design","url":"http://contactURL.com"},"license":{"name":"license","url":"http://licenseURL.com"},"version":""},"host":"host","basePath":"/base","schemes":["https"],"consumes":["application/json","application/xml","application/gob","application/x-gob"],"produces":["application/json","application/xml","application/gob","application/x-gob"],"paths":{"":{"put":{"tags":["res"],"summary":"act res","operationId":"res#act","parameters":[{"name":"payload","in":"body","required":true,"schema":{"$ref":"#/definitions/ActResPayload"}}],"schemes":["https"]}}},"definitions":{"ActResPayload":{"title":"ActResPayload","example":"a23550f5-e402-441c-8239-9707b25d3c8f"}},"tags":[{"name":"tag","description":"Tag desc.","externalDocs":{"description":"Huge docs","url":"http://example.com/tag"}}],"externalDocs":{"description":"doc description","url":"http://docURL.com"}}
21 changes: 21 additions & 0 deletions goagen/gen_swagger/swagger_test.go
Expand Up @@ -234,6 +234,27 @@ var _ = Describe("New", func() {
[]byte(`"required":true`),
})
})
})

Context("with a payload of type Any", func() {
BeforeEach(func() {
Resource("res", func() {
Action("act", func() {
Routing(
PUT("/"),
)
Payload(Any, func() {
Example("example")
})
})
})
})

It("serializes into valid swagger JSON", func() {
validateSwaggerWithFragments(swagger, [][]byte{
[]byte(`"ActResPayload":{"title":"ActResPayload","example":"example"}`),
})
})

})

Expand Down

0 comments on commit de7cdac

Please sign in to comment.