postman-to-openapi icon indicating copy to clipboard operation
postman-to-openapi copied to clipboard

Generating Schemas from examples

Open Kinjalrk2k opened this issue 3 years ago • 6 comments

Few notable points:

  • All the examples are inspected and then a common schema is generated
  • This schema is then automatically injected with the already generated response content.
  • Only application/json responses will have a schema.
  • Updated test cases to support response schemas

Referencing important issues:

  • #22
  • https://github.com/Kinjalrk2k/postman-to-openapi-json-extended/issues/1

Kinjalrk2k avatar Nov 01 '22 15:11 Kinjalrk2k

I was looking into the requestBody and found that the data returned is:

{
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "example": {
            "id": "100",
            "createdAt": "2021-06-04T15:50:38.568Z",
            "name": "Carol",
            "avatar": "https://cdn.fakercloud.com/avatars/nelsonjoyce_128.jpg"
          }
        }
      }
    }
  }
}

Shouldn't the requestBody be:

{
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "type": "object"
        },
        "example": {
          "id": "100",
          "createdAt": "2021-06-04T15:50:38.568Z",
          "name": "Carol",
          "avatar": "https://cdn.fakercloud.com/avatars/nelsonjoyce_128.jpg"
        }
      }
    }
  }
}

What I want to point out is wont the schema and example fields be on the same level? Reference: https://swagger.io/docs/specification/describing-request-body/

Please guide me to the right direction if I'm wrong!

Kinjalrk2k avatar Nov 01 '22 15:11 Kinjalrk2k

please check and merge this PR @joolfe

Mehrdad-Dadkhah avatar Nov 02 '22 10:11 Mehrdad-Dadkhah

@Kinjalrk2k I need some time to review but I'm taking it into consideration, thanks so much for the PR.

joolfe avatar Nov 06 '22 09:11 joolfe

This repo lacks an important feature and the MR at least enables basic support for that. However, the repo from @Kinjalrk2k seems outdated and not maintained as well as fails npm audit.

I would really appreciate a solution here and I think other would do too. Maybe the perfection in #246 can be a long term goal, but with intermediate steps (e.g. this MR)?

Thanks for everyones effort. This generators saves a lot of work!!!

mindrunner avatar Jan 24 '23 13:01 mindrunner

@joolfe Are you able to review this PR?

doggy8088 avatar Dec 10 '23 06:12 doggy8088

I created a package that provides a function to create the missing schema types for request bodies and responses based on the examples. I will deprecate the package if the PR is merged but this repository seems pretty dead.

https://github.com/soerenuhrbach/openapi-schema-types-from-examples#use-with-postman-to-openapi

soerenuhrbach avatar Jan 02 '24 20:01 soerenuhrbach