Skip to content

Commit

Permalink
refactor Delete response according to specification (grpc-ecosystem#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliaksei Burau authored Nov 6, 2018
1 parent 94a2d0d commit e72d763
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Empty file added Dockerfile
Empty file.
39 changes: 29 additions & 10 deletions protoc-gen-swagger/genswagger/atlas_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ The service-defined string used to identify a page of resources. A null value in
schema.Properties = map[string]spec.Schema{}
}

def := sw.Definitions[trim(rsp.Schema.Ref)]
successSchema := map[string]spec.Schema{
"status": *spec.StringProperty().WithExample(opToStatus(on)),
"code": *spec.Int32Property().WithExample(opToCode(on)),
"message": *spec.StringProperty().WithExample("<response message>"),
}

def := sw.Definitions[trim(rsp.Schema.Ref)]
for fn, v := range def.Properties {
if v.Ref.String() == "#/definitions/apiPageInfo" {
successSchema["_offset"] = *spec.Int32Property().WithExample(5).
Expand All @@ -178,22 +178,41 @@ The service-defined string used to identify a page of resources. A null value in
break
}
}

delete(sw.Definitions, "apiPageInfo")
if rsp.Description == "" {
rsp.Description = on + " operation response"
}

switch on {
case "DELETE":
if len(def.Properties) == 0 {
rsp.Description = "No Content"
rsp.Schema = nil
op.Responses.StatusCodeResponses[opToCode(on)] = rsp
delete(sw.Definitions, trim(rsp.Ref))
delete(op.Responses.StatusCodeResponses, 200)
break
}

schema.Properties["success"] = *(&spec.Schema{}).WithProperties(successSchema)
schema.Properties["success"] = *(&spec.Schema{}).WithProperties(successSchema)

sw.Definitions[trim(rsp.Schema.Ref)] = schema
sw.Definitions[trim(rsp.Schema.Ref)] = schema

refs = append(refs, rsp.Schema.Ref)
refs = append(refs, rsp.Schema.Ref)

delete(op.Responses.StatusCodeResponses, 200)
op.Responses.StatusCodeResponses[200] = rsp
default:
schema.Properties["success"] = *(&spec.Schema{}).WithProperties(successSchema)

if rsp.Description == "" {
rsp.Description = on + " operation response"
}
sw.Definitions[trim(rsp.Schema.Ref)] = schema

refs = append(refs, rsp.Schema.Ref)

op.Responses.StatusCodeResponses[opToCode(on)] = rsp
delete(op.Responses.StatusCodeResponses, 200)

op.Responses.StatusCodeResponses[opToCode(on)] = rsp
}
}
}

Expand Down

0 comments on commit e72d763

Please sign in to comment.