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

feat: enable openapi spec swagger link in api register #73

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
34ab326
refactor: add apic api update example
frankqianms Sep 18, 2024
6e07880
tests: add test case
frankqianms Sep 18, 2024
9d91f60
fix: fix style
frankqianms Sep 18, 2024
5fc8a2b
fix: fix test case
frankqianms Sep 18, 2024
92dcff4
fix: fix test case
frankqianms Sep 18, 2024
89889ba
fix: fix test case & add recording
frankqianms Sep 18, 2024
ed12cc1
fix: remove bad command prefix
frankqianms Sep 19, 2024
b99e592
refactor: optimize test case code
frankqianms Sep 19, 2024
7b22cdd
Merge pull request #63 from blackchoey/frank/add_api_update_example
frankqianms Sep 19, 2024
b5b0fa2
refactor: remove duplicate example for apic create
frankqianms Sep 23, 2024
2b45d71
fix: fix style
frankqianms Sep 23, 2024
21e4bcd
Merge pull request #64 from blackchoey/frank/remove-duplicate-example
frankqianms Sep 23, 2024
1a199c9
feat: add examples for create & update apic service with system assig…
frankqianms Sep 23, 2024
f753dd8
Merge pull request #65 from blackchoey/frank/add-example
frankqianms Sep 24, 2024
cbbbb44
fix: fix external doc extracting bug in spec
frankqianms Sep 24, 2024
4bfa5c8
fix: remove extra print
frankqianms Sep 24, 2024
d64719c
fix: fix style
frankqianms Sep 24, 2024
8031a19
fix: fix style
frankqianms Sep 24, 2024
524d76a
fix: fix style
frankqianms Sep 24, 2024
b2315d4
fix: fix style
frankqianms Sep 24, 2024
14acd80
tests: fix test case
frankqianms Sep 24, 2024
f71785f
refactor: remove external docs from tags
frankqianms Sep 25, 2024
7a113c6
tests: update test case
frankqianms Sep 25, 2024
82c4099
Merge pull request #66 from blackchoey/frank/add_external_doc
frankqianms Sep 25, 2024
9ebebdb
refactor: remove summary setting in api register
frankqianms Sep 25, 2024
d912015
feat: support custom metadata export only
frankqianms Sep 25, 2024
f9341a5
fix: fix test case
frankqianms Sep 25, 2024
02827ef
Merge pull request #67 from blackchoey/frank/remove-summary-setting-i…
frankqianms Sep 25, 2024
d47f302
tests: add test case
frankqianms Sep 26, 2024
ecc4647
fix: fix arg type
frankqianms Sep 26, 2024
3a01240
refactor: add help example
frankqianms Sep 26, 2024
7296b18
Merge remote-tracking branch 'origin/v1.0.1' into frank/support-custo…
frankqianms Sep 26, 2024
911012c
fix: fix bad logic of link format
frankqianms Sep 26, 2024
f03bf96
refactor: remove extra example
frankqianms Sep 26, 2024
865d924
refactor: update example
frankqianms Sep 26, 2024
738f46a
Merge pull request #68 from blackchoey/frank/support-custom-metadata-…
frankqianms Sep 26, 2024
1650ba6
doc: update 1.0.1 release history
frankqianms Sep 30, 2024
b9cd37d
refactor: change note style
frankqianms Sep 30, 2024
e6e224b
fix: fix
frankqianms Sep 30, 2024
de969e8
fix: remove breaking change label
frankqianms Sep 30, 2024
349bfa4
Merge pull request #69 from blackchoey/frank/release-note
frankqianms Sep 30, 2024
4633343
build: bump version to 1.1.0
frankqianms Sep 30, 2024
a8f682e
Merge pull request #70 from blackchoey/frank/ga-110-changelog
frankqianms Sep 30, 2024
d1ec9ba
feat: read content from url
frankqianms Oct 9, 2024
f30a140
Merge remote-tracking branch 'origin/dev' into frank/enable_OpenAPI_link
frankqianms Oct 10, 2024
c07bb37
feat: enable register spec from url & add test case
frankqianms Oct 10, 2024
c67a6d9
doc: add example
frankqianms Oct 10, 2024
f13ff87
refactor: also support yml format url content
frankqianms Oct 10, 2024
13bdd42
tests: add test case
frankqianms Sep 18, 2024
e8dc2f4
fix: fix test case
frankqianms Sep 18, 2024
c93645f
fix: fix test case
frankqianms Sep 18, 2024
becf8b7
fix: fix test case & add recording
frankqianms Sep 18, 2024
82b9a73
refactor: optimize test case code
frankqianms Sep 19, 2024
b39bee8
fix: fix external doc extracting bug in spec
frankqianms Sep 24, 2024
1864093
fix: remove extra print
frankqianms Sep 24, 2024
dd9bc14
tests: update test case
frankqianms Sep 25, 2024
d31b1b1
feat: support custom metadata export only
frankqianms Sep 25, 2024
e52274f
tests: add test case
frankqianms Sep 26, 2024
ef179df
refactor: remove summary setting in api register
frankqianms Sep 25, 2024
b7989f6
fix: fix bad logic of link format
frankqianms Sep 26, 2024
e56362f
feat: read content from url
frankqianms Oct 9, 2024
1aa8d29
feat: enable register spec from url & add test case
frankqianms Oct 10, 2024
6287d92
doc: add example
frankqianms Oct 10, 2024
b6ff6b5
refactor: also support yml format url content
frankqianms Oct 10, 2024
7301d19
fix: fix style
frankqianms Oct 11, 2024
af14a92
fix: fix style
frankqianms Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/apic-extension/azext_apic_extension/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
text: |
az apic api register -g api-center-test -n contosoeuap --api-location "examples/cli-examples/spec-examples/openai.json" --environment-id public
az apic api register -g api-center-test -n contosoeuap --api-location "examples/cli-examples/spec-examples/openai.yml" --environment-id public
- name: Register api by providing spec url.
text: |
az apic api register -g api-center-test -n contosoeuap --api-location "https://petstore.swagger.io/v2/swagger.json" --environment-id public
"""
59 changes: 40 additions & 19 deletions src/apic-extension/azext_apic_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,47 @@ def register_apic(cmd, api_location, resource_group, service_name, environment_i
# Load the JSON file
if api_location:

# TODO Future Confirm its a file and not link
with open(str(api_location), 'rb') as f:
rawdata = f.read()
result = chardet.detect(rawdata)
encoding = result['encoding']

# TODO - read other file types later
value = None
if str(api_location).endswith('.yaml') or str(api_location).endswith('.yml'):
with open(str(api_location), 'r', encoding=encoding) as f:
content = f.read()
data = yaml.safe_load(content)
if data:
value = content
if (str(api_location).endswith('.json')):
with open(str(api_location), 'r', encoding=encoding) as f:
content = f.read()
data = json.loads(content)
if data:
value = content
# Read the spec content from URL
if str(api_location).startswith('https://') or str(api_location).startswith('http://'):
try:
# Fetch the content from the URL
response = requests.get(api_location)
# Raise an error for bad status codes
response.raise_for_status()
# Try to parse the content as JSON
try:
data = json.loads(response.content)
except json.JSONDecodeError:
try:
# If JSON parsing fails, try to parse as YAML
data = yaml.safe_load(response.content)
except yaml.YAMLError as e:
logger.error("Error parsing data from %s: %s", api_location, e)
data = None
# If we could parse the content(json or yaml), convert it to a json format string
value = json.dumps(data) if data else None
except requests.exceptions.RequestException as e:
logger.error("Error fetching data from %s: %s", api_location, e)
value = None
else:
# Confirm its a file and not link
with open(str(api_location), 'rb') as f:
rawdata = f.read()
result = chardet.detect(rawdata)
encoding = result['encoding']

# TODO - read other file types later
if str(api_location).endswith('.yaml') or str(api_location).endswith('.yml'):
with open(str(api_location), 'r', encoding=encoding) as f:
content = f.read()
data = yaml.safe_load(content)
value = content if data else None
if (str(api_location).endswith('.json')):
with open(str(api_location), 'r', encoding=encoding) as f:
content = f.read()
data = json.loads(content)
value = content if data else None

# If we could not read the file, return error
if value is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ interactions:
- CONFIG_NOCACHE
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-global-writes:
- '2999'
x-ms-ratelimit-remaining-subscription-writes:
- '199'
- '1199'
x-msedge-ref:
- 'Ref A: ABABBCBF318942349913A2BAAEEBC50C Ref B: MAA201060516047 Ref C: 2024-10-09T08:19:53Z'
x-powered-by:
Expand Down Expand Up @@ -112,7 +110,7 @@ interactions:
cache-control:
- no-cache
content-length:
- '449'
- '448'
content-type:
- application/json; charset=utf-8
date:
Expand All @@ -131,10 +129,8 @@ interactions:
- CONFIG_NOCACHE
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-global-writes:
- '2999'
x-ms-ratelimit-remaining-subscription-writes:
- '199'
- '1199'
x-msedge-ref:
- 'Ref A: 517F261485BF4D8FB1E0C2D974274BFC Ref B: MAA201060516039 Ref C: 2024-10-09T08:19:55Z'
x-powered-by:
Expand Down Expand Up @@ -207,10 +203,8 @@ interactions:
- CONFIG_NOCACHE
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-global-writes:
- '2999'
x-ms-ratelimit-remaining-subscription-writes:
- '199'
- '1199'
x-msedge-ref:
- 'Ref A: 2006204F91514BF494E5D9616CAC87BB Ref B: MAA201060515051 Ref C: 2024-10-09T08:19:56Z'
x-powered-by:
Expand Down Expand Up @@ -675,10 +669,8 @@ interactions:
- CONFIG_NOCACHE
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-global-writes:
- '2999'
x-ms-ratelimit-remaining-subscription-writes:
- '199'
- '1199'
x-msedge-ref:
- 'Ref A: 9A17F989BD03498E839563259636550F Ref B: MAA201060515053 Ref C: 2024-10-09T08:19:58Z'
x-powered-by:
Expand Down Expand Up @@ -742,8 +734,6 @@ interactions:
- CONFIG_NOCACHE
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-global-reads:
- '3749'
x-msedge-ref:
- 'Ref A: 3A6EB45269BE4D76BC76123E5D6A53E0 Ref B: MAA201060513027 Ref C: 2024-10-09T08:20:00Z'
x-powered-by:
Expand Down Expand Up @@ -777,7 +767,7 @@ interactions:
cache-control:
- no-cache
content-length:
- '449'
- '448'
content-type:
- application/json; charset=utf-8
date:
Expand Down Expand Up @@ -1327,10 +1317,8 @@ interactions:
- CONFIG_NOCACHE
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-global-writes:
- '2999'
x-ms-ratelimit-remaining-subscription-writes:
- '199'
- '1199'
x-msedge-ref:
- 'Ref A: 333EF8440AAA48B78D9BC181AA8F1C74 Ref B: MAA201060516049 Ref C: 2024-10-09T08:20:03Z'
x-powered-by:
Expand Down
Loading
Loading