-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenAPI 3.0 upgrade, swagger tool chain update
- Added tests for openAPI spec generator. - OpenAPI spec generator is enhanced to generate rest-server. stubs, this replaces the OpenAPI-generator from commnity. - Removed openAPI client generation. - Added Restconf document generator. - Upgraded specs to openAPI 3.0.
- Loading branch information
1 parent
ca0656c
commit d619bac
Showing
47 changed files
with
38,547 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// // | ||
// Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or // | ||
// its subsidiaries. // | ||
// // | ||
// 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. // | ||
// // | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
package openapi | ||
|
||
// Load function loads OpenAPI generated routes into REST server. | ||
func Load() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
package openapi | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/Azure/sonic-mgmt-framework/rest/server" | ||
) | ||
|
||
{% for operationId in OpIds %} | ||
{% set path = OpIdDict[operationId]["path"] %} | ||
{% set pathEntry = OpIdDict[operationId]["obj"] %} | ||
{% set method = OpIdDict[operationId]["method"] %} | ||
func {{ operationId }}(w http.ResponseWriter, r *http.Request) { | ||
rc, r := server.GetContext(r) | ||
rc.Name = "{{ operationId }}" | ||
{% if method in ["post", "put", "patch"] and "requestBody" in pathEntry %} | ||
{% for consume in pathEntry["requestBody"]["content"].keys() %} | ||
rc.Consumes.Add("{{ consume }}") | ||
{% endfor %} | ||
{% endif %} | ||
{% set content = dict() %} | ||
{% if method == "get" %} | ||
{% set content = pathEntry["responses"]["200"]["content"] %} | ||
{% endif %} | ||
{% if 'x-rpc' in pathEntry and 'content' in pathEntry["responses"]["204"] %} | ||
{% set content = pathEntry["responses"]["204"]["content"] %} | ||
{% endif %} | ||
{% for produce in content.keys() %} | ||
rc.Produces.Add("{{ produce }}") | ||
{% endfor %} | ||
{% if 'x-params' in pathEntry.keys() %} | ||
{% set varMappings = pathEntry['x-params']['varMapping'] %} | ||
rc.PMap = server.NameMap{ {% for varMapping in varMappings %}"{{ varMapping['uriName'] }}":"{{ varMapping['yangName'] }}", {% endfor %} } | ||
{% endif %} | ||
server.Process(w, r) | ||
} | ||
{% if not loop.last %} | ||
|
||
{% endif %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
package openapi | ||
|
||
import ( | ||
"github.com/Azure/sonic-mgmt-framework/rest/server" | ||
) | ||
|
||
func init() { | ||
|
||
{% for operationId in OpIds %} | ||
{% set path = OpIdDict[operationId]["path"] %} | ||
{% set pathEntry = OpIdDict[operationId]["obj"] %} | ||
{% set method = OpIdDict[operationId]["method"] %} | ||
server.AddRoute( | ||
"{{ operationId }}", | ||
"{{ method|capitalize }}", | ||
"{{ path }}", | ||
{{ operationId }}, | ||
) | ||
|
||
{% endfor %} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.PHONY: all test-rpc test-data-nodes | ||
|
||
TOPDIR := ../.. | ||
PYANG_PLUGINS_DIR := $(TOPDIR)/tools/pyang/pyang_plugins | ||
PYANG ?= pyang | ||
|
||
all: test-rpc test-data-nodes test-complex-model test-complex-model-no-oneof | ||
|
||
# This will cover RPC statements with only input, only output and with | ||
# both input and output | ||
test-rpc: | ||
$(PYANG) -f swaggerapi --plugindir $(PYANG_PLUGINS_DIR) test-rpc.yang | diff test-rpc.yang.expect - | ||
|
||
# This will cover container, list, leaf and leaf-lists with both | ||
# simple and nested hierarchies. | ||
# Also this will cover data type testing such as leafref, enum and string with pattern | ||
# simple string, integer types, leaf with default values, mandatory statements etc. | ||
test-data-nodes: | ||
$(PYANG) -f swaggerapi --plugindir $(PYANG_PLUGINS_DIR) test-data-nodes.yang | diff test-data-nodes.yang.expect - | ||
|
||
# This will cover some complex YANGs, with many nested hierarchies | ||
# Also with choice-case statements, Union data types, range with min,max etc | ||
# Test with one-oneof | ||
test-complex-model: | ||
$(PYANG) -f swaggerapi --plugindir $(PYANG_PLUGINS_DIR) --with-oneof ietf-snmp.yang ietf-snmp-community.yang | diff ietf-snmp.yang.expect - | ||
|
||
# Test without one-oneof | ||
test-complex-model-no-oneof: | ||
$(PYANG) -f swaggerapi --plugindir $(PYANG_PLUGINS_DIR) ietf-snmp.yang ietf-snmp-community.yang | diff ietf-snmp.no-oneof.yang.expect - |
Oops, something went wrong.