-
Notifications
You must be signed in to change notification settings - Fork 37
API first tutorial #192
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
Open
GuentherJulian
wants to merge
5
commits into
devonfw-tutorials:main
Choose a base branch
from
GuentherJulian:api-first-tutorial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
API first tutorial #192
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package com.devonfw.quarkus.petstore.rest.v1; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import javax.validation.Valid; | ||
|
|
||
| import com.devonfw.quarkus.openapi.petstore.domain.Pet; | ||
| import com.devonfw.quarkus.openapi.petstore.rest.v1.PetsApi; | ||
|
|
||
| public class PetstoreRestService implements PetsApi { | ||
|
|
||
| private Set<Pet> pets = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>())); | ||
|
|
||
| @Override | ||
| public void createPets(@Valid Pet pet) { | ||
|
|
||
| pet.setId(Long.valueOf(this.pets.size())); | ||
| this.pets.add(pet); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Pet> listPets(Integer limit) { | ||
|
|
||
| if (limit == null) | ||
| return this.pets.stream().collect(Collectors.toList()); | ||
| return this.pets.stream().limit(limit).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| @Override | ||
| public Pet showPetById(String petId) { | ||
|
|
||
| List<Pet> petList = this.pets.stream().filter(pet -> pet.getId() == Long.valueOf(petId)) | ||
| .collect(Collectors.toList()); | ||
| if (petList.size() == 0) | ||
| return null; | ||
| return petList.get(0); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Finally, test the REST service. | ||
|
|
||
| Open a new terminal and type in the folling command to make a POST request and create a new pet: | ||
|
|
||
| curl -X POST -H "Content-Type: application/json" -d '{"name": "Alex", "tag": "Dog"}' http://localhost:8080/pets | ||
|
|
||
| After executing the command, there should be a pet stored in the list. | ||
| Let's check this by getting the entire list using the `listPets` method of the REST service. | ||
|
|
||
| Open https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/pets in the browser and see if the pet has been saved. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| openapi: "3.0.0" | ||
| info: | ||
| version: 1.0.0 | ||
| title: Swagger Petstore | ||
| license: | ||
| name: MIT | ||
| servers: | ||
| - url: http://petstore.swagger.io/v1 | ||
| paths: | ||
| /pets: | ||
| get: | ||
| summary: List all pets | ||
| 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 | ||
| format: int32 | ||
| responses: | ||
| '200': | ||
| description: A paged array of pets | ||
| headers: | ||
| x-next: | ||
| description: A link to the next page of responses | ||
| schema: | ||
| type: string | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Pets" | ||
| default: | ||
| description: unexpected error | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Error" | ||
| post: | ||
| summary: Create a pet | ||
| operationId: createPets | ||
| tags: | ||
| - pets | ||
| requestBody: | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/Pet' | ||
| responses: | ||
| '201': | ||
| description: Null response | ||
| default: | ||
| description: unexpected error | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Error" | ||
| /pets/{petId}: | ||
| get: | ||
| summary: Info for a specific pet | ||
| operationId: showPetById | ||
| tags: | ||
| - pets | ||
| parameters: | ||
| - name: petId | ||
| in: path | ||
| required: true | ||
| description: The id of the pet to retrieve | ||
| schema: | ||
| type: string | ||
| responses: | ||
| '200': | ||
| description: Expected response to a valid request | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Pet" | ||
| default: | ||
| description: unexpected error | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Error" | ||
| components: | ||
| schemas: | ||
| Pet: | ||
| type: object | ||
| required: | ||
| - id | ||
| - name | ||
| properties: | ||
| id: | ||
| type: integer | ||
| format: int64 | ||
| name: | ||
| type: string | ||
| tag: | ||
| type: string | ||
| Pets: | ||
| type: array | ||
| items: | ||
| $ref: "#/components/schemas/Pet" | ||
| Error: | ||
| type: object | ||
| required: | ||
| - code | ||
| - message | ||
| properties: | ||
| code: | ||
| type: integer | ||
| format: int32 | ||
| message: | ||
| type: string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| <?xml version="1.0"?> | ||
| <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.devonfw.quarkus</groupId> | ||
| <artifactId>api-first-tutorial</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| <properties> | ||
| <compiler-plugin.version>3.8.1</compiler-plugin.version> | ||
| <maven.compiler.release>11</maven.compiler.release> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
| <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> | ||
| <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id> | ||
| <quarkus.platform.version>2.6.1.Final</quarkus.platform.version> | ||
| <surefire-plugin.version>3.0.0-M5</surefire-plugin.version> | ||
| </properties> | ||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>${quarkus.platform.group-id}</groupId> | ||
| <artifactId>${quarkus.platform.artifact-id}</artifactId> | ||
| <version>${quarkus.platform.version}</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-resteasy-jackson</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-arc</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-resteasy</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-junit5</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.rest-assured</groupId> | ||
| <artifactId>rest-assured</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>${quarkus.platform.group-id}</groupId> | ||
| <artifactId>quarkus-maven-plugin</artifactId> | ||
| <version>${quarkus.platform.version}</version> | ||
| <extensions>true</extensions> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>build</goal> | ||
| <goal>generate-code</goal> | ||
| <goal>generate-code-tests</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>${compiler-plugin.version}</version> | ||
| <configuration> | ||
| <compilerArgs> | ||
| <arg>-parameters</arg> | ||
| </compilerArgs> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>${surefire-plugin.version}</version> | ||
| <configuration> | ||
| <systemPropertyVariables> | ||
| <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
| <maven.home>${maven.home}</maven.home> | ||
| </systemPropertyVariables> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <profiles> | ||
| <profile> | ||
| <id>native</id> | ||
| <activation> | ||
| <property> | ||
| <name>native</name> | ||
| </property> | ||
| </activation> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-failsafe-plugin</artifactId> | ||
| <version>${surefire-plugin.version}</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>integration-test</goal> | ||
| <goal>verify</goal> | ||
| </goals> | ||
| <configuration> | ||
| <systemPropertyVariables> | ||
| <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> | ||
| <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
| <maven.home>${maven.home}</maven.home> | ||
| </systemPropertyVariables> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <properties> | ||
| <quarkus.package.type>native</quarkus.package.type> | ||
| </properties> | ||
| </profile> | ||
|
|
||
| <profile> | ||
| <id>apigen</id> | ||
| <activation><activeByDefault>true</activeByDefault></activation> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.openapitools</groupId> | ||
| <artifactId>openapi-generator-maven-plugin</artifactId> | ||
| <version>5.3.1</version> | ||
| <executions> | ||
| <execution> | ||
| <phase>generate-sources</phase> | ||
| <goals> | ||
| <goal>generate</goal> | ||
| </goals> | ||
| <configuration> | ||
| <inputSpec>${project.basedir}/src/main/resources/petstore-api.yaml</inputSpec> | ||
| <generatorName>jaxrs-spec</generatorName> | ||
| <apiPackage>com.devonfw.quarkus.openapi.petstore.rest.v1</apiPackage> | ||
| <modelPackage>com.devonfw.quarkus.openapi.petstore.domain</modelPackage> | ||
| <configOptions> | ||
| <sourceFolder>src/main/gen</sourceFolder> | ||
| <useSwaggerAnnotations>false</useSwaggerAnnotations> | ||
| <useTags>true</useTags> | ||
| <interfaceOnly>true</interfaceOnly> | ||
| <generatePom>true</generatePom> | ||
| </configOptions> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </profile> | ||
| </profiles> | ||
| </project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.