Skip to content

Conversation

tfesenko
Copy link
Member

@tfesenko tfesenko commented Sep 25, 2018

1. Design

To do it, simply paste this code to your petstore-expanded.yaml file at the end of the /pets/{id} pathItem:

    put: 
      description: Update a pet based on the ID
      operationId: updatePet
      requestBody:
        content: 
          "application/json":
            schema:
              $ref: "#/components/schemas/NewPet"
      parameters:
        - name: id
          in: path
          description: ID of pet to fetch
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: pet response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

Git branch: step_3a

2. Generate code

Run "Generate Java Spring (Boot + MVC + CloudFeign) Server".
You can see also see the result by switching to step_3b

3. Implement

We didn't have an implementation of the new PUT method yet. Fortunately, Java compiler will notify us about it. (If you don't see error markers in your project, use Project -> clean in the menu bar to force a rebuild.) Let's add this implementation for updatePet in PetsApiDelegateImpl:

	@Override
	public ResponseEntity<Pet> updatePet(Long id, NewPet newPet) {
		if (!pets.containsKey(id)) {
			return new ResponseEntity<>(HttpStatus.NOT_FOUND);
		}
		pets.get(id).name(newPet.getName()).tag(newPet.getTag());
		return new ResponseEntity<>(pets.get(id), HttpStatus.ACCEPTED);
	}

Or, git checkout step_3c

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

Successfully merging this pull request may close these issues.

1 participant