Skip to content

Commit 831e627

Browse files
authored
Merge pull request #29 from DavidBiesack/bugfix-26
Bugfix for #26 (resubmitted)
2 parents c3ac286 + ed86f35 commit 831e627

File tree

6 files changed

+73
-18
lines changed

6 files changed

+73
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ Remove the `webhooks` object, if present.
217217

218218
### ⤓ JSON Schema related changes
219219

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

223224
As a special case, if the resulting `example` includes an `id`, it is
@@ -340,7 +341,6 @@ becomes
340341
title: My Response
341342
description: Response from an API operation
342343
type: object
343-
unevaluatedProperties: false
344344
allOf:
345345
...
346346
```

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@apiture/openapi-down-convert",
3-
"version": "0.13.1",
3+
"version": "0.13.2",
44
"description": "Tool to down convert OpenAPI 3.1 to OpenAPI 3.0",
55
"main": "lib/src/index.js",
66
"bin": {

src/converter.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ export class Converter {
370370
private json(x) {
371371
return JSON.stringify(x, null, 2);
372372
}
373-
373+
/** HTTP methods */
374+
static readonly HTTP_METHODS = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'trace' ];
374375
/**
375376
* OpenAPI 3.1 defines a new `openIdConnect` security scheme.
376377
* Down-convert the scheme to `oauth2` / authorization code flow.
@@ -383,12 +384,11 @@ export class Converter {
383384
const scopes = {};
384385
const paths = this.openapi30?.paths;
385386
for (const path in paths) {
386-
for (const op in paths[path]) {
387-
if (op === 'parameters') {
388-
continue;
389-
}
390-
const operation = paths[path][op];
391-
const sec = operation?.security as object[];
387+
// filter out path.{$ref, summary, description, parameters, servers} and x-* specification extensions
388+
const methods = Object.keys(paths[path]).filter((op) => Converter.HTTP_METHODS.includes(op));
389+
methods.forEach(method => {
390+
const operation = paths[path][method];
391+
const sec = (operation?.security || []) as object[];
392392
sec.forEach((s) => {
393393
const requirement = s?.[schemeName] as string[];
394394
if (requirement) {
@@ -397,7 +397,7 @@ export class Converter {
397397
});
398398
}
399399
});
400-
}
400+
});
401401
}
402402
return scopes;
403403
};

test/converter.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,8 @@ describe('resolver test suite', () => {
773773
const scopes = converted.components.securitySchemes.accessToken.flows.authorizationCode.scopes;
774774
expect(scopes['scope1']).toEqual('Allow the application to access your personal profile data.');
775775
expect(scopes['scope3']).toEqual(`TODO: describe the 'scope3' scope`);
776+
const publicOp = (converted.paths['/users/{appId}/public-preferences'] as object)['get'];
777+
expect(publicOp['security']).toBeFalsy();
776778
done();
777779
});
778780
});
@@ -950,4 +952,3 @@ test('contentMediaType with existing unexpected format', (done) => {
950952
// TODO how to check that Converter logged to console.warn ?
951953
done();
952954
});
953-

test/data/openapi.yaml

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
openapi: 3.1.0
22
info:
3-
title: Transactions
3+
title: Application Preferences (Example OpenAPI)
44
description: ...
55
version: 0.1.2
66
contact:
@@ -18,10 +18,12 @@ tags:
1818
description: Application Preferences
1919
paths:
2020
/users/{appId}/preferences:
21+
summary: Application preferences
22+
description: A user's preferences for an application
2123
parameters:
2224
- $ref: '#/components/parameters/appIdPathParam'
2325
get:
24-
summary: Return preferences for a application
26+
summary: Return preferences for an application
2527
description: ...
2628
operationId: listPreferences
2729
tags:
@@ -66,7 +68,7 @@ paths:
6668
application/pdf:
6769
schema:
6870
type: string
69-
contentMediaType: application/json
71+
contentMediaType: application/pdf
7072
contentEncoding: base64
7173
maxLength: 5000000
7274
'400':
@@ -92,6 +94,58 @@ paths:
9294
- scope2
9395
- scope3
9496
- scope4
97+
/users/{appId}/public-preferences:
98+
parameters:
99+
- $ref: '#/components/parameters/appIdPathParam'
100+
get:
101+
summary: Return public preferences for an application, without auth
102+
description: ...
103+
operationId: listPublicPreferences
104+
tags:
105+
- Preferences
106+
parameters:
107+
- name: categories
108+
description: >-
109+
Filter preferences to only those whose `category` is in this
110+
pipe-separated list.
111+
in: query
112+
style: pipeDelimited
113+
schema:
114+
type: array
115+
minItems: 1
116+
maxItems: 16
117+
examples:
118+
- - Presentation
119+
- - Presentation
120+
- Notifications
121+
items:
122+
type: string
123+
- name: type
124+
description: >-
125+
Filter preferences only those whose `type` is in this pipe-separated
126+
list.
127+
in: query
128+
style: pipeDelimited
129+
schema:
130+
type: array
131+
minItems: 1
132+
maxItems: 4
133+
uniqueItems: true
134+
items:
135+
type: string
136+
responses:
137+
'200':
138+
description: OK.
139+
content:
140+
application/json:
141+
schema:
142+
$ref: '#/components/schemas/preferences'
143+
application/pdf:
144+
schema:
145+
type: string
146+
contentMediaType: application/pdf
147+
contentEncoding: base64
148+
maxLength: 5000000
95149
components:
96150
securitySchemes:
97151
accessToken:
@@ -437,4 +491,4 @@ components:
437491
minlength is for no milliseconds, such as
438492
'2021-10-30T19:06:00Z'
439493
maxLength is for '.' plus up to 9 digits for milliseconds,
440-
such as '2021-10-30T19:06:04.999000999Z'
494+
such as '2021-10-30T19:06:04.999000999Z'

0 commit comments

Comments
 (0)