Skip to content

Commit

Permalink
bug: Paths and security schemes are optional (#427)
Browse files Browse the repository at this point in the history
* chore: add minimal spec samples

* feat: set validation to false by default #425
  • Loading branch information
srinandan authored Mar 5, 2024
1 parent 7bb7b16 commit 0b4747f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
10 changes: 9 additions & 1 deletion internal/bundlegen/generateapiv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ func GenerateAPIProxyDefFromOASv2(name string,
}

// load security schemes
loadSecurityRequirementsv2(docModel.Model.Components.SecuritySchemes)
if docModel.Model.Components != nil && docModel.Model.Components.SecuritySchemes != nil {
loadSecurityRequirementsv2(docModel.Model.Components.SecuritySchemes)
}

apiproxy.SetDisplayName(name)
if docModel.Model.Info != nil {
Expand Down Expand Up @@ -274,6 +276,9 @@ func GenerateAPIProxyDefFromOASv2(name string,
}

func loadSecurityRequirementsv2(securitySchemes *orderedmap.Map[string, *v3.SecurityScheme]) (err error) {
if securitySchemes == nil {
return nil
}
for first := securitySchemes.First(); first != nil; first = first.Next() {
securityScheme := first.Value()
securitySchemesList.SecuritySchemes = append(securitySchemesList.SecuritySchemes, loadSecurityTypev2(first.Key(), securityScheme))
Expand Down Expand Up @@ -488,6 +493,9 @@ func getQuotaDefinitionv2(extension *yaml.Node) ([]quotaDef, error) {
}

func generateFlowsv2(paths *v3.Paths) (err error) {
if paths == nil {
return nil
}
for first := paths.PathItems.First(); first != nil; first = first.Next() {
pathMap, err := getHTTPMethodv2(first.Value(), first.Key())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/apis/oascrtapisv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func init() {
OasCreatev2Cmd.Flags().BoolVarP(&importProxy, "import", "",
true, "Import API Proxy after generation from spec")
OasCreatev2Cmd.Flags().BoolVarP(&validateSpec, "validate", "",
true, "Validate Spec before generating proxy")
false, "Validate Spec before generating proxy")
OasCreatev2Cmd.Flags().BoolVarP(&skipPolicy, "skip-policy", "",
false, "Skip adding the OAS Validate policy")
OasCreatev2Cmd.Flags().BoolVarP(&addCORS, "add-cors", "",
Expand Down
34 changes: 34 additions & 0 deletions test/minspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

openapi: 3.0.2
info:
version: 0.0.1
title: Minimal Spec
description: |
This specification contains the minimum information to generate an Apigee Proxy with PreFlow policies
servers:
- url: https://my.example.com/api
security:
- ApiKeyAuth: []
x-google-ratelimit:
- name: test1_test
rate-literal: 10ps
identifier-ref: request.header.url #optional
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: X-API-KEY
24 changes: 24 additions & 0 deletions test/minspec2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

openapi: 3.0.2
info:
version: 0.0.1
title: Minimal Spec
servers:
- url: https://my.example.com/api
x-google-ratelimit:
- name: test1_test
rate-literal: 10ps
identifier-ref: request.header.url #optional

0 comments on commit 0b4747f

Please sign in to comment.