Skip to content

Commit

Permalink
fix(oas): 🩹 fix missing literal in oas
Browse files Browse the repository at this point in the history
  • Loading branch information
charlzyx committed Dec 25, 2024
1 parent d4510d3 commit 3399223
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/oas/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"status": {
"oneOf": [
{
"const": "placed",
"type": "string",
},
{
"const": "approved",
"type": "string",
},
{
"const": "delivered",
"type": "string",
},
],
Expand Down Expand Up @@ -134,12 +137,15 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"status": {
"oneOf": [
{
"const": "placed",
"type": "string",
},
{
"const": "approved",
"type": "string",
},
{
"const": "delivered",
"type": "string",
},
],
Expand Down Expand Up @@ -223,6 +229,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"createPet": {
"properties": {
"method": {
"const": "PUT",
"type": "string",
},
"resp": {
Expand All @@ -248,6 +255,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/pet",
"type": "string",
},
},
Expand Down Expand Up @@ -298,6 +306,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"method": {
"const": "POST",
"type": "string",
},
"resp": {
Expand All @@ -323,6 +332,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/user",
"type": "string",
},
},
Expand Down Expand Up @@ -376,6 +386,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"type": "array",
},
"method": {
"const": "POST",
"type": "string",
},
"resp": {
Expand Down Expand Up @@ -416,6 +427,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/user/createWithList",
"type": "string",
},
},
Expand All @@ -424,6 +436,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"deleteOrder": {
"properties": {
"method": {
"const": "DELETE",
"type": "string",
},
"path": {
Expand Down Expand Up @@ -463,6 +476,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/store/order/:orderId",
"type": "string",
},
},
Expand All @@ -481,6 +495,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"type": "object",
},
"method": {
"const": "DELETE",
"type": "string",
},
"path": {
Expand All @@ -504,6 +519,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"type": "object",
},
"url": {
"const": "{{SERVER}}/pet/:petId",
"type": "string",
},
},
Expand All @@ -512,6 +528,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"deleteUser": {
"properties": {
"method": {
"const": "DELETE",
"type": "string",
},
"path": {
Expand Down Expand Up @@ -551,6 +568,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/user/:username",
"type": "string",
},
},
Expand All @@ -561,6 +579,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"description": "js doc",
"properties": {
"method": {
"const": "GET",
"type": "string",
},
"path": {
Expand Down Expand Up @@ -618,6 +637,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/:petId",
"type": "string",
},
},
Expand All @@ -626,17 +646,21 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"findPetByStatus": {
"properties": {
"method": {
"const": "GET",
"type": "string",
},
"query": {
"oneOf": [
{
"const": "placed",
"type": "string",
},
{
"const": "approved",
"type": "string",
},
{
"const": "delivered",
"type": "string",
},
],
Expand Down Expand Up @@ -676,6 +700,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/findByStatus",
"type": "string",
},
},
Expand All @@ -684,6 +709,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"findPetByTags": {
"properties": {
"method": {
"const": "GET",
"type": "string",
},
"query": {
Expand Down Expand Up @@ -727,6 +753,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/findByTags",
"type": "string",
},
},
Expand All @@ -735,6 +762,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"getInventory": {
"properties": {
"method": {
"const": "GET",
"type": "string",
},
"resp": {
Expand All @@ -752,6 +780,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"type": "object",
},
"url": {
"const": "{{SERVER}}/store/inventory",
"type": "string",
},
},
Expand All @@ -760,6 +789,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"getOrderById": {
"properties": {
"method": {
"const": "GET",
"type": "string",
},
"path": {
Expand Down Expand Up @@ -817,6 +847,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/store/order/:orderId",
"type": "string",
},
},
Expand All @@ -825,6 +856,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"getUserByName": {
"properties": {
"method": {
"const": "GET",
"type": "string",
},
"path": {
Expand Down Expand Up @@ -882,6 +914,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/user/:username",
"type": "string",
},
},
Expand All @@ -893,6 +926,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"$ref": "#components/schemas/Order",
},
"method": {
"const": "POST",
"type": "string",
},
"resp": {
Expand Down Expand Up @@ -933,6 +967,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/store/order",
"type": "string",
},
},
Expand All @@ -955,6 +990,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
"type": "object",
},
"url": {
"const": "TEST",
"type": "string",
},
},
Expand Down Expand Up @@ -987,6 +1023,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"method": {
"const": "POST",
"type": "string",
},
"resp": {
Expand Down Expand Up @@ -1036,6 +1073,7 @@ exports[`to-oas transformer 全量测试 / Full Test 1`] = `
],
},
"url": {
"const": "{{SERVER}}/pet",
"type": "string",
},
},
Expand All @@ -1056,6 +1094,7 @@ format: binary"
"type": "string",
},
"method": {
"const": "POST",
"type": "string",
},
"path": {
Expand Down Expand Up @@ -1096,6 +1135,7 @@ format: binary"
],
},
"url": {
"const": "{{SERVER}}/pet/:petId/uploadImage",
"type": "string",
},
},
Expand All @@ -1104,6 +1144,7 @@ format: binary"
"updatePetWithForm": {
"properties": {
"method": {
"const": "POST",
"type": "string",
},
"path": {
Expand All @@ -1124,12 +1165,15 @@ format: binary"
"status": {
"oneOf": [
{
"const": "placed",
"type": "string",
},
{
"const": "approved",
"type": "string",
},
{
"const": "delivered",
"type": "string",
},
],
Expand All @@ -1150,6 +1194,7 @@ format: binary"
"type": "object",
},
"url": {
"const": "{{SERVER}}/pet/:petId",
"type": "string",
},
},
Expand All @@ -1158,6 +1203,7 @@ format: binary"
"updateUser": {
"properties": {
"method": {
"const": "PUT",
"type": "string",
},
"path": {
Expand Down Expand Up @@ -1212,6 +1258,7 @@ format: binary"
],
},
"url": {
"const": "{{SERVER}}/user/:username",
"type": "string",
},
},
Expand All @@ -1220,6 +1267,7 @@ format: binary"
"userLogin": {
"properties": {
"method": {
"const": "GET",
"type": "string",
},
"query": {
Expand Down Expand Up @@ -1280,6 +1328,7 @@ format: binary"
],
},
"url": {
"const": "{{SERVER}}/user/login",
"type": "string",
},
},
Expand All @@ -1288,6 +1337,7 @@ format: binary"
"userLogout": {
"properties": {
"method": {
"const": "GET",
"type": "string",
},
"resp": {
Expand All @@ -1306,6 +1356,7 @@ format: binary"
"type": "object",
},
"url": {
"const": "{{SERVER}}/user/logout",
"type": "string",
},
},
Expand Down Expand Up @@ -1365,6 +1416,7 @@ exports[`to-oas transformer 应该正确处理多种注释 / should transform e
"Where": "覆盖情况",
},
"url": {
"const": "somthing",
"description": "interesting",
"type": "string",
},
Expand Down
7 changes: 7 additions & 0 deletions packages/oas/src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ const resolveDefs = (type: Type, ctx: ResolveContext) => {
const primitiveResolve =
(basetype: JsonSchemaType) => (type: Type, ctx: ResolveContext) => {
const extra = consumeExtra(ctx);
const literal = {
const: undefined,
};
if (type.isLiteral()) {
literal.const = type.getLiteralValue();
}
return {
...extra,
...literal,
type: basetype,
_code: type.getText(),
} satisfies OasSchema;
Expand Down

0 comments on commit 3399223

Please sign in to comment.