You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are some fields with decimal as type in our typespec, when generating json schema, their type are string. I want to make sure its type is number.
I got suggestion below, but I get error "Argument '(anonymous model)' is not assignable to parameter of type 'valueof string'TypeSpec(invalid-argument)" when I add code @jsonschema({ type: "number" }) upper the field. Any suggestion?
Version used: "@typespec/json-schema": "0.55.0",
Suggestion:
To ensure that a decimal field type in TypeSpec is emitted as a number type in JSON Schema using the @typespec/json-schema package, you can use the @jsonschema decorator to explicitly specify the JSON Schema type. Here’s how you can achieve this:
Step-by-Step Guide
Define the TypeSpec Model: Create a TypeSpec model with a decimal field.
Use the @jsonschema Decorator: Apply the @jsonschema decorator to specify the JSON Schema type as number.
Example
Define the TypeSpec Model:
import "@typespec/json-schema";
model FinancialModel { @jsonschema({
type: "number"
})
amount: decimal;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
There are some fields with decimal as type in our typespec, when generating json schema, their type are string. I want to make sure its type is number.
I got suggestion below, but I get error "Argument '(anonymous model)' is not assignable to parameter of type 'valueof string'TypeSpec(invalid-argument)" when I add code @jsonschema({ type: "number" }) upper the field. Any suggestion?
Version used: "@typespec/json-schema": "0.55.0",
Suggestion:
To ensure that a decimal field type in TypeSpec is emitted as a number type in JSON Schema using the @typespec/json-schema package, you can use the @jsonschema decorator to explicitly specify the JSON Schema type. Here’s how you can achieve this:
Step-by-Step Guide
Define the TypeSpec Model: Create a TypeSpec model with a decimal field.
Use the @jsonschema Decorator: Apply the @jsonschema decorator to specify the JSON Schema type as number.
Example
Define the TypeSpec Model:
import "@typespec/json-schema";
model FinancialModel {
@jsonschema({
type: "number"
})
amount: decimal;
}
Beta Was this translation helpful? Give feedback.
All reactions