This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new 471cc9cd6 feat(trait): drop support for swagger
471cc9cd6 is described below
commit 471cc9cd606e66fcc865640e8c004540c2ed87b5
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Fri Aug 2 10:31:51 2024 +0200
feat(trait): drop support for swagger
Closes #5735
---
pkg/apis/camel/v1/trait/openapi.go | 2 +-
pkg/trait/openapi_test.go | 161 ++++++++++++++++++++++++++-----------
2 files changed, 114 insertions(+), 49 deletions(-)
diff --git a/pkg/apis/camel/v1/trait/openapi.go
b/pkg/apis/camel/v1/trait/openapi.go
index 3a28b3f37..a8c7f6a41 100644
--- a/pkg/apis/camel/v1/trait/openapi.go
+++ b/pkg/apis/camel/v1/trait/openapi.go
@@ -22,6 +22,6 @@ package trait
// +camel-k:trait=openapi.
type OpenAPITrait struct {
PlatformBaseTrait `property:",squash" json:",inline"`
- // The configmaps holding the spec of the OpenAPI
+ // The configmaps holding the spec of the OpenAPI (compatible with >
3.0 spec only).
Configmaps []string `property:"configmaps" json:"configmaps,omitempty"`
}
diff --git a/pkg/trait/openapi_test.go b/pkg/trait/openapi_test.go
index 6329e188a..8ef68f2a2 100644
--- a/pkg/trait/openapi_test.go
+++ b/pkg/trait/openapi_test.go
@@ -110,52 +110,117 @@ func TestRestDslTraitApplyError(t *testing.T) {
}
var openapi = `
-{
- "swagger" : "2.0",
- "info" : {
- "version" : "1.0",
- "title" : "Greeting REST API"
- },
- "host" : "",
- "basePath" : "/camel/",
- "tags" : [ {
- "name" : "greetings",
- "description" : "Greeting to {name}"
- } ],
- "schemes" : [ "http" ],
- "paths" : {
- "/greetings/{name}" : {
- "get" : {
- "tags" : [ "greetings" ],
- "operationId" : "greeting-api",
- "parameters" : [ {
- "name" : "name",
- "in" : "path",
- "required" : true,
- "type" : "string"
- } ],
- "responses" : {
- "200" : {
- "description" : "Output type",
- "schema" : {
- "$ref" : "#/definitions/Greetings"
- }
- }
- }
- }
- }
- },
- "definitions" : {
- "Greetings" : {
- "type" : "object",
- "properties" : {
- "greetings" : {
- "type" : "string"
- }
- }
- }
- }
-}
+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
`
func TestRestDslTraitApplyWorks(t *testing.T) {
@@ -176,7 +241,7 @@ func TestRestDslTraitApplyWorks(t *testing.T) {
Namespace: "default",
},
Data: map[string]string{
- "greetings-api.json": openapi,
+ "pets.yaml": openapi,
},
},
cm,
@@ -254,5 +319,5 @@ func TestRestDslTraitApplyWorks(t *testing.T) {
return cm.Name == "hello-openapi-000"
})
assert.NotNil(t, sourceCm)
- assert.Contains(t, sourceCm.Data["content"], "get id=\"greeting-api\"
path=\"/greetings/{name}")
+ assert.Contains(t, sourceCm.Data["content"], "get id=\"showPetById\"
path=\"/pets/{petId}\"")
}