-
-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add --x-nullable-as-nullable option to treat x-nullable the sam…
…e as nullable (#1576)
- Loading branch information
1 parent
4c88d9d
commit 77d92a3
Showing
8 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* This file was auto-generated by openapi-typescript. | ||
* Do not make direct changes to the file. | ||
*/ | ||
|
||
export interface paths {} | ||
|
||
export interface definitions { | ||
MyType: string; | ||
/** @description Some value that has x-nullable set */ | ||
MyTypeXNullable: string | null; | ||
/** | ||
* @description Enum with x-nullable | ||
* @enum {string|null} | ||
*/ | ||
MyEnum: ("foo" | "bar") | null; | ||
} | ||
|
||
export interface operations {} | ||
|
||
export interface external {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* This file was auto-generated by openapi-typescript. | ||
* Do not make direct changes to the file. | ||
*/ | ||
|
||
export interface paths {} | ||
|
||
export interface components { | ||
schemas: { | ||
MyType: string; | ||
/** @description Some value that has x-nullable set */ | ||
MyTypeXNullable: string | null; | ||
/** | ||
* @description Enum with x-nullable | ||
* @enum {string|null} | ||
*/ | ||
MyEnum: ("foo" | "bar") | null; | ||
}; | ||
} | ||
|
||
export interface operations {} | ||
|
||
export interface external {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { expect } from "chai"; | ||
import fs from "fs"; | ||
import eol from "eol"; | ||
import openapiTS from "../../dist/index.js"; | ||
|
||
describe("x-nullable-as-nullable", () => { | ||
const cases = [ | ||
{ | ||
name: "swagger 2.0", | ||
expectedFile: "x-nullable-as-nullable.2.0.ts", | ||
schema: { | ||
swagger: "2.0", | ||
definitions: { | ||
MyType: { | ||
type: "string", | ||
}, | ||
MyTypeXNullable: { | ||
type: "string", | ||
description: "Some value that has x-nullable set", | ||
"x-nullable": true, | ||
}, | ||
MyEnum: { | ||
description: "Enum with x-nullable", | ||
type: "string", | ||
enum: ["foo", "bar"], | ||
"x-nullable": true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "openapi 3.1", | ||
expectedFile: "x-nullable-as-nullable.3.1.ts", | ||
schema: { | ||
openapi: "3.1", | ||
components: { | ||
schemas: { | ||
MyType: { | ||
type: "string", | ||
}, | ||
MyTypeXNullable: { | ||
type: "string", | ||
description: "Some value that has x-nullable set", | ||
"x-nullable": true, | ||
}, | ||
MyEnum: { | ||
description: "Enum with x-nullable", | ||
type: "string", | ||
enum: ["foo", "bar"], | ||
"x-nullable": true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
cases.forEach(({ name, expectedFile, schema }) => { | ||
it(name, async () => { | ||
const generated = await openapiTS(schema, { | ||
xNullableAsNullable: true, | ||
}); | ||
const expected = eol.lf(fs.readFileSync(new URL(`./expected/${expectedFile}`, import.meta.url), "utf8")); | ||
expect(generated).to.equal(expected); | ||
}); | ||
}); | ||
}); |