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

Postman Collection Generator #15294

Merged
merged 17 commits into from
May 16, 2023
Merged

Conversation

gcatanese
Copy link
Contributor

Create the Postman generator: from an OpenAPI file, it generates a Postman collection v2.1.0 that can be imported in Postman to execute and test the requests.

The existing OpenAPI import in Postman is very basic (especially when using the API instead of the Postman GUI) resulting in a Collection that doesn't have all the examples and features of the OpenAPI file. When using the Postman GUI there are few options available but this approach is not suitable when automating the generation workflow (i.e. create a collection when a new OpenAPI is available).

This generator implements the generation of a Postman collection with the following:

  • one request for each OpenAPI request example
  • set the Authorization header
  • create a Postman variable to set the API Key
  • (Optionally) Postman variables for path variables
  • (Optionally) Postman variables for placeholders found in the request body of the examples
  • (Optionally) create Postman dynamic variables (i.e. guid, isoTimestamp)
  • prettify JSON examples

I obviously volunteer to maintain the generator.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date.sh
    
    Commit all changed files.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328 wing328 added this to the 7.0.0 milestone May 11, 2023
@wing328 wing328 changed the title Postman Generator Postman Collection Generator May 11, 2023
@wing328
Copy link
Member

wing328 commented May 16, 2023

thanks for the PR. let's give it a try.

@wing328 wing328 merged commit ab4a05a into OpenAPITools:master May 16, 2023
6 checks passed
tiffmaelite added a commit to tiffmaelite/openapi-generator that referenced this pull request Jun 6, 2023
wing328 pushed a commit that referenced this pull request Jun 10, 2023
makru86 pushed a commit to makru86/openapi-generator that referenced this pull request Jun 12, 2023
fmoraespadtec pushed a commit to padteclab/openapi-generator that referenced this pull request Jun 26, 2023
@wing328
Copy link
Member

wing328 commented Aug 29, 2023

Hi @gcatanese I did a test with

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g postman-collection -i https://developer.allegro.pl/swagger.yaml -o /tmp/pc/

and got the following errors in the output (partial):

[main] WARN  o.o.c.l.PostmanCollectionCodegen - Error formatting JSON
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'BINARY_DATA_HERE': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"BINARY_DATA_HERE"; line: 1, column: 17]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2418)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:759)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:3038)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:2079)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:805)
	at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4759)
	at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:3124)
	at org.openapitools.codegen.languages.PostmanCollectionCodegen.formatJson(PostmanCollectionCodegen.java:704)
	at org.openapitools.codegen.languages.PostmanCollectionCodegen.getPostmanRequests(PostmanCollectionCodegen.java:367)
	at org.openapitools.codegen.languages.PostmanCollectionCodegen.postProcessOperationsWithModels(PostmanCollectionCodegen.java:256)
	at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1275)
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:609)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:953)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:511)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
[main] WARN  o.o.c.l.PostmanCollectionCodegen - Error formatting JSON
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'BINARY_DATA_HERE': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"BINARY_DATA_HERE"; line: 1, column: 17]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2418)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:759)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:3038)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:2079)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:805)
	at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4759)
	at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:3124)
	at org.openapitools.codegen.languages.PostmanCollectionCodegen.formatJson(PostmanCollectionCodegen.java:704)
	at org.openapitools.codegen.languages.PostmanCollectionCodegen.getPostmanRequests(PostmanCollectionCodegen.java:367)
	at org.openapitools.codegen.languages.PostmanCollectionCodegen.postProcessOperationsWithModels(PostmanCollectionCodegen.java:256)
	at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1275)
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:609)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:953)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:511)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)

Can you please take a look when you've time?

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

Successfully merging this pull request may close these issues.

None yet

2 participants