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

Add OpenAPI 3.1 support #1749

Closed
jonaslagoni opened this issue Jan 18, 2024 · 12 comments · Fixed by #1778
Closed

Add OpenAPI 3.1 support #1749

jonaslagoni opened this issue Jan 18, 2024 · 12 comments · Fixed by #1778
Labels
area/typescript Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. enhancement New feature or request good first issue Good for newcomers openapi released on @next released

Comments

@jonaslagoni
Copy link
Member

Reason/Context

Right now we already have support for OpenAPI 3.0 and Swagger 2.0. But we should also support the newest 3.1 version: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md

To support it we need to alter the existing OpenAPI input processor to also support the new 3.1 version: https://github.com/asyncapi/modelina/blob/master/src/processors/OpenAPIInputProcessor.ts

This does

You can use the following OpenAPI 3.1 input document for testing (or come up with your own):

{
  "openapi": "3.1.0",
  "info": {
    "version": "1.0.0",
    "title": "Swagger Petstore",
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "http://petstore.swagger.io/v1"
    }
  ],
  "paths": {
    "/pets": {
      "get": {
        "summary": "List all pets",
        "operationId": "listPets",
        "tags": [
          "pets"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "How many items to return at one time (max 100)",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 100,
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A paged array of pets",
            "headers": {
              "x-next": {
                "description": "A link to the next page of responses",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pets"
                }
              }
            }
          },
          "default": {
            "description": "unexpected error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a pet",
        "operationId": "createPets",
        "tags": [
          "pets"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Pet"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Null response"
          },
          "default": {
            "description": "unexpected error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/pets/{petId}": {
      "get": {
        "summary": "Info for a specific pet",
        "operationId": "showPetById",
        "tags": [
          "pets"
        ],
        "parameters": [
          {
            "name": "petId",
            "in": "path",
            "required": true,
            "description": "The id of the pet to retrieve",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Expected response to a valid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pet"
                }
              }
            }
          },
          "default": {
            "description": "unexpected error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Pet": {
        "type": "object",
        "required": [
          "id",
          "name"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "name": {
            "type": "string"
          },
          "tag": {
            "type": "string"
          }
        }
      },
      "Pets": {
        "type": "array",
        "maxItems": 100,
        "items": {
          "$ref": "#/components/schemas/Pet"
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}

Happy to help further if you get stuck on something ✌️

@jonaslagoni jonaslagoni added enhancement New feature or request good first issue Good for newcomers area/typescript Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. openapi labels Jan 18, 2024
@Gmin2
Copy link
Contributor

Gmin2 commented Jan 19, 2024

Hey @jonaslagoni after making changes i can test this in the playground right?

@jonaslagoni
Copy link
Member Author

Cant remember if playground allows multiple inputs yet.

You can write unit tests for it 😄

@Tanay-Verma
Copy link

Tanay-Verma commented Jan 21, 2024

Hello @jonaslagoni,

I'm eager to contribute to this issue and excited to make my first open-source contribution. As a newcomer, I would greatly appreciate some guidance on the task.

Upon inspecting the OpenAPIInputProcessor.ts file, it appears that the current parser used by the project lacks support for parsing and validating OpenAPI 3.1 specifications. After some research, I came across a repository based on apidevtools/swagger-parser.

readme/openapi-parser

I believe integrating this alternative parser could address the gap in OpenAPI 3.1 support. I'm ready to explore and contribute to implementing this improvement. Any guidance or pointers you can provide would be immensely helpful.

@jonaslagoni
Copy link
Member Author

Sounds like a good idea @Tanay-Verma 👍

@Athul0491
Copy link
Contributor

We currently aren't using the latest version of the swagger-parser. The latest version of it has support for the OpenAPI 3.1 version as well.

@jonaslagoni
Copy link
Member Author

Sounds even better @Athul0491, @Tanay-Verma 👍

@Tanay-Verma
Copy link

We currently aren't using the latest version of the swagger-parser. The latest version of it has support for the OpenAPI 3.1 version as well.

Is this the one you are referring swagger-parser?
This is for java 😅.

@Athul0491
Copy link
Contributor

Athul0491 commented Jan 25, 2024

@Tanay-Verma I was referring to swagger-parser. See this, they have added support for OpenAPI 3.1 in version 10.1.0

@Tanay-Verma
Copy link

@Athul0491 @jonaslagoni
Do I have to add a class OpenAPIV3_1Schema in OpenAPIV3Schema.ts ? If so would like some pointers on how to go about it.

@jonaslagoni
Copy link
Member Author

Either that or update the existing one for v3 with v3.1 changes as they should be non breaking

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 3.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 4.0.0-next.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/typescript Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. enhancement New feature or request good first issue Good for newcomers openapi released on @next released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants