Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(pkg/openapi3) Support schema in openapi3 format #136

Merged
merged 3 commits into from
Oct 19, 2020

Conversation

azzz
Copy link
Contributor

@azzz azzz commented Oct 1, 2020

This PR introduces support for OpenAPI3 schema specifications. OpenAPI3 services/endpoints are not included due to OpenAPI3 implementation.

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2020

Codecov Report

Merging #136 into master will increase coverage by 0.01%.
The diff coverage is 63.35%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #136      +/-   ##
==========================================
+ Coverage   82.14%   82.15%   +0.01%     
==========================================
  Files         125      132       +7     
  Lines        5483     5907     +424     
==========================================
+ Hits         4504     4853     +349     
- Misses        664      723      +59     
- Partials      315      331      +16     
Impacted Files Coverage Δ
pkg/generators/openapi3/generator.go 90.83% <ø> (ø)
pkg/generators/openapi3/types/types.go 100.00% <ø> (ø)
pkg/specs/types/types.go 100.00% <ø> (ø)
pkg/providers/openapi3/schema.go 53.57% <53.57%> (ø)
pkg/providers/openapi3/resolver.go 76.92% <76.92%> (ø)
pkg/providers/hcl/hcl.go 81.98% <100.00%> (+1.02%) ⬆️
pkg/specs/template.go 76.00% <100.00%> (+1.00%) ⬆️
pkg/codec/xml/encode.go 56.52% <0.00%> (-18.48%) ⬇️
pkg/codec/xml/scalar.go 96.36% <0.00%> (-3.64%) ⬇️
pkg/codec/xml/enum.go 96.66% <0.00%> (-3.34%) ⬇️
... and 22 more

@azzz azzz force-pushed the feat/openapi-schemas-support branch from fbad000 to 8be015b Compare October 1, 2020 18:22
@azzz azzz changed the title (pkg/openapi3) Basic support of primitive types (pkg/openapi3) Support schema in openapi3 format Oct 2, 2020
@jeroenrinzema jeroenrinzema added the enhancement New feature or request label Oct 3, 2020
@azzz azzz force-pushed the feat/openapi-schemas-support branch 2 times, most recently from 83a230c to d0cfa0c Compare October 8, 2020 13:25
@azzz azzz marked this pull request as ready for review October 8, 2020 13:25
@codecov-io
Copy link

codecov-io commented Oct 8, 2020

Codecov Report

Merging #136 into master will decrease coverage by 0.46%.
The diff coverage is 66.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #136      +/-   ##
==========================================
- Coverage   82.70%   82.23%   -0.47%     
==========================================
  Files         141      144       +3     
  Lines        6204     6385     +181     
==========================================
+ Hits         5131     5251     +120     
- Misses        725      761      +36     
- Partials      348      373      +25     
Impacted Files Coverage Δ
pkg/generators/openapi3/generator.go 90.83% <ø> (ø)
pkg/generators/openapi3/types/types.go 100.00% <ø> (ø)
pkg/specs/types/types.go 100.00% <ø> (ø)
pkg/providers/openapi3/resolver.go 54.54% <54.54%> (ø)
pkg/providers/openapi3/schema.go 65.90% <65.90%> (ø)
pkg/providers/openapi3/scanner.go 69.23% <69.23%> (ø)
pkg/providers/hcl/hcl.go 81.98% <100.00%> (+1.02%) ⬆️
pkg/specs/template.go 76.00% <100.00%> (+1.00%) ⬆️
... and 1 more

@azzz azzz requested a review from jeroenrinzema October 13, 2020 07:33
Copy link
Contributor

@jeroenrinzema jeroenrinzema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, I got a couple of comments regarding schema types.

pkg/providers/openapi3/schema.go Outdated Show resolved Hide resolved
Comment on lines 119 to 141
func scalar(s *openapi.Schema) (specs.Template, error) {
var t types.Type

switch s.Type {
case "string":
t = types.String
case "boolean":
t = types.Bool
case "number":
t = types.Float
case "integer":
t = types.Int32
default:
return specs.Template{}, fmt.Errorf("unknown type %s", s.Type)
}

return specs.Template{
Scalar: &specs.Scalar{Type: t},
}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could easily add add support default types fetched from openapi.Schema.

default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, if type is string, then default can be "foo" but cannot be 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I supported default for scalar types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*I just supported, pls take a look at the commit.

@azzz azzz force-pushed the feat/openapi-schemas-support branch from f3aad11 to dc2d7d7 Compare October 15, 2020 11:21
@azzz azzz force-pushed the feat/openapi-schemas-support branch from dc2d7d7 to f484121 Compare October 15, 2020 11:38
@azzz azzz merged commit ccc79a1 into jexia:master Oct 19, 2020
@azzz azzz deleted the feat/openapi-schemas-support branch October 19, 2020 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants