Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ function getConfiguration(type) {
case 'OAS 3.0':
case 'OAS 3':
return OASConfiguration.OAS30();
case 'OAS 3.1': return OASConfiguration.OAS31();
case 'OAS 3.2': return OASConfiguration.OAS32();
case 'ASYNC 2.0': return AsyncAPIConfiguration.Async20();
case 'ASYNC 3.0': return AsyncAPIConfiguration.Async30();
case 'ASYNC 3.1': return AsyncAPIConfiguration.Async30();
case 'GRPC': return GRPCConfiguration.GRPC();
default: throw new Error(`Unknown API type: ${type}`);
}
Expand All @@ -98,6 +102,7 @@ function getConfiguration(type) {
* @return {Promise<void>}
*/
async function processFile(sourceFile, file, type, destPath, resolution, flattened, sourceMaps) {
// Convert file path to output JSON path
let dest = `${file.substr(0, file.lastIndexOf('.')) }.json`;
if (dest.indexOf('/') !== -1) {
dest = dest.substr(dest.lastIndexOf('/'));
Expand Down
549 changes: 393 additions & 156 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Francisco Di Giandomenico"
],
"dependencies": {
"amf-client-js": "^5.10.2",
"amf-client-js": "5.11.12531",
"fs-extra": "^10.0.0"
},
"devDependencies": {
Expand Down
26 changes: 26 additions & 0 deletions test/api-generation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,30 @@ describe('API generation', () => {
assertValidAmfModel(data);
});
});

describe('New spec generation', () => {
const dest = path.join('test', 'playground');
const srcDir = 'test/';

const cases = [
{ file: 'apis/oas31.yaml', type: 'OAS 3.1', out: 'oas31' },
{ file: 'apis/oas32.yaml', type: 'OAS 3.2', out: 'oas32' },
{ file: 'apis/asyncApi30.yaml', type: 'ASYNC 3.0', out: 'asyncApi30' },
{ file: 'apis/asyncApi31.yaml', type: 'ASYNC 3.1', out: 'asyncApi31' },
];

cases.forEach(({ file, type, out }) => {
describe(`${type} model generation`, () => {
afterEach(() => fs.remove(dest));

it(`generates a valid compact model for ${type}`, async () => {
const files = new Map();
files.set(file, { type, mime: 'application/yaml' });
await generator(files, { src: srcDir, dest });
const compact = await fs.readJson(path.join(dest, `${out}-compact.json`));
assertValidAmfModel(compact);
});
});
});
});
});
29 changes: 29 additions & 0 deletions test/apis/asyncApi30.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# source: /Users/aloose/mulesoft/amf/amf-cli/shared/src/test/resources/validations/async3/bindings-kafka.yaml
asyncapi: '3.0.0'
info:
title: AsyncAPI 3.0 Test
version: '1.0.0'

channels:
userSignedUp:
address: user.signedup
description: Channel for user signup events
messages:
userSignedUpMessage:
name: userSignedUpMessage
contentType: application/json
payload:
type: object
properties:
userId:
type: string
email:
type: string

operations:
sendUserSignedUp:
action: send
channel:
$ref: '#/channels/userSignedUp'
messages:
- $ref: '#/channels/userSignedUp/messages/userSignedUpMessage'
28 changes: 28 additions & 0 deletions test/apis/asyncApi31.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# source: /Users/aloose/mulesoft/amf/amf-cli/shared/src/test/resources/validations/async31/validations/ros2-operation-valid.yaml
asyncapi: 3.1.0
info:
title: AsyncAPI 3.1 Test
version: 1.0.0

channels:
diagnostics:
address: /robot/diagnostics
messages:
diagnosticMessage:
name: diagnosticMessage
contentType: application/json
payload:
type: object
properties:
status:
type: string
timestamp:
type: number

operations:
publishDiagnostics:
action: send
channel:
$ref: '#/channels/diagnostics'
messages:
- $ref: '#/channels/diagnostics/messages/diagnosticMessage'
27 changes: 27 additions & 0 deletions test/apis/oas31.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# source: /Users/aloose/mulesoft/amf/amf-cli/shared/src/test/resources/validations/oas31/items-property-array.yaml
openapi: 3.1.0
info:
title: OAS 3.1 Test API
version: 1.0.0
description: Minimal OAS 3.1 spec to test JSON Schema 2020-12 keywords

paths:
/items:
get:
summary: Get items
responses:
'200':
description: Success
content:
application/json:
schema:
type: object
properties:
items:
type: array
prefixItems:
- type: string
description: First item is always a string
- type: number
description: Second item is always a number
items: false
34 changes: 34 additions & 0 deletions test/apis/oas32.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# source: /Users/aloose/mulesoft/amf/amf-cli/shared/src/test/resources/validations/oas32/tag-cyclic-parent.yaml
openapi: 3.2.0
info:
title: OAS 3.2 Test API
version: 1.0.0

paths:
/auth:
get:
summary: Get authenticated data
tags:
- authentication
responses:
'200':
description: Success

tags:
- name: data
summary: Data operations
- name: authentication
summary: All authentication-related operations
parent: data

components:
securitySchemes:
oauth2Device:
type: oauth2
flows:
deviceAuthorization:
deviceAuthorizationUrl: https://example.com/oauth/device/authorize
tokenUrl: https://example.com/oauth/token
scopes:
read: Read access
write: Write access
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export declare type ApiType = 'RAML 1.0' | 'RAML 0.8' | 'OAS 2.0' | 'OAS 3.0' | 'ASYNC 2.0' | 'GRPC';
export declare type ApiType = 'RAML 1.0' | 'RAML 0.8' | 'OAS 2.0' | 'OAS 3.0' | 'OAS 3.1' | 'OAS 3.2' | 'ASYNC 2.0' | 'ASYNC 3.0' | 'ASYNC 3.1' | 'GRPC';

export declare interface ApiConfiguration {
/**
Expand Down