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

Support for OpenAPI v3 #1330

Merged
merged 9 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,136 changes: 3,136 additions & 0 deletions deploy/camel-catalog-1.2.0-SNAPSHOT-main.yaml

Large diffs are not rendered by default.

892 changes: 892 additions & 0 deletions deploy/camel-catalog-1.2.0-SNAPSHOT-quarkus.yaml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions deploy/resources.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
** xref:traits/prometheus.adoc[Prometheus]
** xref:traits/pull-secret.adoc[Pull Secret]
** xref:traits/quarkus.adoc[Quarkus]
** xref:traits/rest-dsl.adoc[Rest Dsl]
** xref:traits/openapi.adoc[Rest Dsl]
** xref:traits/route.adoc[Route]
** xref:traits/service.adoc[Service]
// End of autogenerated code - DO NOT EDIT! (trait-nav)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ The Rest DSL trait is internally used to allow creating integrations from a Open

This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**.

WARNING: The rest-dsl trait is a *platform trait*: disabling it may compromise the platform functionality.
WARNING: The openapi trait is a *platform trait*: disabling it may compromise the platform functionality.

// End of autogenerated code - DO NOT EDIT! (description)
// Start of autogenerated code - DO NOT EDIT! (configuration)
== Configuration

Trait properties can be specified when running any integration with the CLI:
```
kamel run --trait rest-dsl.[key]=[value] integration.groovy
kamel run --trait openapi.[key]=[value] integration.groovy
```
The following configuration options are available:

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/traits/traits.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See the trait description pages for more information on a specific trait:
* xref:traits/prometheus.adoc[Prometheus Trait]
* xref:traits/pull-secret.adoc[Pull Secret Trait]
* xref:traits/quarkus.adoc[Quarkus Trait]
* xref:traits/rest-dsl.adoc[Rest Dsl Trait]
* xref:traits/openapi.adoc[Rest Dsl Trait]
* xref:traits/route.adoc[Route Trait]
* xref:traits/service.adoc[Service Trait]
// End of autogenerated code - DO NOT EDIT! (trait-list)
111 changes: 111 additions & 0 deletions e2e/files/petstore-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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
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
29 changes: 29 additions & 0 deletions e2e/files/petstore.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// camel-k: language=groovy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//
// kamel run --dev --name petstore --open-api examples/petstore-api.yaml examples/petstore.groovy
//

from('direct:listPets')
.log('listPets')
from('direct:createPets')
.log('createPets')
from('direct:showPetById')
.log('showPetById')

85 changes: 85 additions & 0 deletions e2e/openapi_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// +build knative

// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "knative"

/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"testing"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
)

func TestOpenAPIService(t *testing.T) {
withNewTestNamespaceWithKnativeBroker(t, func(ns string) {
Expect(kamel("install", "-n", ns, "--trait-profile", string(v1.TraitProfileKnative)).Execute()).Should(BeNil())
Expect(kamel(
"run",
"-n", ns,
"--name", "petstore",
"--open-api", "examples/petstore-api.yaml",
"files/petstore.groovy",
).Execute()).Should(BeNil())

Eventually(integrationPodPhase(ns, "petstore"), testTimeoutLong).
Should(Equal(corev1.PodRunning))
Eventually(knativeService(ns, "petstore"), testTimeoutLong).
Should(Not(BeNil()))

Eventually(integrationLogs(ns, "petstore"), testTimeoutMedium).
Should(ContainSubstring("Route: listPets started and consuming from: http://0.0.0.0:8080/v1/pets"))
Eventually(integrationLogs(ns, "petstore"), testTimeoutMedium).
Should(ContainSubstring("Route: createPets started and consuming from: http://0.0.0.0:8080/v1/pets"))
Eventually(integrationLogs(ns, "petstore"), testTimeoutMedium).
Should(ContainSubstring("Route: showPetById started and consuming from: http://0.0.0.0:8080/v1/pets"))

Expect(kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
})
}

func TestOpenAPIDeployment(t *testing.T) {
withNewTestNamespaceWithKnativeBroker(t, func(ns string) {
Expect(kamel("install", "-n", ns, "--trait-profile", string(v1.TraitProfileKubernetes)).Execute()).Should(BeNil())
Expect(kamel(
"run",
"-n", ns,
"--name", "petstore",
"--open-api", "examples/petstore-api.yaml",
"files/petstore.groovy",
).Execute()).Should(BeNil())

Eventually(integrationPodPhase(ns, "petstore"), testTimeoutLong).
Should(Equal(corev1.PodRunning))
Eventually(deployment(ns, "petstore"), testTimeoutLong).
Should(Not(BeNil()))

Eventually(integrationLogs(ns, "petstore"), testTimeoutMedium).
Should(ContainSubstring("Route: listPets started and consuming from: http://0.0.0.0:8080/v1/pets"))
Eventually(integrationLogs(ns, "petstore"), testTimeoutMedium).
Should(ContainSubstring("Route: createPets started and consuming from: http://0.0.0.0:8080/v1/pets"))
Eventually(integrationLogs(ns, "petstore"), testTimeoutMedium).
Should(ContainSubstring("Route: showPetById started and consuming from: http://0.0.0.0:8080/v1/pets"))

Expect(kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
})
}
Loading