Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/24,26 #27

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ Remove the `webhooks` object, if present.

### ⤓ JSON Schema related changes

OAS 3.0 uses an earlier JSON Schema version (Draft 7). The tool converts `examples`
OAS 3.0 uses an earlier JSON Schema version
([JSON Schema Specification Wright Draft 00](https://datatracker.ietf.org/doc/html/draft-wright-json-schema-00)). The tool converts `examples`
in schemas to a single `example`.

As a special case, if the resulting `example` includes an `id`, it is
Expand Down
15 changes: 7 additions & 8 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export class Converter {
private json(x) {
return JSON.stringify(x, null, 2);
}

static readonly METHODS = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'trace' ];
/**
* OpenAPI 3.1 defines a new `openIdConnect` security scheme.
* Down-convert the scheme to `oauth2` / authorization code flow.
Expand All @@ -383,12 +383,11 @@ export class Converter {
const scopes = {};
const paths = this.openapi30?.paths;
for (const path in paths) {
for (const op in paths[path]) {
if (op === 'parameters') {
continue;
}
const operation = paths[path][op];
const sec = operation?.security as object[];
// filter out path.{$ref, summary, description, parameters, servers} and x-* specification extensions
const methods = Object.keys(paths[path]).filter((op) => Converter.METHODS.includes(op));
methods.forEach(method => {
const operation = paths[path][method];
const sec = (operation?.security || []) as object[];
sec.forEach((s) => {
const requirement = s?.[schemeName] as string[];
if (requirement) {
Expand All @@ -397,7 +396,7 @@ export class Converter {
});
}
});
}
});
}
return scopes;
};
Expand Down
3 changes: 2 additions & 1 deletion test/converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,8 @@ describe('resolver test suite', () => {
const scopes = converted.components.securitySchemes.accessToken.flows.authorizationCode.scopes;
expect(scopes['scope1']).toEqual('Allow the application to access your personal profile data.');
expect(scopes['scope3']).toEqual(`TODO: describe the 'scope3' scope`);
const publicOp = (converted.paths['/users/{appId}/public-preferences'] as object)['get'];
expect(publicOp['security']).toBeFalsy();
done();
});
});
Expand Down Expand Up @@ -950,4 +952,3 @@ test('contentMediaType with existing unexpected format', (done) => {
// TODO how to check that Converter logged to console.warn ?
done();
});

62 changes: 58 additions & 4 deletions test/data/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.1.0
info:
title: Transactions
title: Application Preferences (Example OpenAPI)
description: ...
version: 0.1.2
contact:
Expand All @@ -18,10 +18,12 @@ tags:
description: Application Preferences
paths:
/users/{appId}/preferences:
summary: Application preferences
description: A user's preferences for an application
parameters:
- $ref: '#/components/parameters/appIdPathParam'
get:
summary: Return preferences for a application
summary: Return preferences for an application
description: ...
operationId: listPreferences
tags:
Expand Down Expand Up @@ -66,7 +68,7 @@ paths:
application/pdf:
schema:
type: string
contentMediaType: application/json
contentMediaType: application/pdf
contentEncoding: base64
maxLength: 5000000
'400':
Expand All @@ -92,6 +94,58 @@ paths:
- scope2
- scope3
- scope4
/users/{appId}/public-preferences:
parameters:
- $ref: '#/components/parameters/appIdPathParam'
get:
summary: Return public preferences for an application, without auth
description: ...
operationId: listPublicPreferences
tags:
- Preferences
parameters:
- name: categories
description: >-
Filter preferences to only those whose `category` is in this
pipe-separated list.
in: query
style: pipeDelimited
schema:
type: array
minItems: 1
maxItems: 16
examples:
- - Presentation
- - Presentation
- Notifications
items:
type: string
- name: type
description: >-
Filter preferences only those whose `type` is in this pipe-separated
list.
in: query
style: pipeDelimited
schema:
type: array
minItems: 1
maxItems: 4
uniqueItems: true
items:
type: string
responses:
'200':
description: OK.
content:
application/json:
schema:
$ref: '#/components/schemas/preferences'
application/pdf:
schema:
type: string
contentMediaType: application/pdf
contentEncoding: base64
maxLength: 5000000
components:
securitySchemes:
accessToken:
Expand Down Expand Up @@ -437,4 +491,4 @@ components:
minlength is for no milliseconds, such as
'2021-10-30T19:06:00Z'
maxLength is for '.' plus up to 9 digits for milliseconds,
such as '2021-10-30T19:06:04.999000999Z'
such as '2021-10-30T19:06:04.999000999Z'
Loading