Skip to content

Commit

Permalink
Fix collection of components when there are multiple protobuf files w…
Browse files Browse the repository at this point in the history
…ith gnostic options
sudorandom committed Sep 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7ce64e7 commit c1a33f7
Showing 49 changed files with 457 additions and 108 deletions.
1 change: 0 additions & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -14,5 +14,4 @@ plugins:
strategy: all
opt:
# - base=base.yaml
- format=json
- path=openapi.yaml
15 changes: 15 additions & 0 deletions examples/basic.proto
Original file line number Diff line number Diff line change
@@ -30,6 +30,21 @@ option (gnostic.openapi.v3.document) = {
url: "https://github.com/sudorandom/protoc-gen-connect-openapi/blob/master/LICENSE"
}
}
components: {
security_schemes: {
additional_properties: [
{
name: "BasicAuth"
value: {
security_scheme: {
type: "http"
scheme: "basic"
}
}
}
]
}
}
};

// The greeting service definition.
33 changes: 2 additions & 31 deletions internal/converter/converter.go
Original file line number Diff line number Diff line change
@@ -248,40 +248,14 @@ func specToFile(opts options.Options, spec *v3.Document) (string, error) {
}

func appendToSpec(opts options.Options, spec *v3.Document, fd protoreflect.FileDescriptor) error {
spec = gnostic.SpecWithFileAnnotations(spec, fd)
gnostic.SpecWithFileAnnotations(spec, fd)
components, err := fileToComponents(opts, fd)
if err != nil {
return err
}
initializeDoc(spec)
initializeComponents(components)
for pair := components.Schemas.First(); pair != nil; pair = pair.Next() {
spec.Components.Schemas.Set(pair.Key(), pair.Value())
}
for pair := components.Responses.First(); pair != nil; pair = pair.Next() {
spec.Components.Responses.Set(pair.Key(), pair.Value())
}
for pair := components.Parameters.First(); pair != nil; pair = pair.Next() {
spec.Components.Parameters.Set(pair.Key(), pair.Value())
}
for pair := components.Examples.First(); pair != nil; pair = pair.Next() {
spec.Components.Examples.Set(pair.Key(), pair.Value())
}
for pair := components.RequestBodies.First(); pair != nil; pair = pair.Next() {
spec.Components.RequestBodies.Set(pair.Key(), pair.Value())
}
for pair := components.Headers.First(); pair != nil; pair = pair.Next() {
spec.Components.Headers.Set(pair.Key(), pair.Value())
}
for pair := components.SecuritySchemes.First(); pair != nil; pair = pair.Next() {
spec.Components.SecuritySchemes.Set(pair.Key(), pair.Value())
}
for pair := components.Links.First(); pair != nil; pair = pair.Next() {
spec.Components.Links.Set(pair.Key(), pair.Value())
}
for pair := components.Callbacks.First(); pair != nil; pair = pair.Next() {
spec.Components.Callbacks.Set(pair.Key(), pair.Value())
}
util.AppendComponents(spec, components)

pathItems, err := fileToPathItems(opts, fd)
if err != nil {
@@ -323,9 +297,6 @@ func initializeDoc(doc *v3.Document) {
if doc.Security == nil {
doc.Security = []*base.SecurityRequirement{}
}
if doc.ExternalDocs == nil {
doc.ExternalDocs = &base.ExternalDoc{}
}
if doc.Extensions == nil {
doc.Extensions = orderedmap.New[string, *yaml.Node]()
}
Binary file modified internal/converter/fixtures/fileset.binpb
Binary file not shown.
5 changes: 4 additions & 1 deletion internal/converter/fixtures/gnostic.proto
Original file line number Diff line number Diff line change
@@ -63,7 +63,10 @@ service Greeter {
message HelloRequest {
option (gnostic.openapi.v3.schema) = {title: "Custom title for a message"};

string name = 1 [(gnostic.openapi.v3.property) = {title: "Custom title for a field"}];
string name = 1 [
(gnostic.openapi.v3.property).title = "Custom title for a field",
(gnostic.openapi.v3.property).example = {yaml: "Example value"}
];
}

// The response message containing the greetings
Original file line number Diff line number Diff line change
@@ -105,6 +105,5 @@
}
}
},
"security": [],
"externalDocs": {}
"security": []
}
Original file line number Diff line number Diff line change
@@ -80,4 +80,3 @@ components:
additionalProperties: true
description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message.
security: []
externalDocs: {}
Original file line number Diff line number Diff line change
@@ -109,6 +109,5 @@
}
}
},
"security": [],
"externalDocs": {}
"security": []
}
Original file line number Diff line number Diff line change
@@ -83,4 +83,3 @@ components:
additionalProperties: true
description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message.
security: []
externalDocs: {}
Original file line number Diff line number Diff line change
@@ -117,6 +117,5 @@
}
}
},
"security": [],
"externalDocs": {}
"security": []
}
Original file line number Diff line number Diff line change
@@ -90,4 +90,3 @@ components:
additionalProperties: true
description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message.
security: []
externalDocs: {}
9 changes: 7 additions & 2 deletions internal/converter/fixtures/output/envoy.openapi.json
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@
},
"responses": {
"default": {
"description": "Error",
"content": {
"application/json": {
"schema": {
@@ -47,6 +48,7 @@
}
},
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
@@ -92,6 +94,7 @@
},
"responses": {
"default": {
"description": "Error",
"content": {
"application/json": {
"schema": {
@@ -101,6 +104,7 @@
}
},
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
@@ -146,6 +150,7 @@
},
"responses": {
"default": {
"description": "Error",
"content": {
"application/json": {
"schema": {
@@ -155,6 +160,7 @@
}
},
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
@@ -1553,6 +1559,5 @@
{
"name": "envoy.test.ClusterDiscoveryService"
}
],
"externalDocs": {}
]
}
7 changes: 6 additions & 1 deletion internal/converter/fixtures/output/envoy.openapi.yaml
Original file line number Diff line number Diff line change
@@ -24,11 +24,13 @@ paths:
required: true
responses:
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/connect.error'
"200":
description: Success
content:
application/json:
schema:
@@ -55,11 +57,13 @@ paths:
required: true
responses:
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/connect.error'
"200":
description: Success
content:
application/json:
schema:
@@ -86,11 +90,13 @@ paths:
required: true
responses:
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/connect.error'
"200":
description: Success
content:
application/json:
schema:
@@ -1374,4 +1380,3 @@ components:
security: []
tags:
- name: envoy.test.ClusterDiscoveryService
externalDocs: {}
13 changes: 11 additions & 2 deletions internal/converter/fixtures/output/flex.openapi.json
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
},
"responses": {
"default": {
"description": "Error",
"content": {
"application/json": {
"schema": {
@@ -48,6 +49,7 @@
}
},
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
@@ -94,6 +96,7 @@
},
"responses": {
"default": {
"description": "Error",
"content": {
"application/json": {
"schema": {
@@ -103,6 +106,7 @@
}
},
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
@@ -149,6 +153,7 @@
},
"responses": {
"default": {
"description": "Error",
"content": {
"application/json": {
"schema": {
@@ -158,6 +163,7 @@
}
},
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
@@ -204,6 +210,7 @@
},
"responses": {
"default": {
"description": "Error",
"content": {
"application/json": {
"schema": {
@@ -213,6 +220,7 @@
}
},
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
@@ -259,6 +267,7 @@
},
"responses": {
"default": {
"description": "Error",
"content": {
"application/json": {
"schema": {
@@ -268,6 +277,7 @@
}
},
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
@@ -564,6 +574,5 @@
"name": "flex.FlexService",
"description": "This service tries to flex the different options"
}
],
"externalDocs": {}
]
}
Loading

0 comments on commit c1a33f7

Please sign in to comment.