Skip to content

Commit

Permalink
Properly generate format for primitive types in OpenAPI specs (goades…
Browse files Browse the repository at this point in the history
  • Loading branch information
tchssk authored Jan 12, 2024
1 parent 1e3bc41 commit 8de12b8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion http/codegen/openapi/json_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ func initAttributeValidation(s *Schema, at *expr.AttributeExpr) {
return
}
s.Enum = val.Values
s.Format = string(val.Format)
if val.Format != "" {
s.Format = string(val.Format)
}
s.Pattern = val.Pattern
if val.ExclusiveMinimum != nil {
s.ExclusiveMinimum = val.ExclusiveMinimum
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"int","in":"body","required":true,"schema":{"type":"integer","minimum":0,"maximum":42}}],"responses":{"200":{"description":"OK response.","schema":{"type":"integer","minimum":0,"maximum":42}}},"schemes":["https"]}}}}
{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"int","in":"body","required":true,"schema":{"type":"integer","format":"int64","minimum":0,"maximum":42}}],"responses":{"200":{"description":"OK response.","schema":{"type":"integer","format":"int64","minimum":0,"maximum":42}}},"schemes":["https"]}}}}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ paths:
required: true
schema:
type: integer
format: int64
minimum: 0
maximum: 42
responses:
"200":
description: OK response.
schema:
type: integer
format: int64
minimum: 0
maximum: 42
schemes:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"post":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"integer","example":1,"minimum":0,"maximum":42},"example":1}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"integer","example":1,"minimum":0,"maximum":42},"example":1}}}}}}},"components":{},"tags":[{"name":"testService"}]}
{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"post":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"integer","example":1,"format":"int64","minimum":0,"maximum":42},"example":1}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"integer","example":1,"format":"int64","minimum":0,"maximum":42},"example":1}}}}}}},"components":{},"tags":[{"name":"testService"}]}
2 changes: 2 additions & 0 deletions http/codegen/openapi/v3/testdata/golden/integer_file1.golden
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ paths:
schema:
type: integer
example: 1
format: int64
minimum: 0
maximum: 42
example: 1
Expand All @@ -29,6 +30,7 @@ paths:
schema:
type: integer
example: 1
format: int64
minimum: 0
maximum: 42
example: 1
Expand Down
4 changes: 3 additions & 1 deletion http/codegen/openapi/v3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ func (sf *schemafier) schemafy(attr *expr.AttributeExpr, noref ...bool) *openapi
return s
}
s.Enum = val.Values
s.Format = string(val.Format)
if val.Format != "" {
s.Format = string(val.Format)
}
s.Pattern = val.Pattern
if val.ExclusiveMinimum != nil {
s.ExclusiveMinimum = val.ExclusiveMinimum
Expand Down

0 comments on commit 8de12b8

Please sign in to comment.