Skip to content

Instantly share code, notes, and snippets.

View johanste's full-sized avatar

Johan Stenberg (MSFT) johanste

  • Microsoft Corporation
  • Redmond, WA
View GitHub Profile
@johanste
johanste / cadlsidecar.md
Last active September 28, 2022 18:37
Client coden annotations for Cadl

Cadl for code gen

Requirements

  • There should be no need for customizations. A "raw" service specification should be enough to generate a client library.

  • The cost of customizations should be proportional to the amount of customizations we are making. It must not have a steep cost cliff when we want to customize a small aspect of the generated code (a.k.a. "the cost of the first customization should be low").

Solution

@johanste
johanste / azurenomnom.puml
Last active July 1, 2021 22:34
PlantUML version of service nomenclature
```plantuml
@startuml
abstract Model
abstract StructuredInformation
abstract Entity
abstract Operation
Operation : Id
Operation : status
abstract Job
abstract Batch
@johanste
johanste / llc.py
Created March 4, 2021 04:23
Prototype generic llc request builder
import json
import typing
import purl
HeadersType = typing.Union[typing.Sequence[typing.Tuple[str, typing.Any]], typing.Mapping[str, typing.Any], None]
JsonBodyType = typing.Union[typing.Mapping[str, "JsonBodyType"], str, int, float, bool, None]
ParamType2 = typing.Union[typing.Sequence[typing.Tuple[str, typing.Any]], typing.Mapping[str, typing.Any]]
ParamType = typing.Union[typing.Sequence[typing.Tuple[str, typing.Any]], typing.Mapping[str, typing.Any]]
@johanste
johanste / overrideresourceproperties.json
Created February 8, 2021 23:13
More specific "derived" swagger type
{
"swagger": "2.0",
"info": {
"title": "Examples of scenarios - #1, more constrained children",
"version": "1.0"
},
"paths": [],
"definitions": {
"GenericResource": {
"type": "object",
@johanste
johanste / overloads-in-swagger-2.0.json
Last active January 13, 2021 21:55
Show how to use the (autorest) x-ms-paths extension to overload operations for the same path.
{
"swagger": "2.0",
"info": {
"title": "Show x-ms-paths",
"version": "1.0"
},
"x-ms-paths": {
/* Note - fake query parameter to make the path unique. Not actually used in the API.
You can also differentiate using a different path parameter name if the path is parameterized
*/
@johanste
johanste / openapi.py
Created December 4, 2020 22:53
Swagger as TypedDict (WIP)
import typing
class InfoFragment(typing.TypedDict):
title: str
version: str
OptionalInAttribute = typing.TypedDict(
@johanste
johanste / example.json
Last active October 5, 2020 22:28
Polymorphic swagger
{
"swagger": "2.0",
"info": {
"title": "Example of polymorphic models, hypothetical document recognition style",
"version": "1.0"
},
"consumes": ["application/json"],
"produces": ["application/json"],
"paths": {
"/analyze": {
@johanste
johanste / computation.json
Last active July 31, 2020 16:51
Training/openapi example for service description
{
"swagger": "2.0",
"info": {
"title": "Example service",
"version": "1.1"
},
"paths": {
"/ComputeNodes": {
"parameters": [
{
@johanste
johanste / metaregistergridevent.py
Created July 23, 2020 01:33
Registering event types for event grid messages...
class AiEventMeta(type):
def __init__(cls, name, bases, nmspc):
super().__init__(name, bases, nmspc)
if not hasattr(cls, 'event_type_registry'):
setattr(cls, 'event_type_registry', {})
if hasattr(cls, 'EVENT_TYPE_NAME'):
cls.event_type_registry[cls.EVENT_TYPE_NAME] = cls
class AiEvent(metaclass=AiEventMeta):
@johanste
johanste / carbonsession.py
Created July 17, 2020 22:59
Mix of decorators and module level function to compose multiple capabilities (Python)
import carbon
video_stream = ...
# Module level function lets you pick a stream, "features" and go
# (this assumes there is a default configuration for each feature/category/model)
for event in carbon.recognize(video_stream, features=['faceDetection', 'vehicleDetection']):
print(event)
# Slightly more involved scenario with custom configurations and a dedicated session...