Skip to content

Commit

Permalink
apic-extension 1.0.0b5 release (Azure#7432)
Browse files Browse the repository at this point in the history
* fix: --title --kind --custom-property parameters (#1)

* feat: support yaml file in register command (#3)

* fix: workspace parameter should not be required (#2)

* style: fix lint issues (#6)

* chore: update codeowner for apic-extension (#5)

* feat: revert changes to min cli version (#4)

* feat: resolve comments to CLI experience (#10)

* feat: mark "apic api register" command as preview (#13)

* feat: remove --terms-of-service parameter (#12)

* feat: remove --workspace-name parameter (#11)

* feat: support python 3.8 and 3.9 (#14)

* feat: fix command descriptions (#17)

* tests: add test cases for 'apic service' commands (#16)

* feat: Use 03-01 spec from azure-rest-api-specs repo to regenerate CLI (#19)

* fix: CLI errors (#20)

* fix: import error when run CLI command

* fix: no workspace name error when run import specification command

* feat: mark some parameters as required (#21)

* feat: mark --assignments parameter required for metadata commands

* doc: update sample commands

* feat: mark --source-resource-ids parameter as required for import-from-apim command

* doc: update description for import-from-apim command

* feat: bump version to 1.0.0b5 and update changelog (#18)

* build: fix ci (#22)

* style: fix style warnings

* test:fix test cases

* fix: service update command failure (#28)

* doc: fix command samples (#30)

* doc: update changelog per feedback (#29)

* doc: remove extra spaces in register command help message (#34)

* doc: update api definition and metadata command samples (#36)
  • Loading branch information
blackchoey authored Apr 28, 2024
1 parent cb7abc8 commit 25109ba
Show file tree
Hide file tree
Showing 72 changed files with 1,309 additions and 1,764 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/src/subscription/ @wilcobmsft

/src/apic-extension/ @arpishahmsft
/src/apic-extension/ @arpishahmsft @blackchoey @adashen

/src/alias/ @Juliehzl

Expand Down
9 changes: 8 additions & 1 deletion src/apic-extension/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ Release History

1.0.0b5
+++++
* Remove: All portal commands as it should not be exposed to customers.
* Add: Support yaml file for `az apic api register` command.
* Update: Command names, parameter names, and command descriptions for better understanding. Please leverage `-h` option or refer Azure CLI reference doc to see full list of commands and parameters.
* Update: Introduction to parameter constraints to ensure that valid values are provided.
* Update: Minimum Azure CLI version requirement is updated to 2.57.
* Fix: Various bug fixes for lastest preview version.
* Remove: Portal commands as we don't support this capability any longer.
* Remove: `--workspace-name` and `--terms-of-service` parameters are removed as they are not expected to be exposed.
* Remove: `head` commands in each command group are removed.

1.0.0b4
+++++
Expand Down
18 changes: 7 additions & 11 deletions src/apic-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ az apic service delete --resource-group api-center-test --service-name contosoeu
az apic service delete --resource-group arpi-test-rg1 -s apictestcli3
```

Show Workspace Example
```
Az apic workspace show -g api-center-test -s contosoeuap --name devdiv
```

Create API Examples
```
az apic api create -g api-center-test -s contosoeuap --name echo-api --title "Echo API" --kind "rest"
Expand All @@ -50,10 +45,10 @@ az apic api create --resource-group api-center-test --service-name contosoeuap -

Update API Examples
```
az apic api update -g api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" -w default
az apic api update -g api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service"
```
```
az apic api update --resource-group api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" --workspace-name default
az apic api update --resource-group api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service"
```

LIST Api Example
Expand Down Expand Up @@ -90,10 +85,10 @@ az apic api version create --resource-group api-center-test --service-name conto

UPDATE Api Version Examples
```
Az apic api version update -g api-center-test -s contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" -w default
Az apic api version update -g api-center-test -s contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01"
```
```
az apic api version update --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" --workspace-name default
az apic api version update --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01"
```

LIST Api Version Examples
Expand Down Expand Up @@ -127,7 +122,7 @@ az apic api definition create -g api-center-test -s contosoeuap --api-name echo-

UPDATE API Definition Example
```
az apic api definition update -g api-center-test -s contosoeuap --api-name echo-api --version 2023-01-01 --name "openapi" --title "OpenAPI" -w default
az apic api definition update -g api-center-test -s contosoeuap --api-name echo-api --version 2023-01-01 --name "openapi" --title "OpenAPI"
```

SHOW API Definition Example
Expand Down Expand Up @@ -209,7 +204,7 @@ Where envcreate1.json contains

UPDATE Environment
```
az apic environment update -g api-center-test -s contosoeuap --name public --title "Public cloud" -w default
az apic environment update -g api-center-test -s contosoeuap --name public --title "Public cloud"
```

LIST Environment
Expand Down Expand Up @@ -283,4 +278,5 @@ az apic metadata-schema export-metadata-schema -g api-center-test -s contosoeuap
Register API or Quick Add
```
az apic api register -g api-center-test -s contosoeuap --api-location "C:/Users/arpishah/examples/cli-examples/spec-examples/openai.json" --environment-name public
az apic api register -g api-center-test -s contosoeuap --api-location "C:/Users/arpishah/examples/cli-examples/spec-examples/openai.yml" --environment-name public
```
22 changes: 20 additions & 2 deletions src/apic-extension/azext_apic_extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------
from typing import Type

from azure.cli.core import AzCommandsLoader
from azure.cli.core.aaz import AAZCommand
from azext_apic_extension._help import helps # pylint: disable=unused-import


Expand All @@ -19,7 +21,7 @@ def __init__(self, cli_ctx=None):
custom_command_type=custom_command_type)

def load_command_table(self, args):
from azext_apic_extension.commands import load_command_table
from azext_apic_extension.commands import load_custom_commands
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
Expand All @@ -31,12 +33,28 @@ def load_command_table(self, args):
aaz_pkg_name=aaz.__name__,
args=args
)
load_command_table(self, args)
load_command_patches(self)
load_custom_commands(self, args)
return self.command_table

def load_arguments(self, command):
from azext_apic_extension._params import load_arguments
load_arguments(self, command)


def is_aaz_command_subclass(value: Type) -> bool:
return isinstance(value, type) and issubclass(value, AAZCommand)


def load_command_patches(loader: AzCommandsLoader) -> None:
import inspect
from azext_apic_extension import command_patches

for _, value in inspect.getmembers(command_patches):
# Only load custom commands from the command_patches module
if is_aaz_command_subclass(value) and value.__module__ == command_patches.__name__:
if value.AZ_NAME:
loader.command_table[value.AZ_NAME] = value(loader=loader)


COMMAND_LOADER_CLS = ApicExtensionCommandsLoader
5 changes: 3 additions & 2 deletions src/apic-extension/azext_apic_extension/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

helps['apic api register'] = """
type: command
short-summary: Single Command for registering api, api version, api definition, import spec, create deployment provided a spec file.
short-summary: Registers a new API with version, definition, and associated deployments using the specification file as the source of truth.
parameters:
- name: --api-location -l
type: string
short-summary: Location of spec file .
short-summary: Location of spec file.
- name: --resource-group -g
type: string
short-summary: Resource group name.
Expand All @@ -30,4 +30,5 @@
- name: Register api by providing spec file.
text: |
az apic api register -g api-center-test -s contosoeuap --api-location "examples/cli-examples/spec-examples/openai.json" --environment-name public
az apic api register -g api-center-test -s contosoeuap --api-location "examples/cli-examples/spec-examples/openai.yml" --environment-name public
"""
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .__cmd_group import *
from ._create import *
from ._delete import *
from ._head import *
from ._list import *
from ._show import *
from ._update import *
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
"apic api create",
)
class Create(AAZCommand):
"""Create new or updates existing API.
"""Register a new API or update an existing API.
:example: Create API
az apic api create -g contoso-resources -s contoso --name echo-api --title "Echo API"
az apic api create -g contoso-resources -s contoso --api-id echo-api --title "Echo API" --type REST
:example: Create API with custom properties
az apic api create -g contoso-resources -s contoso --api-id echo-api --title "Echo API" --type REST --custom-properties '{\"public-facing\":true}'
"""

_aaz_info = {
Expand All @@ -44,11 +47,12 @@ def _build_arguments_schema(cls, *args, **kwargs):
# define Arg Group ""

_args_schema = cls._args_schema
_args_schema.api_name = AAZStrArg(
options=["--api", "--name", "--api-name"],
help="The name of the API.",
_args_schema.api_id = AAZStrArg(
options=["--api-id"],
help="The id of the API.",
required=True,
fmt=AAZStrArgFormat(
pattern="^[a-zA-Z0-9-]{3,90}$",
max_length=90,
min_length=1,
),
Expand All @@ -61,6 +65,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
help="The name of the API Center service.",
required=True,
fmt=AAZStrArgFormat(
pattern="^[a-zA-Z0-9-]{3,90}$",
max_length=90,
min_length=1,
),
Expand All @@ -71,6 +76,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
required=True,
default="default",
fmt=AAZStrArgFormat(
pattern="^[a-zA-Z0-9-]{3,90}$",
max_length=90,
min_length=1,
),
Expand All @@ -84,7 +90,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
arg_group="Properties",
help="The contact information for the API.",
)
_args_schema.custom_properties = AAZObjectArg(
_args_schema.custom_properties = AAZFreeFormDictArg(
options=["--custom-properties"],
arg_group="Properties",
help="The custom metadata defined for API catalog entities.",
Expand All @@ -103,10 +109,11 @@ def _build_arguments_schema(cls, *args, **kwargs):
arg_group="Properties",
help="Additional, external documentation for the API.",
)
_args_schema.kind = AAZStrArg(
options=["--kind"],
_args_schema.type = AAZStrArg(
options=["--type"],
arg_group="Properties",
help="Kind of API. For example, REST or GraphQL.",
help="Type of API.",
required=True,
enum={"graphql": "graphql", "grpc": "grpc", "rest": "rest", "soap": "soap", "webhook": "webhook", "websocket": "websocket"},
)
_args_schema.license = AAZObjectArg(
Expand All @@ -122,15 +129,11 @@ def _build_arguments_schema(cls, *args, **kwargs):
max_length=200,
),
)
_args_schema.terms_of_service = AAZObjectArg(
options=["--terms-of-service"],
arg_group="Properties",
help="Terms of service for the API.",
)
_args_schema.title = AAZStrArg(
options=["--title"],
arg_group="Properties",
help="API title.",
required=True,
fmt=AAZStrArgFormat(
max_length=50,
min_length=1,
Expand Down Expand Up @@ -212,16 +215,6 @@ def _build_arguments_schema(cls, *args, **kwargs):
max_length=200,
),
)

terms_of_service = cls._args_schema.terms_of_service
terms_of_service.url = AAZStrArg(
options=["url"],
help="URL pointing to the terms of service.",
required=True,
fmt=AAZStrArgFormat(
max_length=200,
),
)
return cls._args_schema

def _execute_operations(self):
Expand Down Expand Up @@ -271,7 +264,7 @@ def error_format(self):
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"apiName", self.ctx.args.api_name,
"apiName", self.ctx.args.api_id,
required=True,
),
**self.serialize_url_param(
Expand Down Expand Up @@ -322,18 +315,17 @@ def content(self):
typ=AAZObjectType,
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
)
_builder.set_prop("properties", AAZObjectType, typ_kwargs={"flags": {"client_flatten": True}})
_builder.set_prop("properties", AAZObjectType, ".", typ_kwargs={"flags": {"required": True, "client_flatten": True}})

properties = _builder.get(".properties")
if properties is not None:
properties.set_prop("contacts", AAZListType, ".contacts")
properties.set_prop("customProperties", AAZObjectType, ".custom_properties")
properties.set_prop("customProperties", AAZFreeFormDictType, ".custom_properties")
properties.set_prop("description", AAZStrType, ".description")
properties.set_prop("externalDocumentation", AAZListType, ".external_documentation")
properties.set_prop("kind", AAZStrType, ".kind", typ_kwargs={"flags": {"required": True}})
properties.set_prop("kind", AAZStrType, ".type", typ_kwargs={"flags": {"required": True}})
properties.set_prop("license", AAZObjectType, ".license")
properties.set_prop("summary", AAZStrType, ".summary")
properties.set_prop("termsOfService", AAZObjectType, ".terms_of_service")
properties.set_prop("title", AAZStrType, ".title", typ_kwargs={"flags": {"required": True}})

contacts = _builder.get(".properties.contacts")
Expand All @@ -346,6 +338,10 @@ def content(self):
_elements.set_prop("name", AAZStrType, ".name")
_elements.set_prop("url", AAZStrType, ".url")

custom_properties = _builder.get(".properties.customProperties")
if custom_properties is not None:
custom_properties.set_anytype_elements(".")

external_documentation = _builder.get(".properties.externalDocumentation")
if external_documentation is not None:
external_documentation.set_elements(AAZObjectType, ".")
Expand All @@ -362,10 +358,6 @@ def content(self):
license.set_prop("name", AAZStrType, ".name")
license.set_prop("url", AAZStrType, ".url")

terms_of_service = _builder.get(".properties.termsOfService")
if terms_of_service is not None:
terms_of_service.set_prop("url", AAZStrType, ".url", typ_kwargs={"flags": {"required": True}})

return self.serialize_content(_content_value)

def on_200_201(self, session):
Expand Down Expand Up @@ -393,7 +385,7 @@ def _build_schema_on_200_201(cls):
flags={"read_only": True},
)
_schema_on_200_201.properties = AAZObjectType(
flags={"client_flatten": True},
flags={"required": True, "client_flatten": True},
)
_schema_on_200_201.system_data = AAZObjectType(
serialized_name="systemData",
Expand All @@ -405,7 +397,7 @@ def _build_schema_on_200_201(cls):

properties = cls._schema_on_200_201.properties
properties.contacts = AAZListType()
properties.custom_properties = AAZObjectType(
properties.custom_properties = AAZFreeFormDictType(
serialized_name="customProperties",
)
properties.description = AAZStrType()
Expand All @@ -418,6 +410,7 @@ def _build_schema_on_200_201(cls):
properties.license = AAZObjectType()
properties.lifecycle_stage = AAZStrType(
serialized_name="lifecycleStage",
flags={"read_only": True},
)
properties.summary = AAZStrType()
properties.terms_of_service = AAZObjectType(
Expand Down
Loading

0 comments on commit 25109ba

Please sign in to comment.