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

Response schemas

Open joolfe opened this issue 4 years ago • 11 comments

We need to have a way to define response schemas so docs are more complete

joolfe avatar Jun 28 '20 11:06 joolfe

Postman allows you to save example responses maybe the schema can be derived from those ?

kyriakos avatar Apr 13 '21 15:04 kyriakos

Yes probably this is the direction to follow but there are lot of questions as a response don't have description etc... Just a name and a value in the fields

joolfe avatar Apr 13 '21 20:04 joolfe

I do not think that it is possible to generate the necessary data from the response. Maybe the information could be generated in a similar way as with the status code. At example by evaluating the schema of the following function.

pm.expect(tv4.validate(pm.response.json(), schema)).to.be.true;

However, I am not sure how often such tests are implemented for the response

thomasweiland93 avatar Jun 13 '21 02:06 thomasweiland93

In version 1.3.0 now is possible to add example responses in the request, is still not a schema solution but can be work for lot of people meanwhile.

joolfe avatar Jul 16 '21 07:07 joolfe

Perhaps the best interim solution is to just have a scheme with a name and a type for now. Not having a scheme with types is a deal-breaker for me to use this library. Another service reads the swagger doc to determine the data types of incoming data. If having a description is essential then the markdown solution might be the only option @joolfe

Just dropped a project working towards this! https://github.com/Kinjalrk2k/postman-to-openapi-json-extended

What I've done is:

  • Used this library to parse the Postman collection and extract the paths in which schemas might be useful.
  • Use the examples for building the schemas using: https://github.com/Nijikokun/generate-schema
  • Write all these down on a JSON file for the ~user~ developer to edit the schemas as they wish
  • Again use this library to build the OpenAPI spec file whilst adding the extracted schemas

My use-case was JSON specific, hence favoured JSON on the OpenAPI side ;)

Kinjalrk2k avatar Dec 05 '21 12:12 Kinjalrk2k

@kyriakos cool approach the use of external json files is not a bad ideaat all

Best Regards.

joolfe avatar Dec 09 '21 15:12 joolfe

Just dropped a project working towards this! https://github.com/Kinjalrk2k/postman-to-openapi-json-extended

What I've done is:

  • Used this library to parse the Postman collection and extract the paths in which schemas might be useful.
  • Use the examples for building the schemas using: https://github.com/Nijikokun/generate-schema
  • Write all these down on a JSON file for the ~user~ developer to edit the schemas as they wish
  • Again use this library to build the OpenAPI spec file whilst adding the extracted schemas

My use-case was JSON specific, hence favoured JSON on the OpenAPI side ;)

I think that was cool if you create a PR to this repo, however, please create a PR about generate schema from examples.

hosseinmd avatar Aug 16 '22 08:08 hosseinmd

Hi there, great tool first of all!

I think. this way already discussed in some of the closed issues, but not sure if it's solved. Is it possible to somehow create request body properties in the output openapi file? Currently, I'm adding the properties manually to the output according to my example responses, but it would be great if it's automatically supported.

Best regards.

maorstamati avatar Sep 01 '22 06:09 maorstamati

Why can't the schema be inferred from the example response(s)? The name and literal types are there.

ryanackley avatar Nov 10 '22 15:11 ryanackley

Using $ref to reference files generated/manually created elsewhere doesn't solve this problem, but makes it easier to workaround. This tool automates much of the work I need to perform. I have no problem manually creating request/response schemas. Will you consider reopening https://github.com/joolfe/postman-to-openapi/issues/243?

clintonb avatar Jan 31 '23 22:01 clintonb