Skip to content

Commit

Permalink
Restore @default constraint shifting (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon authored Feb 21, 2025
1 parent 43932f2 commit 64a2798
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
38 changes: 19 additions & 19 deletions examples/function-calling/arguments/claude.sale.input.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"section_code": "general",
"channels": [
{
"code": "samchon",
"category_codes": [
"2in1_laptops",
"tablets",
"windows_tablets"
]
}
],
"opened_at": null,
"closed_at": null,
"content": {
Expand All @@ -25,22 +35,12 @@
],
"files": []
},
"channels": [
{
"code": "samchon",
"category_codes": [
"electronics",
"laptops",
"2in1_laptops"
]
}
],
"tags": [
"surface",
"laptop",
"tablet",
"2-in-1",
"microsoft"
"microsoft",
"windows"
],
"units": [
{
Expand Down Expand Up @@ -99,7 +99,7 @@
],
"stocks": [
{
"name": "i3/8GB/128GB",
"name": "Surface Pro 9 (i3/8GB/128GB)",
"price": {
"nominal": 1000000,
"real": 899000
Expand All @@ -121,7 +121,7 @@
]
},
{
"name": "i3/16GB/256GB",
"name": "Surface Pro 9 (i3/16GB/256GB)",
"price": {
"nominal": 1200000,
"real": 1099000
Expand All @@ -143,7 +143,7 @@
]
},
{
"name": "i3/16GB/512GB",
"name": "Surface Pro 9 (i3/16GB/512GB)",
"price": {
"nominal": 1400000,
"real": 1299000
Expand All @@ -165,7 +165,7 @@
]
},
{
"name": "i5/16GB/256GB",
"name": "Surface Pro 9 (i5/16GB/256GB)",
"price": {
"nominal": 1500000,
"real": 1399000
Expand All @@ -187,7 +187,7 @@
]
},
{
"name": "i5/32GB/512GB",
"name": "Surface Pro 9 (i5/32GB/512GB)",
"price": {
"nominal": 1800000,
"real": 1699000
Expand All @@ -209,7 +209,7 @@
]
},
{
"name": "i7/16GB/512GB",
"name": "Surface Pro 9 (i7/16GB/512GB)",
"price": {
"nominal": 1800000,
"real": 1699000
Expand All @@ -231,7 +231,7 @@
]
},
{
"name": "i7/32GB/512GB",
"name": "Surface Pro 9 (i7/32GB/512GB)",
"price": {
"nominal": 2000000,
"real": 1899000
Expand Down
2 changes: 1 addition & 1 deletion examples/function-calling/schemas/claude.sale.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
},
"units": {
"title": "List of units",
"description": "List of units.\n\nRecords about individual product composition informations that are sold\nin the sale. Each {@link IShoppingSaleUnit unit} record has configurable\n{@link IShoppingSaleUnitOption options},\n{@link IShoppingSaleUnitOptionCandidate candidate} values for each\noption, and {@link IShoppingSaleUnitStock final stocks} determined by\nselecting every candidate values of each option.",
"description": "List of units.\n\nRecords about individual product composition information that are sold\nin the sale. Each {@link IShoppingSaleUnit unit} record has configurable\n{@link IShoppingSaleUnitOption options},\n{@link IShoppingSaleUnitOptionCandidate candidate} values for each\noption, and {@link IShoppingSaleUnitStock final stocks} determined by\nselecting every candidate values of each option.",
"type": "array",
"items": {
"description": "Creation information of sale unit.\n\n------------------------------\n\nDescription of the current {@link IShoppingSaleUnit.ICreate} type:\n\n> Creation information of sale unit.\n\n------------------------------\n\nDescription of the parent {@link IShoppingSaleUnit} type:\n\n> Product composition information handled in the sale.\n> \n> `IShoppingSaleUnit` is an entity that embodies the \"individual product\"\n> information handled in the {@link IShoppingSale sale}.\n> \n> For reference, the reason why `IShoppingSaleUnit` is separated from\n> {@link IShoppingSaleSnapshot} by an algebraic relationship of 1: N is because\n> there are some cases where multiple products are sold in one listing. This is\n> the case with so-called \"bundled products\".\n> \n> - Bundle from regular product (Mackbook Set)\n> - Main Body\n> - Keyboard\n> - Mouse\n> - Apple Care (Free A/S Voucher)\n> \n> And again, `IShoppingSaleUnit` does not in itself refer to the\n> {@link IShoppingSaleUnitStock final stock} that the\n> {@link IShoppingCustomer customer} will {@link IShoppingOrder purchase}.\n> The final stock can be found only after selecting all given\n> {@link IShoppingSaleUnitOption options} and their\n> {@link IShoppingSaleUnitOptionCandidate candidate values}.\n> \n> For example, even if you buy a Macbook, the final stocks are determined only\n> after selecting all the options (CPU / RAM / SSD), etc.",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samchon/openapi",
"version": "2.5.0",
"version": "2.5.1",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",
"main": "./lib/index.js",
"module": "./lib/index.mjs",
Expand Down
18 changes: 17 additions & 1 deletion src/utils/OpenApiConstraintShifter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export namespace OpenApiConstraintShifter {
| "exclusiveMinimum"
| "exclusiveMaximum"
| "multipleOf"
| "default"
>,
>(
v: Schema,
Expand All @@ -48,6 +49,7 @@ export namespace OpenApiConstraintShifter {
| "exclusiveMinimum"
| "exclusiveMaximum"
| "multipleOf"
| "default"
> => {
const tags: string[] = [];
if (v.exclusiveMinimum === undefined && v.minimum !== undefined) {
Expand Down Expand Up @@ -76,6 +78,10 @@ export namespace OpenApiConstraintShifter {
description: v.description,
tags,
});
if (v.default !== undefined) {
tags.push(`@default ${v.default}`);
delete v.default;
}
return v;
};

Expand All @@ -88,12 +94,18 @@ export namespace OpenApiConstraintShifter {
| "format"
| "pattern"
| "contentMediaType"
| "default"
>,
>(
v: Schema,
): Omit<
Schema,
"minLength" | "maxLength" | "format" | "pattern" | "contentMediaType"
| "minLength"
| "maxLength"
| "format"
| "pattern"
| "contentMediaType"
| "default"
> => {
const tags: string[] = [];
if (v.minLength !== undefined) {
Expand All @@ -116,6 +128,10 @@ export namespace OpenApiConstraintShifter {
tags.push(`@contentMediaType ${v.contentMediaType}`);
delete v.contentMediaType;
}
if (v.default !== undefined) {
tags.push(`@default ${v.default}`);
delete v.default;
}
v.description = writeTagWithDescription({
description: v.description,
tags,
Expand Down

0 comments on commit 64a2798

Please sign in to comment.