-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for OpenAPI version 3.1.0 (#1778)
Co-authored-by: Jonas Lagoni <[email protected]>
- Loading branch information
1 parent
f7fa01e
commit 35f871a
Showing
14 changed files
with
260 additions
and
80 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
# OpenAPI 3.1 from object | ||
|
||
A basic example of how to use Modelina with a basic OpenAPI v3.1.0 object. | ||
|
||
## How to run this example | ||
|
||
Run this example using: | ||
|
||
```sh | ||
npm i && npm run start | ||
``` | ||
|
||
If you are on Windows, use the `start:windows` script instead: | ||
|
||
```sh | ||
npm i && npm run start:windows | ||
``` |
53 changes: 53 additions & 0 deletions
53
examples/openapi-v3_1-from-object/__snapshots__/index.spec.ts.snap
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,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Should be able to process a pure OpenAPI V3.1 object and should log expected output to console 1`] = ` | ||
Array [ | ||
"class TestPost_200ApplicationJson { | ||
private _email?: string; | ||
constructor(input: { | ||
email?: string, | ||
}) { | ||
this._email = input.email; | ||
} | ||
get email(): string | undefined { return this._email; } | ||
set email(email: string | undefined) { this._email = email; } | ||
}", | ||
] | ||
`; | ||
|
||
exports[`Should be able to process a pure OpenAPI V3.1 object and should log expected output to console 2`] = ` | ||
Array [ | ||
"class TestPostMultipartFormMinusData { | ||
private _id?: string; | ||
private _address?: Map<string, any>; | ||
private _profileImage?: string; | ||
private _additionalProperties?: Map<string, any>; | ||
constructor(input: { | ||
id?: string, | ||
address?: Map<string, any>, | ||
profileImage?: string, | ||
additionalProperties?: Map<string, any>, | ||
}) { | ||
this._id = input.id; | ||
this._address = input.address; | ||
this._profileImage = input.profileImage; | ||
this._additionalProperties = input.additionalProperties; | ||
} | ||
get id(): string | undefined { return this._id; } | ||
set id(id: string | undefined) { this._id = id; } | ||
get address(): Map<string, any> | undefined { return this._address; } | ||
set address(address: Map<string, any> | undefined) { this._address = address; } | ||
get profileImage(): string | undefined { return this._profileImage; } | ||
set profileImage(profileImage: string | undefined) { this._profileImage = profileImage; } | ||
get additionalProperties(): Map<string, any> | undefined { return this._additionalProperties; } | ||
set additionalProperties(additionalProperties: Map<string, any> | undefined) { this._additionalProperties = additionalProperties; } | ||
}", | ||
] | ||
`; |
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,15 @@ | ||
const spy = jest.spyOn(global.console, 'log').mockImplementation(() => { | ||
return; | ||
}); | ||
import { generate } from './index'; | ||
describe('Should be able to process a pure OpenAPI V3.1 object', () => { | ||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
test('and should log expected output to console', async () => { | ||
await generate(); | ||
expect(spy.mock.calls.length).toEqual(2); | ||
expect(spy.mock.calls[0]).toMatchSnapshot(); | ||
expect(spy.mock.calls[1]).toMatchSnapshot(); | ||
}); | ||
}); |
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,70 @@ | ||
import { TypeScriptGenerator } from '../../src'; | ||
|
||
const generator = new TypeScriptGenerator(); | ||
const swaggerDocument = { | ||
openapi: '3.1.0', | ||
info: { | ||
version: '0.1', | ||
title: 'Simple basic api' | ||
}, | ||
paths: { | ||
'/test': { | ||
post: { | ||
requestBody: { | ||
content: { | ||
'multipart/form-data': { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
id: { | ||
type: 'string', | ||
format: 'uuid' | ||
}, | ||
address: { | ||
type: 'object', | ||
properties: {} | ||
}, | ||
profileImage: { | ||
type: 'string', | ||
contentMediaType: 'image/png', | ||
contentEncoding: 'base64' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
responses: { | ||
200: { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
email: { | ||
type: 'string', | ||
format: 'email' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export async function generate(): Promise<void> { | ||
const models = await generator.generate(swaggerDocument); | ||
for (const model of models) { | ||
console.log(model.result); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
generate(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
{ | ||
"config" : { "example_name" : "openapi-v3_1-from-object" }, | ||
"scripts": { | ||
"install": "cd ../.. && npm i", | ||
"start": "../../node_modules/.bin/ts-node --cwd ../../ ./examples/$npm_package_config_example_name/index.ts", | ||
"start:windows": "..\\..\\node_modules\\.bin\\ts-node --cwd ..\\..\\ .\\examples\\%npm_package_config_example_name%\\index.ts", | ||
"test": "../../node_modules/.bin/jest --config=../../jest.config.js ./examples/$npm_package_config_example_name/index.spec.ts", | ||
"test:windows": "..\\..\\node_modules\\.bin\\jest --config=..\\..\\jest.config.js examples/%npm_package_config_example_name%/index.spec.ts" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.