Extension for AutoRest (https://github.com/Azure/autorest) that generates TypeScript code. The transpiled javascript code is isomorphic. It can be run in browser and in node.js environment.
After a conversation about this with the TypeSpec team here is some important considerations:
for a model
model Foo {
bar: string;
baz?: number;
}
op Update(@header content-type: "application/merge-patch+json", ...Foo): void;
op Create(...Foo): void;
which is used in a merge-patch+json operation, we should implicitly consider baz to be nullable as well only for the context of that operation, while other operations such as post would be true to the model definition.
So the implicit assumptions for the merge-patch+json context are:
For json-merge+patch:
'null' values have a special meaning - they erase any existing value
properties marked as optional can be set to null, properties marked as required cannot
All properties (required or optional in the schema) are optional in the request payload
Array values are completely replaced by array values in the patch
Keyed object values in the patch are recursively patched to the corresponding value on the service.
Because 'null' has a special meaning, it is inappropriate for any properties that allow explicit 'null' values to occur in a PATCH.
For other kinds of operations, if null is allowed on the wire, then the property type should include null: myProp: string | null
After a conversation about this with the TypeSpec team here is some important considerations:
for a model
which is used in a merge-patch+json operation, we should implicitly consider
baz
to be nullable as well only for the context of that operation, while other operations such aspost
would be true to the model definition.So the implicit assumptions for the merge-patch+json context are:
For json-merge+patch: