How to make decimal type field with number type in json schema? #5390
Unanswered
hyang691
asked this question in
Json Schema
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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