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

[Server][Spring] support interface and implementation classes for API controllers #1

Merged
merged 2 commits into from
Oct 31, 2023

Conversation

kapilguptavz
Copy link
Owner

added enhancement for java spring asked in OpenAPITools#426 (comment)

Reproduction Steps for java spring:

  1. Create sample.yaml with endpoint containing only get method and generate server stub with below command:
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i sample.yaml -g spring -o springserver
 sample.yaml(paths details with get)
	 paths:
	  /pets:
		get:
		  summary: List all pets
		  operationId: listPets
		  tags:
			- pets
		  parameters:
			- name: limit.....
  1. Update sample.yaml with post method in exiting endpoint and generate server stub with same command given in step 1.
    updated sample.yaml (paths details with post method added)
		  paths:
			/pets:
			get:
			  summary: List all pets
			  operationId: listPets
			  tags:
				- pets
			  parameters:
				- name: limit
			post:
			  summary: Create a pet
			  operationId: createPets
			  tags:
				- pets
			  responses:
				'201':....

Result: In step 1, it will create PetsApi.java(interface ), PetsApiController.java(implementation class) as new and in 2nd step
it overwrites both file.

Enhancement with result:
added checks for file creation for java spring server for controller class.
Unit Test Case: Tested for multiple endpoints
sample.yaml

    paths:
	  /pets:
		get:
		  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':
			 ....
		post:
			summary: Create a pet
			operationId: createPets
			tags:
			  - pets
			responses:
			  '201':
				description: Null response
			  default:
				description: unexpected error
				content:
				  application/json:
					schema:
					  $ref: "#/components/schemas/Error"
	  /pots/{potId}:
		get:
		  summary: Info for a specific pet
		  operationId: showPetById
		  tags:
			- pets
		  parameters:
			- name: potId
			  in: path
			  required: true
			  description: The id of the pet to retrieve
			  schema:
				type: string
		  responses:
			'200':`

Result: generated server stubs multiple times. It only overwrites interfaces (pets.api and pots.api). Implementation classes(PetsApiController.java and PotsApiController.java) are created once.
@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg

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/configs/*.yaml
    ./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.
  • File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.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.

Copy link
Collaborator

@saibalroyvz saibalroyvz left a comment

Choose a reason for hiding this comment

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

Code looks good..

Copy link

@martin-mfg martin-mfg left a comment

Choose a reason for hiding this comment

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

Hi @kapilguptavz, this PR is targetting your fork of OpenAPI Generator. But you probably wanted to target the original OpenAPI Generator repository.
Please take care of the one comment below and then open a new PR in the original OpenAPI Generator repo.
Also, thanks for your contribution!

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