Skip to content

Commit

Permalink
(fix): a single enum with x-fern-enum is not turned into a literal (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Feb 21, 2024
1 parent d938128 commit a6e133a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`x-fern-enum x-fern-enum simple 1`] = `
{
"definitionFiles": {
"transcripts.yml": {
"types": {
"SpeechModel": {
"docs": "The speech model to use for the transcription.",
"enum": [
{
"docs": "The Nano tier is a lightweight model that is optimized for speed and cost.",
"name": "Nano",
"value": "nano",
},
],
},
},
},
},
"packageMarkerFile": {},
"rootApiFile": {
"display-name": "Test extension \`x-fern-enum\` for enums",
"error-discrimination": {
"strategy": "status-code",
},
"name": "api",
},
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.1.0
info:
title: Test extension `x-fern-enum` for enums
version: 1.0.0
paths: {}
components:
schemas:
SpeechModel:
type: string
description: The speech model to use for the transcription.
x-fern-sdk-group-name: transcripts
enum:
- nano
x-fern-enum:
nano:
name: Nano
description: The Nano tier is a lightweight model that is optimized for speed and cost.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testConvertOpenAPI } from "./testConvertOpenApi";

describe("x-fern-enum", () => {
testConvertOpenAPI("x-fern-enum", "openapi.yml");
});
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export function convertSchemaObject(
});
}

if (schema.enum.length === 1 && schema.enum[0] != null) {
const fernEnum = getFernEnum(schema);

if (schema.enum.length === 1 && schema.enum[0] != null && fernEnum == null) {
return convertLiteral({
nameOverride,
generatedName,
Expand All @@ -158,7 +160,7 @@ export function convertSchemaObject(
return convertEnum({
nameOverride,
generatedName,
fernEnum: getFernEnum(schema),
fernEnum,
enumVarNames: getExtension<string[]>(schema, [OpenAPIExtension.ENUM_VAR_NAMES]),
enumValues: schema.enum,
description,
Expand Down

0 comments on commit a6e133a

Please sign in to comment.