From 1a8a201cc3729f208c0e59e248b5efb43843398d Mon Sep 17 00:00:00 2001 From: David Biesack Date: Sun, 21 Apr 2024 21:49:05 -0400 Subject: [PATCH] Fix #24 - link to correct JSON Schema version for OAS 3.0.x Fixed #36 - Allow for no security requirements object on an operaetion --- src/converter.ts | 2 +- test/converter.spec.ts | 3 ++- test/data/openapi.yaml | 60 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/converter.ts b/src/converter.ts index 07c3358..3f4e92f 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -388,7 +388,7 @@ export class Converter { continue; } const operation = paths[path][op]; - const sec = operation?.security as object[]; + const sec = (operation?.security || []) as object[]; sec.forEach((s) => { const requirement = s?.[schemeName] as string[]; if (requirement) { diff --git a/test/converter.spec.ts b/test/converter.spec.ts index 0b2f582..85053c6 100644 --- a/test/converter.spec.ts +++ b/test/converter.spec.ts @@ -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 unauthOp = (converted.paths['/users/{appId}/open-preferences'] as object)['get']; + expect(unauthOp['security']).toBeFalsy(); done(); }); }); @@ -950,4 +952,3 @@ test('contentMediaType with existing unexpected format', (done) => { // TODO how to check that Converter logged to console.warn ? done(); }); - diff --git a/test/data/openapi.yaml b/test/data/openapi.yaml index e8f77a2..0376f0a 100644 --- a/test/data/openapi.yaml +++ b/test/data/openapi.yaml @@ -1,6 +1,6 @@ openapi: 3.1.0 info: - title: Transactions + title: Application Preferences (Example OpenAPI) description: ... version: 0.1.2 contact: @@ -21,7 +21,7 @@ paths: parameters: - $ref: '#/components/parameters/appIdPathParam' get: - summary: Return preferences for a application + summary: Return preferences for an application description: ... operationId: listPreferences tags: @@ -66,7 +66,7 @@ paths: application/pdf: schema: type: string - contentMediaType: application/json + contentMediaType: application/pdf contentEncoding: base64 maxLength: 5000000 '400': @@ -92,6 +92,58 @@ paths: - scope2 - scope3 - scope4 + /users/{appId}/open-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: @@ -437,4 +489,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' \ No newline at end of file + such as '2021-10-30T19:06:04.999000999Z'