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 for #26 (resubmitted) #29

Merged
merged 8 commits into from
Apr 23, 2024
Merged
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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -340,7 +341,6 @@ becomes
title: My Response
description: Response from an API operation
type: object
unevaluatedProperties: false
allOf:
...
```
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apiture/openapi-down-convert",
"version": "0.13.1",
"version": "0.13.2",
"description": "Tool to down convert OpenAPI 3.1 to OpenAPI 3.0",
"main": "lib/src/index.js",
"bin": {
Expand Down
16 changes: 8 additions & 8 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ export class Converter {
private json(x) {
return JSON.stringify(x, null, 2);
}

/** HTTP methods */
static readonly HTTP_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 +384,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.HTTP_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 +397,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