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

feat: conversion of openapi '3.0' to asyncapi '3.0' #269

Merged
merged 16 commits into from
Aug 13, 2024

Conversation

Gmin2
Copy link
Contributor

@Gmin2 Gmin2 commented Jun 16, 2024

Description

  • Converted openapi, info, servers, tags, externalDocs, and security.
  • Converted path keyword
  • Converted components.

Related issue(s)
Fixes #233

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@Gmin2 Gmin2 marked this pull request as draft June 16, 2024 20:29
Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code is way too tangled together at the moment. There should be clear separations between converting AsyncAPI between versions and converting OpenAPI to AsyncAPI 🙂

Its completely fine to have 2 functions, one called convert for converting AsyncAPI between versions and then another called ? to convert OpenAPI to AsyncAPI 🤙

Also make sure you add more test, especially edge cases for it to convert 🙂

But this is a good first PR to merge, good first initial feature 👍

@Gmin2
Copy link
Contributor Author

Gmin2 commented Jun 17, 2024

dont merge @jonaslagoni need to add some more test cases

@aeworxet
Copy link

@asyncapi/bounty_team

@asyncapi-bot asyncapi-bot added the bounty AsyncAPI Bounty label Jun 17, 2024
Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to double-check whether the converted AsyncAPI document is valid 🙂

src/interfaces.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated Show resolved Hide resolved
test/output/openapi-to-asyncapi/no-channel-parameter.yml Outdated Show resolved Hide resolved
test/output/openapi-to-asyncapi/no-channel-parameter.yml Outdated Show resolved Hide resolved
@jonaslagoni
Copy link
Member

@Gmin2 ping me if you need anything

@Gmin2
Copy link
Contributor Author

Gmin2 commented Jul 21, 2024

@jonaslagoni can we merge this PR, i will make another PR with more testcases and refining the conversion of path objects

@Gmin2 Gmin2 marked this pull request as ready for review July 22, 2024 18:30
@Gmin2 Gmin2 requested a review from jonaslagoni July 22, 2024 18:31
@jonaslagoni
Copy link
Member

Since you already included everything in one PR and it is not a fully working change by it self, we cannot unfortunately...

@Gmin2
Copy link
Contributor Author

Gmin2 commented Jul 27, 2024

@jonaslagoni completed all the work, please review

@jonaslagoni
Copy link
Member

@Gmin2 let me know when you are ready for a final review.

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, a bit more is needed before we can merge this ✌️

A few things are needed:

  • Make sure you test the perspective option
  • Make sure that new functions have jsdocs associated that explains abstracted what it does
  • Make sure that the converted operation object also assigns the .reply section where needed.

src/openapi.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated Show resolved Hide resolved
@jonaslagoni
Copy link
Member

@Gmin2 also make sure you update the readme file to introduce the new feature

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to mention (actually thought I did in the last review) remember to change the main readme file in the repo so everyone can find this new functionality 🙂

Ahh, wrote it here: #269 (comment)

src/convert.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated Show resolved Hide resolved
@Gmin2
Copy link
Contributor Author

Gmin2 commented Jul 28, 2024

Forgot to mention (actually thought I did in the last review) remember to change the main readme file in the repo so everyone can find this new functionality 🙂

Done, need a final look @jonaslagoni

@Gmin2 Gmin2 requested a review from jonaslagoni July 28, 2024 13:45
Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this last efforts always are the toughest to perfect but makes all the difference for the users 🤙

I see some edge cases that are not covered so far by the tests and will make complex OpenAPI documents fail. I dont think we can do anything about External -> internal, except make a notice in the readme about it being something not supported. However, External schema objects and Nested schema objects is something that should be supported. Same with parameters of course.

  • External schema objects
openapi: 3.0.0
info:
  title: test
  version: 1.0.0
  description: Test
paths:
  /test:
    get:
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: './external.json'
  • Nested schema objects
openapi: 3.0.0
info:
  title: test
  version: 1.0.0
  description: Test
paths:
  /test:
    get:
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/test'
components:
  schemas:
    test:
      type: object
      properties:
        message:
          $ref: '#/components/schemas/test2'
    test2:
      type: object
      properties:
        message:
          type: string

Here, you cannot convert both schemas to the multi format schema, because referencing test2 as a multi format schema inside test is not allowed.

  • External -> internal
openapi: 3.0.0
info:
  title: test
  version: 1.0.0
  description: Test
paths:
  /test:
    get:
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: './external.json'
components:
  schemas:
    test:
      type: object
      properties:
        message:
          type: string

# external.json
type: object
properties:
  message:
    $ref: './asyncapi.json#/components/schemas/test'

Same as above, referencing test as a multi format schema inside external is not allowed.

  • Parameters are not being converted in the AsyncAPI document, even though we have explicit test document for it 🤔

test/openapi-to-asyncapi.spec.ts Outdated Show resolved Hide resolved
test/output/openapi-to-asyncapi/callbacks_and_contents.yml Outdated Show resolved Hide resolved
src/openapi.ts Show resolved Hide resolved
@Gmin2 Gmin2 requested a review from jonaslagoni August 1, 2024 06:55
Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments ✌️

README.md Outdated Show resolved Hide resolved
src/convert.ts Outdated Show resolved Hide resolved
src/openapi.ts Outdated
Comment on lines 467 to 473
if (isRefObject(schema)) {
// Check if it's an external reference
if (schema.$ref.startsWith('./') || schema.$ref.startsWith('http')) {
return schema;
}
return schema;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not entirely correct we still need to support External schema objects case, as we still need to convert the schema to multi schema object even if external. We just dont touch the external file and do any changes there. That is the restriction.

Make sure to add a test case for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (schema.$ref.startsWith('./') || schema.$ref.startsWith('http')) {
      // Convert external references to multi-format schema objects
      return {
        schemaFormat: 'application/vnd.oai.openapi;version=3.0.0',
        schema: schema
      };
    }
    return schema;

pushed this

@Gmin2 Gmin2 requested a review from jonaslagoni August 1, 2024 19:11
Copy link

sonarqubecloud bot commented Aug 2, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, good first step 🤙

Lets give the other maintainers a chance to do final review before merging 😊

@jonaslagoni
Copy link
Member

cc @fmvilas @magicmatatjahu

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging as two weeks have passed ✌️

Nicely done @Gmin2 💪

@jonaslagoni
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit b3592ef into asyncapi:master Aug 13, 2024
9 of 10 checks passed
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jonaslagoni
Copy link
Member

@all-contributors please add @Gmin2 for code, doc, example, test

Copy link
Contributor

@jonaslagoni

I've put up a pull request to add @Gmin2! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

Convert OpenAPI 3.0 to AsyncAPI 3.0
4 participants